Why Monitor Resources?
Monitoring CPU, memory, disk, and network usage helps you:
- Identify bottlenecks before they cause downtime
- Right-size your server plan
- Debug performance issues
- Plan capacity for growth
CPU Monitoring
Quick Check
# Current load average (1, 5, 15 minutes)
uptime
# 10:30:00 up 45 days, load average: 0.85, 1.20, 0.95
# Real-time process viewer
htop
Understanding Load Average
| Load Average | Meaning (single-core) |
|---|---|
| < 1.0 | Server is underutilized |
| 1.0 | Fully utilized, no queue |
| > 1.0 | Processes are waiting |
| > 2.0 | Significant contention |
Tip Multiply these thresholds by your CPU core count. A 4-core server is comfortable at load 4.0.
Per-Process CPU Usage
# Top CPU consumers
ps aux --sort=-%cpu | head -10
# Watch a specific process
pidstat -p $(pgrep nginx) 1
Memory Monitoring
free -h
# total used free shared buff/cache available
# Mem: 3.8Gi 1.2Gi 312Mi 45Mi 2.3Gi 2.3Gi
# Swap: 2.0Gi 0B 2.0Gi
Key metrics:
- available (not free) tells you how much memory applications can use
- Linux uses free memory for disk cache — this is normal and healthy
- If swap used is consistently high, you need more RAM
Disk Monitoring
# Disk space usage
df -h /
# /dev/vda1 50G 12G 36G 25% /
# Find largest directories
du -sh /var/* | sort -rh | head -10
# Disk I/O activity
iostat -x 1 3
Warning If disk usage exceeds 90%, services may fail to write logs, temp files, or database data. Set up alerts before this happens.
Network Monitoring
# Install vnstat for bandwidth tracking
sudo apt install -y vnstat
# Monthly summary
vnstat -m
# Live traffic
vnstat -l
# Connection counts by state
ss -s
Setting Up Simple Alerts
Create a quick monitoring script:
#!/bin/bash
# /opt/monitor/check.sh
DISK_THRESHOLD=85
MEM_THRESHOLD=90
# Check disk
DISK_USAGE=$(df / | awk 'NR==2 {print int($5)}')
if [ "$DISK_USAGE" -gt "$DISK_THRESHOLD" ]; then
echo "ALERT: Disk usage at ${DISK_USAGE}%" | mail -s "Disk Alert" admin@example.com
fi
# Check memory
MEM_USAGE=$(free | awk '/^Mem:/ {printf("%.0f", $3/$2 * 100)}')
if [ "$MEM_USAGE" -gt "$MEM_THRESHOLD" ]; then
echo "ALERT: Memory usage at ${MEM_USAGE}%" | mail -s "Memory Alert" admin@example.com
fi
Schedule it with cron:
*/5 * * * * /opt/monitor/check.sh