Linux iostat Command
1. Overview of the iostat Command
iostat (Input/Output Statistics) is a powerful performance monitoring tool on Linux systems and is part of the sysstat package. It is mainly used to monitor system disk I/O activity and CPU usage.
1.1 Basic Functions
- Monitor system disk I/O read/write speed
- View CPU utilization
- Summarize device load
- Identify I/O performance bottlenecks
1.2 Typical Application Scenarios
- Server performance tuning
- Storage device performance analysis
- System bottleneck troubleshooting
- Capacity planning
2. Installation and Basic Usage
2.1 Installation Methods
Most Linux distributions do not install iostat by default; 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
sudo apt-get install sysstat
# CentOS/RHEL
sudo yum install sysstat
# Fedora
sudo dnf install sysstat
2.2 Basic Command Format
Example
iostat [Options] [Interval] [Count]
Simple Example
Example
# Display statistics for all devices once
iostat
# Refresh every 2 seconds, display 5 times in total
iostat 2 5
iostat
# Refresh every 2 seconds, display 5 times in total
iostat 2 5
3. Detailed Command Options
3.1 Common Options
| Option | Description |
|---|---|
| -c | Display only CPU usage |
| -d | Display only disk usage |
| -h | Display in human-readable format (e.g., KB, MB, GB) |
| -k | Display data in KB |
| -m | Display data in MB |
| -N | Display device mapping names |
| -p | Display statistics for a specified device or partition |
| -t | Display timestamp |
| -x | Display extended statistics |
| -y | Skip the first report (usually used with an interval) |
3.2 Advanced Options
| Option | Description |
|---|---|
| -z | Omit output for devices with zero activity |
| -j ID | Display persistent names for specified devices |
| --dec={0|1|2} | Specify the number of decimal places |
4. Interpreting Output Results
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 virtual environments
- %idle: CPU idle time percentage
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 (-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 merged read requests per second
- wrqm/s: Number of merged write requests per second
- r/s: Number of completed read I/O operations per second
- w/s: Number of completed write I/O operations 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
5. Practical Example Analysis
5.1 Monitor a Specific Disk
Example
# Monitor sda disk, refresh every 2 seconds, display 3 times in total
iostat -d -x sda 2 3
iostat -d -x sda 2 3
5.2 Comprehensive Monitoring of CPU and Disk
Example
# Monitor CPU and disk, refresh every 5 seconds, display continuously
iostat -c -d -x -t 5
iostat -c -d -x -t 5
5.3 Display in MB
Example
# Display disk statistics in MB
iostat -d -m
iostat -d -m
5.4 Monitor All Partitions
Example
# Monitor all partitions, including LVM
iostat -p ALL
iostat -p ALL
6. Performance Metrics Interpretation and Optimization Suggestions
6.1 Key Performance Metrics
%util: Device utilization
80% indicates the device is approaching saturation
- Sustained 100% indicates the device has become a bottleneck
await: I/O wait time
- Normally should be < 10ms
50ms indicates possible performance issues
avgqu-sz: Queue length
> 1 indicates the device may be overloaded
6.2 Common Problem Diagnosis
Problem 1: High %util but low throughput
- Possible cause: Excessive random I/O
- Solution: Optimize the application I/O pattern, consider using SSDs
Problem 2: High await but low %util
- Possible cause: Controller or bus bottleneck
- Solution: Check the HBA card or storage controller
Problem 3: Abnormally high rkB/s or wkB/s
- Possible cause: Applications performing heavy reads/writes
- Solution: Optimize the application or increase cache
7. Integration with Other Tools
7.1 Combining with vmstat
Example
# Monitor memory and I/O simultaneously
vmstat 1 5 & iostat -x 1 5
vmstat 1 5 & iostat -x 1 5
7.2 Combining with sar
Example
# View historical I/O data
sar -d
sar -d
7.3 Combining with iotop
Example
# Identify specific high-I/O processes
iotop
iotop
8. Summary and Best Practices
8.1 Usage Recommendations
- In production environment monitoring, it is recommended to use the -x option for detailed data
- For long-term monitoring, use sar to collect historical data
- When analyzing performance issues, pay attention to both CPU and I/O data
- Comparing statistics from different time periods is more meaningful
8.2 Common Command Combinations
Example
# 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
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 the I/O performance of Linux systems and promptly detect and resolve storage-related performance bottlenecks.
Other Extensions
Linux Command Encyclopedia