vmstat
Overview
The vmstat command reports virtual memory statistics. It provides information about processes, memory, paging, block IO, traps, and CPU activity.
Syntax
vmstat [options] [delay [count]]Common Options
| Option | Description |
|---|---|
-a |
Active/inactive memory |
-f |
Fork statistics |
-m |
Slab info |
-n |
Header once |
-s |
Event counters |
-d |
Disk statistics |
-p partition |
Partition stats |
-S unit |
Output units |
-t |
Timestamp |
-w |
Wide output |
Output Fields
| Field | Description |
|---|---|
| r | Running processes |
| b | Blocked processes |
| swpd | Virtual memory |
| free | Idle memory |
| buff | Buffer memory |
| cache | Cache memory |
| si | Swapped in |
| so | Swapped out |
| bi | Blocks in |
| bo | Blocks out |
| in | Interrupts |
| cs | Context switches |
| us | User time |
| sy | System time |
| id | Idle time |
| wa | IO wait |
| st | Stolen time |
Key Use Cases
- Memory monitoring
- System performance
- IO analysis
- CPU utilization
- Process states
Examples with Explanations
Example 1: Basic Usage
vmstatCurrent statistics
Example 2: Continuous
vmstat 2 10Every 2s, 10 times
Example 3: Disk Stats
vmstat -dShow disk statistics
Common Usage Patterns
Real-time monitoring:
vmstat 1Memory details:
vmstat -sDisk activity:
vmstat -d -p /dev/sda1
Additional Resources
Best Practices
- Regular monitoring
- Set intervals
- Compare trends
- Document baselines
- Check all metrics
Performance Analysis
- Memory usage
- CPU utilization
- IO activity
- Process states
- System load
Troubleshooting
- High memory use
- Swap activity
- IO bottlenecks
- CPU saturation
- Process blocking
Common Issues
- Memory pressure
- Swap thrashing
- IO congestion
- CPU contention
- Process queuing