Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux iostat command

Linux iostat command

Linux Command Reference Linux Command Reference


I. Overview of the iostat command

iostat (Input/Output Statistics) is a powerful performance monitoring tool on Linux systems and is part of the sysstat toolkit. It is mainly used to monitor a system's disk I/O activity and CPU usage.

1.1 Basic functions

1.2 Typical use cases


II. Installation and basic usage

2.1 Installation method

Most Linux distributions do not install iostat by default, so you need to install the sysstat package first:

Example

Ubuntu/Debian

sudo

apt-get install

sysstat

CentOS/RHEL

sudo

yum install

sysstat

Fedora

sudo

dnf

install

sysstat

2.2 Basic command format

Example

iostat

[

Option

]

[

Time interval

]

[

Count

]

Simple Example

Example

Display statistics for all devices once

iostat

Refresh every 2 seconds, 5 times in total

iostat

2

5


III. Detailed command options

3.1 Common options

Option Description
-c Show CPU usage only
-d Show disk usage only
-h Display in a human-readable format (such as KB, MB, GB)
-k Display data in KB
-m Display data in MB
-N Show device mapper names
-p Show statistics for the specified devices or partitions
-t Show timestamps
-x Show extended statistics
-y Skip the first statistics report (usually used together with a time interval)

3.2 Advanced options

Option Description
-z Omit output for devices with zero activity
-j ID Show persistent names for the specified devices
--dec={0|1|2} Specify the number of decimal places

IV. Interpreting the output

4.1 CPU statistics section

avg-cpu:  %user   %nice %system %iowait  %steal   %idle

           5.32    0.00    1.06    0.25    0.00   93.37

4.2 Disk statistics section (basic)

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn

sda               1.02        12.34         5.67    1234567     567890

4.3 Extended statistics (the -x option)

Device:  rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util

sda       0.00     0.50    1.00    0.50    12.00     4.00    21.33     0.02   10.00    8.00   14.00   6.00   0.90


V. Practical example analysis

5.1 Monitor a specific disk

Example

Monitor the sda disk, refreshing every 2 seconds, 3 times in total

iostat

-d

-x

sda

2

3

5.2 Monitor CPU and disk together

Example

Monitor CPU and disk, refreshing every 5 seconds, continuously

iostat

-c

-d

-x

-t

5

5.3 Display in MB

Example

Display disk statistics in MB

iostat

-d

-m

5.4 Monitor all partitions

Example

Monitor all partitions, including LVM

iostat

-p

ALL


VI. Interpreting performance metrics and optimization tips

6.1 Key performance metrics

  1. %util: Device utilization

  2. 80% means the device is close to saturation

  3. A sustained 100% means the device has become a bottleneck
  4. -

    80% means the device is close to saturation

    - A sustained 100% means the device has become a bottleneck
    1. await: I/O wait time

    2. Under normal circumstances it should be < 10ms
    3. 50ms may indicate a performance problem

    4. - Under normal circumstances it should be < 10ms -

      50ms may indicate a performance problem

      1. avgqu-sz: Queue length

      2. 1 means the device may be overloaded

      3. -

        1 means the device may be overloaded

        6.2 Diagnosing common problems

        Problem 1: High %util but low throughput

        Problem 2: High await but low %util

        Problem 3: Abnormally high rkB/s or wkB/s


        VII. Use with other tools

        7.1 Combined with vmstat

        Example

        Monitor memory and I/O at the same time

        vmstat

        1

        5

        &

        iostat

        -x

        1

        5

        7.2 Combined with sar

        Example

        View historical I/O data

        sar

        -d

        7.3 Combined with iotop

        Example

        Identify specific high-I/O processes

        iotop


        VIII. Summary and best practices

        8.1 Usage recommendations

        1. When monitoring in production, it is recommended to use the -x option to get detailed data
        2. For long-term monitoring, combine with sar to collect historical data
        3. When analyzing performance problems, pay attention to both CPU and I/O data
        4. Comparing statistics across different time periods is more meaningful

        8.2 Common command combinations

        Example

        A comprehensive monitoring command

        iostat

        -c

        -d

        -x

        -t

        -m

        5

        Monitor only extended disk information

        iostat

        -d

        -x

        2

        Monitor a specific partition

        iostat

        -p

        sda1

        -x

        1

        10

        By mastering the iostat command, system administrators can effectively monitor and analyze a Linux system's I/O performance and promptly detect and resolve storage-related performance bottlenecks.

        Linux Command Reference Linux Command Reference