Linux Commands

How to Monitor Disk IO in Linux

iostat is used to get the input/output statistics for storage devices and partitions. iostat is a part of the sysstat package. With iostat, you can monitor the read/write speeds of your storage devices (such as hard disk drives, SSDs) and partitions (disk partitions). In this article, I am going to show you how to monitor disk input/output using iostat in Linux. So, let’s get started.

Installing iostat on Ubuntu/Debian:

The iostat command is not available on Ubuntu/Debian by default. But, you can easily install the sysstat package from the official package repository of Ubuntu/Debian using the APT package manager. iostat is a part of the sysstat package as I’ve mentioned before.

First, update the APT package repository cache with the following command:

$ sudo apt update

Now, install the sysstat package with the following command:

$ sudo apt install sysstat

sysstat package should be installed.

Installing iostat on CentOS 7:

iostat is not available on CentOS 7 by default. But, the sysstat package is available in the official package repository of CentOS 7. So, you can easily install it with the YUM package manager.

To install sysstat with the YUM package manager, run the following command:

$ sudo yum install sysstat

Now, press y and then press <Enter> to continue.

Now, press y and then press <Enter> to accept the GPG key of the CentOS 7 package repository.

sysstat should be installed.

Installing iostat on Arch Linux:

iostat is not available on Arch Linux by default. But, the sysstat package is available in the official package repository of Arch Linux. So, you can easily install it with the Pacman package manager.

To install sysstat, run the following command:

$ sudo pacman -Sy sysstat

Now, press y and then press <Enter> to continue.

sysstat should be installed.

Basic Usage of iostat:

You can monitor all the storage devices and disk partitions of your computer with iostat as follows:

$ sudo iostat

As you can see, iostat generated a report of read/write speeds (in kilobytes/second or kB/s) and total reads/writes (in kB) of every storage devices and partitions at that time.

In the above command, iostat prints the statistics at the instance you ran iostat only. This is good for shell scripting and automation.

If you want to see real time statistics, then you can tell iostat to update the report every n seconds (let’s say 2 seconds) interval as follows:

$ sudo iostat -d 2

As you can see, iostat is updating the report every 2 seconds.

Monitoring Specific Storage Devices or Partitions with iostat:

By default, iostat monitors all the storage devices of your computer. But, you can monitor specific storage devices (such as sda, sdb etc) or specific partitions (such as sda1, sda2, sdb4 etc) with iostat as well.

For example, to monitor the storage device sda only, run iostat as follows:

$ sudo iostat sda

Or

$ sudo iostat -d 2 sda

As you can see, only the storage device sda is monitored.

You can also monitor multiple storage devices with iostat.

For example, to monitor the storage devices sda and sdb, run iostat as follows:

$ sudo iostat sda sdb

Or

$ sudo iostat -d 2 sda sdb

If you want to monitor specific partitions, then you can do so as well.

For example, let’s say, you want to monitor the partitions sda1 and sda2, then run iostat as follows:

$ sudo iostat sda1 sda2

Or

$ sudo iostat -d 2 sda1 sda2

As you can see, only the partitions sda1 and sda2 are monitored.

Monitoring LVM Devices with iostat:

You can monitor the LVM devices of your computer with the -N option of iostat.

To monitor the LVM devices of your Linux machine as well, run iostat as follows:

$ sudo iostat -N -d 2

You can also monitor specific LVM logical volume as well.

For example, to monitor the LVM logical volume centos-root (let’s say), run iostat as follows:

$ sudo iostat -N -d 2 centos-root

Changing the Units of iostat:

By default, iostat generates reports in kilobytes (kB) unit. But there are options that you can use to change the unit.

For example, to change the unit to megabytes (MB), use the -m option of iostat.

You can also change the unit to human readable with the -h option of iostat. Human readable format will automatically pick the right unit depending on the available data.

To change the unit to megabytes, run iostat as follows:

$ sudo iostat -m -d 2 sda

To change the unit to human readable format, run iostat as follows:

$ sudo iostat -h -d 2 sda

I copied as file and as you can see, the unit is now in megabytes (MB).

It changed to kilobytes (kB) as soon as the file copy is over.

Extended Display of iostat:

If you want, you can display a lot more information about disk i/o with iostat. To do that, use the -x option of iostat.

For example, to display extended information about disk i/o, run iostat as follows:

$ sudo iostat -x -d 2 sda

You can find what each of these fields (rrqm/s, %wrqm etc) means in the man page of iostat.

Getting Help:

If you need more information on each of the supported options of iostat and what each of the fields of iostat means, I recommend you take a look at the man page of iostat.

You can access the man page of iostat with the following command:

$ man iostat

So, that’s how you use iostat in Linux. Thanks for reading this article.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.