Monitoring Server Resources: CPU, Memory, and Disk
Essential tools and techniques for monitoring your Linux server resources to prevent downtime and optimize performance.
Monitoring Server Resources: CPU, Memory, and Disk
Effective server monitoring helps you detect issues before they cause downtime. Learn how to monitor your Linux server resources.
Why Monitor Server Resources?
Resource monitoring helps you:
- Detect performance bottlenecks
- Prevent outages from resource exhaustion
- Optimize application performance
- Plan for scaling needs
- Troubleshoot issues quickly
Quick Resource Overview Commands
Check CPU Usage
top
# or
htop # More user-friendly (install with: sudo apt install htop)
Check Memory Usage
free -h
Check Disk Usage
df -h
Check Disk I/O
iostat
# Install with: sudo apt install sysstat
Detailed Monitoring with top/htop
Understanding top Output
top - 14:30:42 up 10 days, 3:21, 1 user, load average: 0.52, 0.58, 0.59
Tasks: 123 total, 1 running, 122 sleeping
%Cpu(s): 2.3 us, 0.7 sy, 0.0 ni, 96.7 id, 0.3 wa
MiB Mem : 3951.4 total, 245.8 free, 2341.5 used, 1364.1 buff/cache
Key metrics:
- load average: System load (should be below CPU core count)
- us (user): CPU time on user processes
- sy (system): CPU time on system processes
- id (idle): CPU idle time
- wa (wait): CPU waiting for I/O
Using htop Effectively
Install htop:
sudo apt install htop
Key features:
- Color-coded CPU and memory bars
- Tree view of processes (F5)
- Search processes (F3)
- Kill processes (F9)
- Sort by various metrics (F6)
Memory Monitoring
Check Memory Details
free -h
Output:
total used free shared buff/cache available
Mem: 3.9Gi 2.3Gi 240Mi 10Mi 1.3Gi 1.4Gi
Swap: 2.0Gi 512Mi 1.5Gi
- total: Total physical RAM
- used: RAM used by processes
- free: Unused RAM
- buff/cache: RAM used for caching (can be freed if needed)
- available: RAM available for new applications
Find Memory-Hungry Processes
ps aux --sort=-%mem | head
Disk Monitoring
Check Disk Space
df -h
Find Large Files
du -h --max-depth=1 | sort -hr | head -20
Find Large Files Recursively
find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null
Monitor Disk I/O in Real-Time
iostat -x 2
Setting Up Alerts
Email Alert for High CPU
Create /usr/local/bin/cpu-alert.sh
:
#!/bin/bash
CPU_THRESHOLD=80
CPU_USAGE=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1}')
if (( $(echo "$CPU_USAGE > $CPU_THRESHOLD" | bc -l) )); then
echo "High CPU usage: $CPU_USAGE%" | mail -s "CPU Alert" admin@example.com
fi
Add to crontab:
*/5 * * * * /usr/local/bin/cpu-alert.sh
Using Monitoring Tools
Install netdata (Real-time Monitoring)
bash <(curl -Ss https://my-netdata.io/kickstart.sh)
Access at: http://your-server-ip:19999
Best Practices
1. Monitor Trends: Track metrics over time, not just snapshots
2. Set Alerts: Get notified before problems become critical
3. Regular Reviews: Check metrics weekly
4. Document Baselines: Know your normal resource usage
5. Capacity Planning: Monitor growth trends for scaling decisions
Conclusion
Regular resource monitoring prevents performance issues and downtime. Gumpbox provides beautiful, real-time visualizations of your server resources in an easy-to-use dashboard.
Next Steps
Ready to simplify your Linux server management?
Gumpbox makes server administration effortless with an intuitive interface designed for developers.
Get Started