Linux – How to measure total disk I/O per hour

diskiolinux

I have a cloud server were we get billed also for disk IO usage. Here is an example from the stats:

04/Sep/2013 07:24:19
04/Sep/2013 08:24:19
0,5 GB / 1 vCPU (0,08 Kr. per hour): Charge for 44.7578125GB disk I/O

So for one hour we get billed for around 45 GB disk I/O.

To me that sounds like a lot of traffic and I would like to do some monitoring to check it myself. I know about tools like dstat and sysstat etc but I have not found any examples showing totals for one hour (or other timeframe). Most examples is averaging the results, like this command:

dstat -tdD total 60

Here, it shows disk I/O measuring for 60 seconds, but it is averaged. So if I copy a large file, I will see the number increase while copying, but as soon as it is finished, the number will decrease again. I other words, I don't end up with a true total for that period.

How can I log the total amount of disk I/O in a given timeframe?

Best Answer

You can use the tool iostat to collect the disk utilization information. It takes several arguments, including the switch, -d:

   -d     Display the device utilization report.

It also takes an argument in seconds an interval of how frequent it should re-run. The value 3600 would be the number of seconds in an hour.

Example

$ iostat -d 3600
Linux 2.6.35.14-106.fc14.x86_64 (grinchy)   09/04/2013  _x86_64_    (4 CPU)

Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sda              20.53        71.86      1259.61   20308334  356000380
dm-0              4.92        39.02        28.81   11027610    8143376
dm-1              0.54         0.93         3.38     261472     954912
dm-2            156.65        31.87      1227.42    9006394  346902056

The output from this command could be redirected to a file:

$ iostat -d 3600 >> iostat_hrly.log

Meaning of the units

If you consult the man page for iostat it has pretty good descriptions of the units.

excerpt

   Blk_read/s
         Indicate the amount of data read from the device expressed in a 
         number of blocks per second. Blocks are equivalent to sectors with
         kernels 2.4 and later and  therefore have a size of 512 bytes. With
         older kernels, a block is of indeterminate size.

  Blk_wrtn/s
         Indicate the amount of data written to the device expressed in a 
         number of blocks per second.

  Blk_read
         The total number of blocks read.

  Blk_wrtn
         The total number of blocks written.

So a block is 512 bytes, so the Blk_read/s in terms of MB for device sda would be, 71.86 * 512 bytes = 36.79232 kilobytes/sec.

There are additional switches that will change the units automatically in the output.

excerpt from iostat man page

-h     Make the NFS report displayed by option -n easier to read by a human.

-k     Display statistics in kilobytes per second instead of blocks per 
       second.  Data displayed are valid only with kernels 2.4 and later.

-m     Display statistics in megabytes per second instead of blocks or 
       kilobytes per second.  Data displayed are valid only with kernels 
       2.4 and later.

Example in KB/s

So this might be more useful, showing the throughput in KB/s:

$ iostat -dk 3600
Linux 2.6.35.14-106.fc14.x86_64 (grinchy)   09/05/2013  _x86_64_    (4 CPU)

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda              20.85        47.25       663.81   15475096  217427086
dm-0              5.01        20.00        14.43    6549301    4725068
dm-1              0.54         0.58         1.60     189064     524872
dm-2            165.30        26.65       647.78    8730281  212177124
Related Question