The iostat is the command in Linux and Unix-like operating systems. This command is useful to monitor system input, output, and CPU utilization details for device and partitions. So, you can say that it monitors system I/O device load as it observes the time the devices are active to their average transfer rates.

Also, You can use the report from this command to change the system configuration. So, a better balance can happen between physical disks for input and output load.

Importantly, if you generate the first report then it will create the report from the system booted. And, again when you generate the report, it will create after the last report.

Types of report generate by iostat command

  • CPU utilization report
  • All disks input and output report

System files used by iostat command

Some files are used by iostat command to generate the report. So, you can find the list of that system files below.

  • /proc/stat this is the file to get the system statistics.
  • /sys this is the directory to get the block device statistics
  • /proc/uptime this is the file that contains the system uptime.
  • /proc/diskstats this is the file that contains the disks statistics.
  • /dev/disk this is the directory that contains the persistent device names.
  • /proc/self/mountstats this is the file that contains the statistics for network filesystems.

Installation of the iostat

So if you want to install iostat then you have to install a sysstat software package. You can find the below commands useful to install it.

Installation of iostat on CentOS/RHEL 6/7

If you want to install on CentOS/RHEL 6 and 7 then you can use the below command. Also, this command is useful for CentOS/RHEL 8.

sudo yum -y install sysstat

Installation of iostat on CentOS/RHEL 8 and Fedora

Also, You can use the below command to install on CentOS/RHEL 8 and Fedora.

sudo dnf -y install sysstat

Installation of iostat on Debian/Ubuntu/Mint

If you are installing on Debian, Ubuntu, or Mint then you can use the below command.

sudo apt-get -y install sysstat

Note: There is no service for this software package.

How to get help for the iostat command

I always suggest reading the manual page and help. This will give you a deep introduction to the command.

So, to get the manual page type the below command,

man iostat

Also, to get the only command options, you can type the below command.

iostat --help

Syntax of the iostat command

As we know now, how to get some information about the iostat command using the above command with arguments. Now let’s talk about iostat syntax. The syntax of the iostat command is mentioned below,

Syntax:

iostat [ -c ] [ -d ] [ -h ] [ -k | -m ] [ -N ] [ -t ] [ -V ] [ -x ] [ -y ] [ -z ] [ -j { ID | LABEL | PATH |
UUID | … } ] [ [ -T ] -g group_name ] [ -p [ device [,…] | ALL ] ] [ device […] | ALL ] [ interval [
count ] ]

Syntax simplified

iostat [option] [interval] [count]

  • the interval parameter specifies the duration of time in seconds between each report
  • Count parameter allows you to specify the number of reports that are generated before iostat exits.

The most frequently used option with iostat command

There is the list of most frequently used options along with iostat, you can find the list below.

  • -x: to get more details oriented statistics information.
  • -c: to get the only CPU statistics.
  • -d: this will display the only device report.
  • -xd: to get the extended input and output statistic for the device only.
  • -k: To get the statistics in kilobytes or megabytes.
  • -k 2 3: to get CPU and device statistics with delay.
  • -p: to get statistics for block devices.
  • -N: to get lvm2 statistic information.

Generating the statistics report using iostat command

So, if you want to get the complete statistics report then you can use the below command.

iostat

As a result, you will get the below output on the screen.

iostat-command
The output of the iostat command

Firstly, you can see that the CPU report. But, this report is in percentage.

  • %user: this is the percentage of the CPU utilization for the user.
  • %nice: this is the percentage of the CPU utilization for apps with nice priority.
  • %system: this is the percentage of the CPU utilization that occurred while executing at the system (kernel) level.
  • %iowait: this is the time percentage during which CPU was idle but there was an outstanding I/O request.
  • %steal: This is the percentage of time when the CPU was waiting because the hypervisor was working on another CPU.
  • %idle: this is the percentage of time that the CPU was idle and the system did not have any outstanding disk I/O request.

Secondly, you can see the device utilization report.

  • Device: This is the name of the device or partition. And, it shows all as in /dev directory.
  • tps: this indicates the number of transfers per second that were issued to the device.
  • kB_read/s: this indicates the amount of data read from the device expressed in some blocks (kilobytes, megabytes) per second.
  • kB_wrtn/s: this indicates the amount of data written to the device expressed in some blocks (kilobytes, megabytes) per second.
  • kB_read: The total number of blocks (kilobytes, megabytes) read.
  • kB_wrtn: The total number of blocks (kilobytes, megabytes) written.

Generating the detail statistics report using iostat command

