The iostat command is an essential command to evaluate the efficiency of I/O devices in Linux systems. It also measures CPU usage concerning time. Hence, it is essential to learn how to use the iostat command on Linux.
The iostat command generates a monitoring report for the CPU and input/output (I/O) devices. In addition, this report helps change the system configuration to balance the load between I/O and physical disks.
In this article, we will look at how to install and use the iostat command on Linux. We will also be covering basic iostat examples and how it helps with determining the I/O and CPU usage concerning time. So, let’s dive in!
Install Iostat Command on Linux
The iostat command is not installed on Linux systems by default. Hence, users usually have to install this package using the package manager. The package manager depends on the version of the Linux system. To install the
iostat command on RedHat/CentOS/Fedora, use the yum package. For instance:
yum install sysstat
However, you should be using the apt package manager for other Linux distributions. For example:
sudo apt install sysstat
The output would look something like this:
In case you get the dpkg error while installing as seen below:
Use this alternative command to fix the error instead:
sudo dpkg –configure -a
Use Iostat Command on Linux
To start using the iostat command on Linux, open the Terminal from the Applications panel. Alternatively, you can also use the shortcut key, “Ctrl+Alt+T” to open it. Next, type in the command ‘
iostat‘ in the Terminal. Input the following:
You should get a similar output like this one:
The command will now show statistical reports since the system has started booting. Every time you execute this command, you will get a subsequent report that covers the time since the previous report. It is divided into two parts, the CPU Utilization Report, and Devices Utilization Report.
CPU Utilization Report of Iostat Command on Linux
The CPU report displays the CPU performance using different parameters. These parameters are:
%user: The amount of CPU used by each user (or application) displayed in percentage.
%nice: This tag shows the usage of CPU in percentage at a user level with nice priority.
%system: This tag indicates the CPU usage at the system or kernel level.
%iowait: IOWait is the time (in percentage) in which the Kernel gets the I/O request.
%steal: This tag shows the time (in percentage) in which the CPU waited voluntarily.
%idle: Idle time is the time in percentage in which the Kernel gets no I/O request.
Device Utilization Report of Iostat Command on Linux
The next section of this report, the Devices Utilization Report, displays the performance of I/O devices using the following parameters:
Device: Lists all the I/O devices whose report is displayed.
Tps: It lists the tps (transfers per second) when the I/O device makes a transfer request to the CPU.
kB_read/s: The amount of data read by CPU per second.
kB_wrtn/s: The amount of data written by the CPU per second.
kB_dscd/s: The rate of data discarded by CPU per second.
kB_read: The total number of blocks of data read by the CPU.
kB_wrtn: The total number of blocks of data written by the CPU.
The data shown in report is collected by the iostat command from the following directories:
/proc/stat: System statistics
/proc/uptime: System uptime
/proc/diskstats: Disk statistics
/sys: Statistics for block devices
/proc/self/mountstats: Data for network filesystems.
Iostat Command Syntax
To use the
iostat command with different options and for each device, here is the general syntax as seen below:
iostat [option] [device-name]
Use Iostat Command on Linux with Different Options
There are many options available with the
iostat command. You can access all those options using the man command. For example:
Now that we’ve tackled all that, let’s look at some examples of iostat commands with different options.
Check Iostat Version
To check the iostat version, type the ‘
iostat‘ command followed by the
The output would look something like this:
Display CPU Report
To display the CPU report only, use the
-c option with the iostat command. Type in the following:
And this is what the report should look like:
Display I/O Report
If in case you only want to view the device report, use the
-d flag. Specifically input:
And you will get a similar output:
Display Detailed Report
Alternatively, you can also view the report in detail by using the
-x option. For example:
You will notice that there are new parameters in the report consisting of device details. To find out more about these parameters, visit this link.
Display Report in Different Units
If you wish to view the report details in MegaBytes (MBs) instead of KiloBytes (KBs) or KBs instead of MBS, you can use the
-m options. To be specific, input the following commands:
iostat -m iostat -k
Display Report in JSON Format
To view the CPU and Device report in JSON format, you can use the
-j flag. For example:
iostat -o JSON
IThe JSON format should look something like this:
Display Continuous Report
To view the CPU or I/O status report after a fixed interval, let’s say two-second intervals, use the number two (2) after the command. For example:
iostat -d 2
This command will display the device status report after every two seconds. To break the operation, press “Ctrl + C”. Alternatively, you can fix the number of reports you want to view and after what interval. For instance, you wish to view six reports after every two seconds, execute the command:
iostat -d 2 6
Use Multiple Options with Iostat Command
Instead of using options and flags separately to generate a report, you can use multiple options together with the iostat command. For instance, you want to print the report of devices in MBs with a human-readable format. To achieve this, simply execute the command given below:
Invoking the command above will get you the device-only report, showing the usage in MBs in the following easy to digest format:
Alternatively, you can also use the
–pretty option to view the report in a human-readable format.
The iostat command is quite useful in measuring the performance of the CPU and I/O devices in Linux systems. In this article, you did not only learn how to install and use the iostat command, you also found out how to customize the iostat reports using various options. We hope you found this article to be helpful.
If this guide helped you, please share it.