Iostat - Install
# Ubuntu/Debian
sudo apt install sysstat
# Enable data collection
sudo systemctl enable sysstat
sudo systemctl start sysstat
Basic iostat
iostat
Extended statistics
iostat -x
Show in MB/s
iostat -m
Specific device
iostat -x sda
Continuous monitoring (every 2s)
iostat -x 2
Monitor 5 times, every 2s
iostat -x 2 5
CPU statistics only
iostat -c
Disk statistics only
iostat -d
Human readable
iostat -h
Include partition stats
iostat -p sda
NFS statistics
iostat -n
Important iostat metrics
%util # Device utilization (100% = saturated)
await # Average wait time (ms)
svctm # Service time (deprecated)
r/s # Reads per second
w/s # Writes per second
rkB/s # KB read per second
wkB/s # KB written per second
SAR - Basic usage
sar
CPU usage (current)
sar -u 1 5
CPU usage (all cores)
sar -P ALL 1 5
Memory usage
sar -r 1 5
Swap usage
sar -S 1 5
Disk I/O
sar -d 1 5
Network statistics
sar -n DEV 1 5
Network errors
sar -n EDEV 1 5
Load average
sar -q 1 5
Context switches
sar -w 1 5
Paging statistics
sar -B 1 5
View historical data
sar -f /var/log/sysstat/sa$(date +%d)
Historical CPU
sar -u -f /var/log/sysstat/sa15
Historical for specific time
sar -u -s 10:00:00 -e 11:00:00
Historical for date
sar -u -f /var/log/sysstat/sa15 -s 14:00:00 -e 15:00:00
All statistics
sar -A
Export to file
sar -u 1 10 -o /tmp/sar_data
Read from file
sar -u -f /tmp/sar_data
Network device stats
sar -n DEV,EDEV 1 5
TCP statistics
sar -n TCP 1 5
Socket statistics
sar -n SOCK 1 5
Important SAR metrics
%user # User CPU time
%system # System CPU time
%iowait # Waiting for I/O
%idle # Idle CPU time
kbmemfree # Free memory
kbswpfree # Free swap
tps # Transfers per second
rxkB/s # KB received per second
txkB/s # KB transmitted per second
Analyze high I/O wait
# Check overall CPU
sar -u 1 5
# Check disk I/O
sar -d 1 5
# Check individual disks
iostat -x 1 5
# Find processes
iotop
SAR report for yesterday
sar -u -f /var/log/sysstat/sa$(date -d yesterday +%d)
Generate daily report
# Ubuntu/Debian
/usr/lib/sysstat/sa2
SAR configuration
Edit /etc/default/sysstat:
ENABLED="true"
SAR data retention
Edit /etc/sysstat/sysstat:
HISTORY=30
Cron schedule
cat /etc/cron.d/sysstat
Real-time monitoring script
#!/bin/bash
while true; do
clear
echo "=== CPU ==="
sar -u 1 1 | tail -1
echo ""
echo "=== Memory ==="
sar -r 1 1 | tail -1
echo ""
echo "=== Disk I/O ==="
iostat -x 1 1 | grep -E "sda|nvme"
sleep 2
done