Similarly, If you want to get more detail based output then you have to use -x option along with iostat command. So, you can use the below command for this purpose.

iostat -x

As a result, you will get the below output on the screen.

 

iostat-x-command
The output of the iostat command using the option -x

The iostat terms defined below from the above picture

  • rrqm/s: The number of reading 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 reading requests completed per second for the device.
  • w/s: The number (after merges) of write requests completed per second for the device.
  • rkB/s: The number of sectors (kilobytes, megabytes) read from the device per second.
  • wkB/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. So, This includes the time spent by the requests in queue and the time spent servicing them.
  • r_await: The average time (in milliseconds) for reading requests issued to the device to be served. So, 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. So, 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 anymore. This field will be removed in a future sysstat version.
  • %util: Percentage of elapsed 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%.

Getting the CPU report only using iostat command

For example, you can also generate only the CPU report then there is an option -c. So, use the below command to complete this task.

iostat -c

As a result, you will get the below output on the screen.

iostat-c-command
The output of the iostat command using the -c argument

Getting the I/O report for all the devices only using iostat command

For example, if you want to generate the report only for the connected devices then there is an option -d. So, you can use the below command.

iostat -d

As a result, you will get the below output on the screen.

iostat-d-command
The output of the iostat command using the -d argument

Getting the detail I/O report for all the devices only using iostat command

For example, if you want to get a detailed report for all the devices connected with the system. So, you can use the -xd option along with iostat command. In short, you can use the below command for that.

iostat -xd

As a result, you will get the below output on the screen.

iostat-xd-command
The output of the iostat command using the -xd argument

Getting report in KB or MB using the iostat command

So, if you want to get the report in kilobytes then you can use the -k option along with iostat command. But, if you want to get the report in megabytes then you use the -m argument along with iostat command. Thus, you can see both commands below.

Firstly, to get the report in KB, use the below command

iostat -k

As a result, you will get the below output on the screen.

iostat-k-command
The output of the iostat command using the -k argument

Secondly, to get the report in MB, use the below command.

iostat -m

As a result, you will get the below output on the screen.

iostat-m-command
The output of the iostat command using the -m argument

Getting system I/O statistics report with delay

So, if you want to get the report with a delay then you can mention the iostat command followed by an interval in seconds and the number of the reports required.

For example, I want to see the report with an interval of 5 seconds and 2 times. As a result, the command will be as below.

iostat 5 2

As a result, you will get the below output on the screen.

iostat-5-2-command
The output of the iostat command using 5 seconds and twice report argument

Getting the LVM statistics report

Similarly, if you want to get the report for LVM statistics then you can use the -N option along with iostat command.

iostat -N

As a result, you will get the below output on the screen.

iostat-N-command
The output of the iostat command using the -N argument

Getting I/O statistics for a single device

To get the report for a specific single device, you can use the -p option along with device name and iostat command. So, you can see the below command is helpful for it.

For example, I am generating a report for device sda. But, you can change it as per your device.

iostat -p sda

As a result, you will get the below output on the screen.

iostat-p-sda-command
The output of the iostat command using the -p argument and device name sda

Getting iostat reports with a timestamp

In case, you want to get the report along with timestamp then you can use the option -t.

iostat -t 

As a result, you will get the below output on the screen.

iostat-t-command
The output of the iostat command using the -t argument

Getting statistics report with the device UUID

For instance, as per now you want to generate a report based on the persistent device. So, you have to get the UUID of the device using the blkid command.

Firstly, we are going to get the UUID using the blkid command.

blkid

As a result, you will get the below output on the screen.

blkid
The output of the blkid command

Secondly, after getting the UUID from the blkid command, run the below command and replace the UUID with your device UUID.

iostat -j id 20a92fbc-b4d4-4358-a550-4680487a39e7

As a result, you will get the below output on the screen.

iostat-j-id-command
The output of the iostat command using the -j argument along with UUID of the device

Generating I/O statistics for Network File System(NFS)

Lastly, if you are using the nfs server and you want to generate the report for that then you can use the below command.

nfsiostat

Note: nfsiostat command is the part of the software package nfs-utils. So, if you want to learn about nfs server then you visit the link How to set up NFS server on CentOS/RHEL 7

As a result, you will get the below output on the screen.

nfsiostat-command
The output of the nfsiostat command

Conclusion

Briefly, you learn about iostat command and its use. I hope you understand but if you have any questions, you can ask in the comment section.

You can get the manual page by visiting the man7 page

Leave a Reply