Monitor System Resources
You are helping the user monitor live system resource usage (CPU, RAM, disk I/O, network).
Task
Quick resource overview:
# System overview top -b -n 1 | head -20 # Better overview with htop (if installed) htop # Modern alternative: btop btopCPU monitoring:
# CPU usage summary mpstat 1 5 # 5 samples, 1 second interval # Per-core usage mpstat -P ALL 1 5 # Top CPU consumers ps aux --sort=-%cpu | head -10 # CPU frequency and temperature watch -n 1 "grep MHz /proc/cpuinfo | head -20 && sensors"Memory monitoring:
# Memory usage free -h # Detailed memory info cat /proc/meminfo # Top memory consumers ps aux --sort=-%mem | head -10 # Memory usage by process smem -tk # If smem is installed # Watch memory usage watch -n 1 free -hDisk I/O monitoring:
# I/O statistics iostat -x 1 5 # Disk usage by device iotop -o # Only show active I/O # Per-process I/O iotop -P # Watch disk I/O watch -n 1 "iostat -x | grep -E 'Device|sd|nvme'"Network monitoring:
# Network interface statistics ifstat 1 5 # Bandwidth per interface bmon # Network speed iftop # Connection summary ss -s # Active connections nethogsCombined system monitoring:
# All-in-one monitoring glances # Custom dashboard watch -n 1 ' echo "=== CPU ===" top -b -n 1 | head -5 | tail -2 echo "" echo "=== Memory ===" free -h | grep -E "Mem|Swap" echo "" echo "=== Disk I/O ===" iostat -x 1 1 | grep -E "Device|sd|nvme" | head -5 echo "" echo "=== Network ===" ifstat 1 1 | tail -1 'GPU monitoring (AMD):
# AMD GPU usage radeontop # GPU sensors watch -n 1 "rocm-smi" # Detailed GPU info watch -n 1 "rocm-smi --showuse --showmemuse --showtemp"Process tree with resource usage:
# Process tree pstree -p # Resource-aware process tree ps auxf # Find resource hogs ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head -20System load monitoring:
# Load average uptime # Load over time watch -n 1 "uptime && cat /proc/loadavg" # Who's causing load tload -d 1Create monitoring script:
cat > /tmp/system-monitor.sh << 'EOF' #!/bin/bash echo "System Resource Monitor - $(date)" echo "========================================" echo "" echo "CPU Usage:" mpstat 1 1 | tail -1 echo "" echo "Memory:" free -h | grep -E "Mem|Swap" echo "" echo "Load Average:" uptime echo "" echo "Top 5 CPU Processes:" ps aux --sort=-%cpu | head -6 | tail -5 echo "" echo "Top 5 Memory Processes:" ps aux --sort=-%mem | head -6 | tail -5 echo "" echo "Disk Usage:" df -h / /home echo "" echo "Disk I/O:" iostat -x 1 1 | grep -E "sd|nvme" EOF chmod +x /tmp/system-monitor.sh /tmp/system-monitor.sh
Present Summary to User
Provide snapshot of:
- CPU: Usage %, load average, top processes
- Memory: Used/Free, swap usage, top consumers
- Disk: Usage %, I/O wait, active reads/writes
- Network: Bandwidth usage, active connections
- GPU: Usage % (if applicable)
Flag any concerning patterns:
- High CPU usage (>80% sustained)
- Low memory (<10% free)
- High swap usage
- Disk I/O bottlenecks
- Network saturation
Install Monitoring Tools if Needed
# Install commonly needed tools
sudo apt install -y \
htop \
btop \
iotop \
iftop \
nethogs \
glances \
sysstat \
bmon \
radeontop
Troubleshooting High Usage
High CPU:
- Identify process:
toporhtop - Check if legitimate (updates, backups, encoding)
- Kill if necessary:
kill -15 PID
High Memory:
- Check for memory leaks:
ps aux --sort=-%mem - Clear caches:
sudo sync && sudo sysctl -w vm.drop_caches=3 - Check for swap thrashing
High Disk I/O:
- Identify process:
iotop -o - Check if expected (backups, indexing, updates)
- Monitor disk health:
/check-disk-errors
High Network:
- Identify connections:
nethogsoriftop - Check for unexpected traffic
- Use
ss -tunapto see connections
Notes
- Most monitoring tools require sudo for full functionality
glancesprovides best all-in-one viewbtopis modern, colorful alternative tohtop- Some tools need to be installed separately
- For persistent monitoring, consider setting up Prometheus/Grafana
- Check
systemd-cgtopfor cgroup resource usage