gopsutil icon indicating copy to clipboard operation
gopsutil copied to clipboard

[process][linux]collect rchar and wchar from /proc/${pid}/io

Open roccowong95 opened this issue 6 years ago • 7 comments
trafficstars

Is your feature request related to a problem? Please describe. IOCountersStat now have ReadBytes and WriteBytes, but /proc/${pid}/io also provides rchar and wchar, which is not affected by possible disk pagecache. Users may want these two value(rchar and wchar) as well as read_bytes and write_bytes.

Describe the solution you'd like

  • [x] On linux, these two values are easy to get.
  • [x] IOCounters is not implemented on darwin.
  • [ ] Not sure how to get these on windows, either set them 0 or the same as read_bytes, write_bytes makes sense to me...

Describe alternatives you've considered

Additional context An example from the doc.

Example
-------

test:/tmp # dd if=/dev/zero of=/tmp/test.dat &
[1] 3828

test:/tmp # cat /proc/3828/io
rchar: 323934931 <---- 
wchar: 323929600
syscr: 632687
syscw: 632675
read_bytes: 0 <---- 
write_bytes: 323932160
cancelled_write_bytes: 0

roccowong95 avatar Apr 23 '19 11:04 roccowong95

@roccowong95 when will two metrics rchar and wchar be helpful? Isn't it enough to monitor typical metrics read_bytes or write_bytes?

mznet avatar Apr 26 '19 15:04 mznet

So rchar has a value even if read_bytes are 0 in sometimes, correct? If so, how about use rchar value as read_bytes if read_bytes is 0. According to your cited URL, rchar is

The number of bytes which this task has caused to be read from storage

so it can be used as read_bytes and no need to add other fields IMO.

shirou avatar Apr 27 '19 02:04 shirou

There is significant difference between metrics

  • rchar - bytes read from an application point of view. files may read from pagecache. also include process pipes.
  • read_bytes - bytes read from the storage layer.

So if process not used pipes you can monitor pagecache usage by difference.

(https://man7.org/linux/man-pages/man5/proc.5.html)

maizy avatar Sep 03 '20 07:09 maizy

@maizy The significance is understandable, but what insight or advantage do we get by monitoring these two metrics?

mznet avatar Sep 06 '20 12:09 mznet

@maizy The significance is understandable, but what insight or advantage do we get by monitoring these two metrics?

@mznet in my case it was indirect way to monitor pagecache usage. lightweight alternative to eBPF solution.

maizy avatar Sep 23 '20 06:09 maizy