I'm trying to figure out how to count read and written bytes per second. At the moment what I'm doing is I read the data from /proc/diskstats which looks like this:
202 0 xvda 80702313 1132334 2823807338 426518304 89838477 177437957 2140229136 1696949080 0 142957364 2123455348
I read the 6th (sectors/s read) and 10th (sectors/s written) fields and multiply them by 512 ( I figured that's the right value by checking the output from fdisk which is saying
sectors of 1 * 512 = 512 bytes) which should give me the number of bytes. I take 2 samples and substract the first one from the latter one and then divide the resulting values by the number of seconds in between the samples.
It doesn't seem to give the correct results though. Anyone idea on how this should actually be done ?
I'm looking for something similar to what
sar -b outputs