2

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

milosgajdos
  • 1,808
  • 2
  • 21
  • 29

2 Answers2

2

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.

Soham Chakraborty
  • 3,534
  • 16
  • 24
0

Use iostat with interval

iostat -d /dev/xvda <interval(sec)> <counter>

Do iostat in 10sec interval

iostat -d /dev/xvda 10

If you want to get easy output for ploting

iostat -d /dev/xvda 10 | grep xvda

Then it will give you someting like following

xvda               1.30         3.28        38.68    1151011   13583372
xvda              15.00         0.00       100.00          0        100
xvda               0.00         0.00         0.00          0          0
xvda               0.00         0.00         0.00          0          0
xvda               5.00         0.00        32.00          0         32
xvda               0.00         0.00         0.00          0          0
xvda               0.00         0.00         0.00          0          0
xvda               8.00         0.00       240.00          0        240
xvda               0.00         0.00         0.00          0          0

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.

John Siu
  • 3,577
  • 2
  • 15
  • 23