Installing and Utilizing iostat on Ubuntu

Iostat is a powerful command-line utility designed to provide in-depth statistics about input/output operations on system devices, such as disks. It is bundled with the sysstat package and is easily installed via apt. The iostat command is invaluable for monitoring the performance of storage devices. It provides critical metrics such as the volume of data read or written, the time spent waiting for I/O operations, and the percentage of CPU time devoted to I/O tasks. Particularly, iostat is beneficial for identifying disk bottlenecks and optimizing system performance.

In this tutorial, we will guide you through installing and utilizing the iostat tool on Ubuntu Linux. This guide supports all Ubuntu versions from 16.04 to 24.04.

Prerequisites

  • Ubuntu desktop or server installed on your system.
  • A non-root user configured with sudo privileges.

Installing iostat

The iostat utility is part of the sysstat package, available by default in Ubuntu repositories. To install it, execute the following command:

sudo apt install sysstat -y

Once sysstat is installed, you are ready to proceed with using iostat.

Basic Usage of iostat

To begin using iostat, run the command without any arguments. This command provides information about CPU usage and I/O statistics for your system:

iostat

Example 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 above output offers insights into CPU time utilization and device usage statistics. It displays device-specific data, including transaction rates, read/write operations per second, and total block metrics.

To include the current time in the report, use:

iostat -t

Example 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

For the version information of iostat, run:

iostat -V

Output:

sysstat version 10.2.0
(C) Sebastien Godard (sysstat  orange.fr)

To display all available options with the iostat command, use:

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 ]

Advanced Usage Examples of iostat

To view only the device report a single time, execute:

iostat -d

Example 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

For continuous device reports every 5 seconds, repeated 3 times, use:

iostat -d 5 3

Example 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

To view statistics for specific devices, use:

iostat -p sda

Example 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 specify multiple devices:

iostat -p sda, sdb, sdc

To view I/O statistics in MB/second, use:

iostat -m

Example 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

For extended statistics on a specific partition (e.g., sda4), run:

iostat -x sda4

Example 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

To display only the CPU usage statistics, use:

iostat -c

Example 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

Frequently Asked Questions (FAQ)

What is iostat used for?

iostat is used for monitoring the I/O performance of disk drives by displaying in-depth statistics about their activity, helping diagnose bottlenecks and optimize performance.

Is iostat compatible with all Linux distributions?

iostat is available on most Linux distributions that support the sysstat package, though specific installation steps may vary.

Can iostat monitor multiple devices simultaneously?

Yes, iostat can monitor multiple devices at once. Specify devices separated by commas, e.g., iostat -p sda, sdb, sdc.

How can I display I/O statistics in megabytes per second?

Use the -m option with iostat to display statistics in MB/second.

Does iostat only provide statistics at the device level?

No, iostat can also provide statistics at the partition level using options like -x for extended statistics and -p for specific partitions.