Linux iostat command
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
- Monitor the read/write speed of a system's disk I/O
- View CPU utilization
- Gather device load statistics
- Identify I/O performance bottlenecks
1.2 Typical use cases
- Server performance tuning
- Storage device performance analysis
- System bottleneck troubleshooting
- Capacity planning
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
- %user: User-level (application) CPU usage
- %nice: CPU usage of processes with adjusted priority
- %system: System-level (kernel) CPU usage
- %iowait: Percentage of time the CPU waits for I/O operations to complete
- %steal: "Stolen" time in a virtualized environment
- %idle: Percentage of CPU idle time
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
- tps: Transfers per second
- kB_read/s: Amount of data read per second (KB)
- kB_wrtn/s: Amount of data written per second (KB)
- kB_read: Total amount of data read (KB)
- kB_wrtn: Total amount of data written (KB)
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
- rrqm/s: Number of read requests merged per second
- wrqm/s: Number of write requests merged per second
- r/s: Number of read I/O operations completed per second
- w/s: Number of write I/O operations completed per second
- rkB/s: KB read per second
- wkB/s: KB written per second
- avgrq-sz: Average data size per I/O operation (sectors)
- avgqu-sz: Average I/O queue length
- await: Average wait time per I/O operation (milliseconds)
- r_await: Average wait time for read operations (milliseconds)
- w_await: Average wait time for write operations (milliseconds)
- svctm: Average service time per I/O operation (milliseconds)
- %util: Device bandwidth utilization percentage
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
-
%util: Device utilization
80% means the device is close to saturation
- A sustained 100% means the device has become a bottleneck80% means the device is close to saturation
-
await: I/O wait time
50ms may indicate a performance problem
50ms may indicate a performance problem
-
avgqu-sz: Queue length
1 means the device may be overloaded
1 means the device may be overloaded
6.2 Diagnosing common problems
Problem 1: High %util but low throughput
- Possible cause: Too much random I/O
- Solution: Optimize the application's I/O pattern and consider using an SSD
Problem 2: High await but low %util
- Possible cause: A controller or bus bottleneck
- Solution: Check the HBA card or storage controller
Problem 3: Abnormally high rkB/s or wkB/s
- Possible cause: Heavy read/write activity by an application
- Solution: Optimize the application or add caching
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
- When monitoring in production, it is recommended to use the -x option to get detailed data
- For long-term monitoring, combine with sar to collect historical data
- When analyzing performance problems, pay attention to both CPU and I/O data
- 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