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
Thanks
Because you can't compare both of them. sar -b is at specific times, at an interval of 10 minutes or whatever you have specified in your cron job.
But /proc/diskstats is a kernel run time value. It is not calculated at any specific time interval but more of a counter that kernel keeps for accounting. It is from where iostat reads the data. If you specify iostat -xdk 5 5 then, at 5 seconds interval iostat is going to read the /proc/diskstats file and get the weighted average of data from there. Important point to note is that /proc/diskstats is not time dependent and hence you cannot compare it with sar -b which runs at fixed, particular intervals in time.
If you want a more elaborate description, I can check the code and tell but now it is really late in night here.
Use iostat with interval
Do iostat in 10sec interval
If you want to get easy output for ploting
Then it will give you someting like following
You should always discard the first line because that is the total since machine start or since the counter last wrap around.
I am not sure how difficult to plot with graphite, you can copy and paste them into Excel or LibraOffice Calc and create the chart.