If you employ Linux in your data center, you know how powerful it can be. Linux contains more tools than most admins will ever use. Some of those tools exist well outside of the realm of the obvious, but can still play a vital role in helping you keep your systems running smoothly.

One such tool is the iostat command. The iostat command is used for monitoring system I/O device loading. Iostat achieves this by observing the time devices are active in relation to their average transfer rates. With a quick run of the command, you will see reports that can help you optimize a system’s input and output load.

Let’s install and use iostat.

Installation

I will be demonstrating the installation on Elementary OS. The iostat command can be installed on other distributions, so modify the installation command as needed.

The iostat is a part of the sysstat package, which is really just a file that is read by a certain set of tools (such as iostat). So to install iostat, issue the command:

sudo apt install sysstat

Once the installation completes, you are ready to start using iostat.

Usage

If you issue the iostat command without arguments, it will display information about CPU usage, and I/O statistics for every partition on the system (Figure A).

Figure A

With that command, you see how much has been read and written, both in total and per second, for every device. For my example, I’m getting 155.52 KB written per second on /dev/sda, have had a total of 54659628 KB written since boot, 13.09 KB read per second, and 4601755 read since boot. I can compare that to what the average of that particular SSD drive should be, and then act accordingly. That command will also display CPU statistics, which can give you an idea if your CPU is causing problems on a system.

If you want to see those details in a more readable format, issue the command iostat -m, which will display the statistics in MB (instead of KB). The output of that command is shown in Figure B.

Figure B

What if you only want to see statistics for a specific device? Say you have a data drive you suspect might be having problems. The command to display only a specific device is iostat -p DEVICE (Where DEVICE is the name of the drive–such as sda or sdb). You can combine that option with the -m option, as in iostat -m -p sdb, to display the statistics of a single drive in a more readable format (Figure C).

Figure C

The above command will display stats for all partitions on that device. If you want to view the statistics for a specific partition, that command would be something like iostat -m -p sdb2.

Extended statistics

If you need extended statistics, you can issue the command with the -x argument, like so:

iostat -x -p sdb

The above command will add some important stats to the report. One of the more important stats is avgqu-sz; this particular stat shows the number of operations that were either queued or being serviced on a device. This stat should be in the single digits, with an occasional double-digit spike being okay.

The other extended stats reported are:

  • 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.
  • r_await–The average time (in milliseconds) for read requests issued to the device to be served.
  • w_await–The average time (in milliseconds) for write requests issued to the device to be served.
  • svctm–This field should be ignored (as it cannot be trusted). It was supposed to have been removed from sysstat.
  • %util–Percentage of elapsed time during which I/O requests were issued to the device.

Another very handy way to make use of iostat is by running it with an option to continue displaying stats for a device every five seconds, which is handy for device troubleshooting. The command to display stats every five seconds on device sdb would be iostat -m -p sdb 5. The output would refresh every five seconds (Figure D).

Figure D

To escape the output of this command, type the [Ctl]+[c] combination.

Keep reading

And that’s the gist of using the iostat command. To learn more about using this handy tool, read the man page with the command man iostat. You should find iostat a very useful tool to keep your Linux datacenter servers running smoothly.

Subscribe to the Data Insider Newsletter

Learn the latest news and best practices about data science, big data analytics, artificial intelligence, data security, and more. Delivered Mondays and Thursdays

Subscribe to the Data Insider Newsletter

Learn the latest news and best practices about data science, big data analytics, artificial intelligence, data security, and more. Delivered Mondays and Thursdays