Iostat is a command-line utility that provides detailed statistics about input/output operations on system devices, such as disks. It is part of the sysstat package, which you can install using apt. iostat helps monitor the performance of storage devices by reporting metrics like the amount of data read or written, the time spent waiting for I/O operations, and the percentage of CPU time spent on I/O tasks. This tool is especially useful for diagnosing disk bottlenecks and optimizing system performance.
In this tutorial, we will learn how to install and use the iostat software on Ubuntu Linux. This guide is compatible with all Ubuntu versions between 24.04 and 16.04.
Prerequisite
- Ubuntu desktop or server installed on your system.
- Non-root user with sudo privileges setup on your system
Install iostat
By default, iostat is included with sysstat package in Ubuntu. You can easily install it by just running the following command:
sudo apt install sysstat -y
Once sysstat is installed, you can proceed to the next step.
iostat Basic Example
Let’s start by running the iostat command without any argument. This will displays information about the CPU usage, and I/O statistics of your system:
iostat
You should see the following output:
Linux 3.19.0-25-generic (Ubuntu-PC) Saturday 16 December 2017 _x86_64_ (4 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 22.67 0.52 6.99 1.88 0.00 67.94 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 15.15 449.15 119.01 771022 204292
The first line displays the Linux kernel version and hostname in the above output. The next two lines display CPU statistics like average CPU usage, the percentage of time the CPU was idle and waited for I/O response, the percentage of waiting time of virtual CPU, and the percentage of time the CPU is idle. The next two lines display the device utilization report, like the number of blocks read and written per second, and the total block reads and writes per second.
By default, iostat displays the report with the current date. If you want to display the current time, run the following command:
iostat -t
You should see the following output:
Linux 3.19.0-25-generic (Ubuntu-PC) Saturday 16 December 2017 _x86_64_ (4 CPU) Saturday 16 December 2017 09:44:55 IST avg-cpu: %user %nice %system %iowait %steal %idle 21.37 0.31 6.93 1.28 0.00 70.12 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 9.48 267.80 79.69 771022 229424
To check the version of the iostat, run the following command:
iostat -V
Output:
sysstat version 10.2.0 (C) Sebastien Godard (sysstatorange.fr)
You can list out all the options available with iostat command using the following command:
iostat --help
Output:
Usage: iostat [ options ] [[ ] ] Options are: [ -c ] [ -d ] [ -h ] [ -k | -m ] [ -N ] [ -t ] [ -V ] [ -x ] [ -y ] [ -z ] [ -j { ID | LABEL | PATH | UUID | ... } ] [ [ -T ] -g ] [ -p [ [,...] | ALL ] ] [ [...] | ALL ]
iostat Advance Usage Example
If you want to view only the device report only once, run the following command:
iostat -d
You should see the following output:
Linux 3.19.0-25-generic (Ubuntu-PC) Saturday 16 December 2017 _x86_64_ (4 CPU) Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 12.18 353.66 102.44 771022 223320
To view the device report continuously for every 5 seconds, for 3 times:
iostat -d 5 3
You should see the following output:
Linux 3.19.0-25-generic (Ubuntu-PC) Saturday 16 December 2017 _x86_64_ (4 CPU) Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 11.77 340.71 98.95 771022 223928 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 2.00 0.00 8.00 0 40 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 0.60 0.00 3.20 0 16
If you want to view the statistics of specific devices, run the following command:
iostat -p sda
You should see the following output:
Linux 3.19.0-25-generic (Ubuntu-PC) Saturday 16 December 2017 _x86_64_ (4 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 21.69 0.36 6.98 1.44 0.00 69.53 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 11.00 316.91 92.38 771022 224744 sda1 0.07 0.27 0.00 664 0 sda2 0.01 0.05 0.00 128 0 sda3 0.07 0.27 0.00 648 0 sda4 10.56 315.21 92.35 766877 224692 sda5 0.12 0.48 0.02 1165 52 sda6 0.07 0.32 0.00 776 0
You can also view the statistics of multiple devices with the following command:
iostat -p sda, sdb, sdc
If you want to display the device I/O statistics in MB/second, run the following command:
iostat -m
You should see the following output:
Linux 3.19.0-25-generic (Ubuntu-PC) Saturday 16 December 2017 _x86_64_ (4 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 21.39 0.31 6.94 1.30 0.00 70.06 Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn sda 9.67 0.27 0.08 752 223
If you want to view the extended information for a specific partition (sda4), run the following command:
iostat -x sda4
You should see the following output:
Linux 3.19.0-25-generic (Ubuntu-PC) Saturday 16 December 2017 _x86_64_ (4 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 21.26 0.28 6.87 1.19 0.00 70.39 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util sda4 0.79 4.65 5.71 2.68 242.76 73.28 75.32 0.35 41.80 43.66 37.84 4.55 3.82
If you want to display only the CPU usage statistics, run the following command:
iostat -c
You should see the following output:
Linux 3.19.0-25-generic (Ubuntu-PC) Saturday 16 December 2017 _x86_64_ (4 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 21.45 0.33 6.96 1.34 0.00 69.91
About Hitesh Jethva
Over 8 years of experience as a Linux system administrator. My skills include a depth knowledge of Redhat/Centos, Ubuntu Nginx and Apache, Mysql, Subversion, Linux, Ubuntu, web hosting, web server, Squid proxy, NFS, FTP, DNS, Samba, LDAP, OpenVPN, Haproxy, Amazon web services, WHMCS, OpenStack Cloud, Postfix Mail Server, Security etc.