mpstat Command
Display CPU statistics and performance metrics for multiprocessor systems.
Syntax
The mpstat command displays activities for each available processor, processor 0 being the first one. Global average activities among all processors are also reported.
Common Options
| Option | Description |
|---|---|
-A |
Display all statistics (equivalent to -u -I ALL) |
-I {SUM|CPU|SCPU|ALL} |
Display interrupt statistics |
-P {cpu_list|ALL} |
Display statistics for specific processors |
-u |
Display CPU utilization report (default) |
-V |
Print version number and exit |
-o JSON |
Display statistics in JSON format |
-T |
Display timestamp for each report |
-h |
Display help message |
CPU Metrics Explained
| Metric | Description | Good Range |
|---|---|---|
%usr |
Percentage of CPU used by user processes | < 70% |
%nice |
Percentage of CPU used by nice processes | Variable |
%sys |
Percentage of CPU used by system processes | < 30% |
%iowait |
Percentage of CPU waiting for I/O operations | < 10% |
%irq |
Percentage of CPU servicing hardware interrupts | < 5% |
%soft |
Percentage of CPU servicing software interrupts | < 5% |
%steal |
Percentage of CPU stolen by hypervisor | < 5% |
%guest |
Percentage of CPU used by guest OS | Variable |
%idle |
Percentage of CPU idle time | > 20% |
Basic Examples
Basic CPU statistics
Basic CPU utilization monitoring
Per-CPU statistics
Monitor individual CPU cores and overall system
Interrupt statistics
Monitor interrupt activity and distribution
Advanced Usage
Comprehensive monitoring
Complete system monitoring with all metrics
Output formatting
Format output for analysis and logging
Specific monitoring scenarios
Targeted monitoring for specific performance issues
Performance Analysis
Identifying CPU bottlenecks
Analyze CPU performance patterns and bottlenecks
Load balancing analysis
Analyze workload distribution across CPU cores
Practical Examples
System monitoring scripts
Automated CPU monitoring and alerting
Performance troubleshooting
Comprehensive performance analysis workflow
Capacity planning
Long-term monitoring for capacity planning
Integration with Other Tools
Combining with system tools
Combine mpstat with other monitoring tools
Data collection and analysis
Collect and format data for further analysis
Troubleshooting
Common Issues
- Command not found - sysstat package not installed
- No data displayed - Insufficient permissions or system issues
- Inconsistent readings - System under heavy load
- Missing CPU cores - CPU hotplug or virtualization issues
Installation and setup
Install and configure sysstat package
Common troubleshooting
Diagnose system and CPU-related issues
Best Practices
Monitoring Guidelines
- Use appropriate intervals - 1-5 seconds for troubleshooting, 5-15 minutes for trending
- Monitor all CPUs on multi-core systems with -P ALL
- Include timestamps for historical analysis
- Combine with other tools for complete system view
- Set up automated alerts for critical thresholds
- Archive historical data for capacity planning
Performance Interpretation
- High %usr - Application bottleneck, consider optimization
- High %sys - System call overhead, kernel bottleneck
- High %iowait - I/O bottleneck, check disk performance
- High %steal - Virtualization overhead, resource contention
- Uneven CPU distribution - Load balancing issues
- High interrupt rates - Hardware or driver issues