Saturday, 4 August 2012

Linux "iostat" command...

I recently discovered the "iostat" command while debugging a slow database input/output problem... If you have a large amount of database reads/writes the iostat command can tell you how your disks are performing which in turn has a huge influence your a busy database...

You can install iostat on Ubuntu machines using:


sudo apt-get install sysstat


Command for a specific disk eg /dev/sda and updated every second:
iostat -dmx /dev/sda 1

Command for a quick once off overview of all disks:
iostat -dmx  (you can add space separated disks here too, eg. sda sdb)



The arguments used above:

-d (device utilization report)
-m (display in MB)
-x (extended statistics)



Sample output:


The %util column is the first one you'll want to keep an eye on as the server is actively being used. Basically it shows us how saturated the controller is for the specific device, if this percentage is constantly high the controller is working hard to keep up with the read/write requirements and could be a good indication that you maybe need to re-evaluate the server's hardware to accommodate the IO...

The other columns of the report as per the man page:


rrqm/s - The number of read requests merged per second that were queued to the device.
wrqm/s - The number of write requests merged per second that were queued to the device.
r/s - The number (after merges) of read requests completed per second for the device.
w/s - The number (after merges) of write requests completed per second for the device.
rsec/s (rkB/s, rMB/s) - The number of sectors (kilobytes, megabytes) read from the device per second.
wsec/s (wkB/s, wMB/s) - The number of sectors (kilobytes, megabytes) written to the device per second.
avgrq-sz - The average size (in sectors) of the requests that were issued to the device.
avgqu-sz - The average queue length of the requests that were issued to the device.
await - The average time (in milliseconds) for I/O requests issued to the device to be served. This includes the time spent by the requests in queue and the time  spent  servicing them.
r_await - The  average time (in milliseconds) for read requests issued to the device to be served. This includes the time spent by the requests in queue and the time spent servicing them.
w_await - The average time (in milliseconds) for write requests issued to the device to be served. This includes the time spent by the requests in queue and the time spent servicing them.
svctm - The  average service time (in milliseconds) for I/O requests that were issued to the device. Warning! Do not trust this field any more.  This field will be removed in a future sysstat version.
%util - Percentage of CPU time during which I/O requests were issued to the device (bandwidth utilization for the device). Device saturation occurs when this value is close to 100%.


No comments:

Post a Comment