Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
    
iostat -d 3600 –  Stéphane Chazelas Sep 4 '13 at 21:12

1 Answer 1

up vote 1 down vote accepted

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
share|improve this answer
    
How do I relate Blk_read/wrtn to actual bytes? Is it the sector size of the disk? So if Blk_read is 20308334 there is read 20308334*512 bytes or around 10GB? –  marlar Sep 5 '13 at 7:48
    
@marlar - see updates. –  slm Sep 5 '13 at 10:01
    
Thanks - it works! –  marlar Sep 13 '13 at 9:41
1  
BTW: One thing I wasn't aware of is that iostat shows the stats from since it was run last time. So the first time you run it, you will see the accumulated stats from since the OS bootet. Or if you did run it some time ago, it will show the stats since then and not just in the last hour etc. –  marlar Sep 13 '13 at 9:49
    
@marlar - yes I neglected to mention that. Wasn't sure how to explain that on top of everything else, so I opted to leave that out. Glad this worked out for you. –  slm Sep 13 '13 at 12:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.