Monitoring VPS Resources (CPU, RAM, Disk)
Proactive resource monitoring helps you identify performance bottlenecks, plan capacity upgrades, and keep your {{COMPANY_NAME}} VPS running smoothly. This guide covers built-in tools and lightweight monitoring solutions.
Quick Resource Overview
For a fast snapshot of your server's health, use these commands:
# Uptime and load average
uptime
# Memory usage
free -h
# Disk space
df -h
# CPU info
nproc && lscpu | grep "Model name"CPU Monitoring
Understanding Load Average
The uptime command shows three load averages (1, 5, and 15 minutes):
$ uptime
14:30:05 up 45 days, 2:15, 1 user, load average: 0.50, 0.75, 0.60Interpreting load averages:
- A load of 1.0 on a single-core VPS means the CPU is fully utilized
- A load of 2.0 on a 2-core VPS means full utilization
- Load consistently above your CPU count indicates a bottleneck
Real-Time CPU Monitoring with top
topKey fields in top:
- %us -- user space CPU usage
- %sy -- kernel/system CPU usage
- %wa -- I/O wait (high values indicate disk bottleneck)
- %id -- idle CPU (higher is better)
Useful top shortcuts:
- Press
1to show per-core CPU usage - Press
Mto sort by memory - Press
Pto sort by CPU - Press
qto quit
htop (Enhanced Process Viewer)
sudo apt install htop -y
htophtop provides a color-coded, scrollable interface with CPU and memory bars. It is significantly easier to use than top.
Check CPU Usage Over Time with mpstat
sudo apt install sysstat -y
# CPU stats every 2 seconds, 5 times
mpstat 2 5
# Per-core breakdown
mpstat -P ALL 2 5Memory (RAM) Monitoring
free Command
free -hSample output:
total used free shared buff/cache available
Mem: 3.8Gi 1.2Gi 512Mi 45Mi 2.1Gi 2.3Gi
Swap: 2.0Gi 0B 2.0GiKey points:
- available is the most important column -- it shows memory truly available for new processes
- buff/cache is memory used for file caching; it can be freed when needed
- High swap usage indicates your VPS needs more RAM
Identifying Memory-Hungry Processes
# Top 10 processes by memory usage
ps aux --sort=-%mem | head -n 11
# Detailed memory breakdown
cat /proc/meminfoMonitoring Swap Usage
# Check swap usage
swapon --show
# Monitor swap activity
vmstat 2 5The si (swap in) and so (swap out) columns in vmstat show active swapping. Consistent swap activity indicates a RAM shortage.
Disk Monitoring
Disk Space Usage
# Overall disk space
df -h
# Directory sizes
du -sh /var/*
du -sh /home/*
# Find the largest directories
du -h / --max-depth=1 | sort -hr | head -20Disk I/O Monitoring
# Install iostat (part of sysstat)
sudo apt install sysstat -y
# Disk I/O statistics
iostat -x 2 5Key iostat columns:
- %util -- percentage of time disk is busy (>80% is concerning)
- await -- average I/O wait time in ms
- r/s, w/s -- reads and writes per second
Disk Health (SMART)
sudo apt install smartmontools -y
sudo smartctl -a /dev/sdaTip: On VPS instances, SMART data may not be available as the underlying hardware is managed by the host.
Network Monitoring
Bandwidth Usage
# Install nload for real-time bandwidth
sudo apt install nload -y
nload
# Alternative: iftop for per-connection bandwidth
sudo apt install iftop -y
sudo iftopConnection Monitoring
# Active connections
ss -tan | head -20
# Connection count by state
ss -tan | tail -n +2 | awk '{print $1}' | sort | uniq -c | sort -rn
# Connections per IP
ss -tan | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | head -10Setting Up Alerts
Simple Monitoring Script
Create a script that alerts you when resources are running low:
sudo nano /usr/local/bin/resource-alert.sh#!/bin/bash
# Disk usage alert (>85%)
DISK_USAGE=$(df / | tail -1 | awk '{print $5}' | sed 's/%//')
if [ "$DISK_USAGE" -gt 85 ]; then
echo "WARNING: Disk usage is ${DISK_USAGE}%" | mail -s "VPS Disk Alert" [email protected]
fi
# Memory alert (available < 200MB)
AVAIL_MEM=$(free -m | awk '/^Mem:/{print $7}')
if [ "$AVAIL_MEM" -lt 200 ]; then
echo "WARNING: Available memory is ${AVAIL_MEM}MB" | mail -s "VPS Memory Alert" [email protected]
fi
# Load alert (>CPU count)
LOAD=$(cat /proc/loadavg | awk '{print $1}')
CPUS=$(nproc)
if (( $(echo "$LOAD > $CPUS" | bc -l) )); then
echo "WARNING: Load average is $LOAD (CPUs: $CPUS)" | mail -s "VPS Load Alert" [email protected]
fisudo chmod +x /usr/local/bin/resource-alert.sh
# Run every 5 minutes via cron
sudo crontab -e
# Add:
*/5 * * * * /usr/local/bin/resource-alert.shLightweight Monitoring Tools
| Tool | Purpose | Install |
|---|---|---|
| htop | Interactive process viewer | sudo apt install htop |
| nload | Real-time network bandwidth | sudo apt install nload |
| iotop | Disk I/O per process | sudo apt install iotop |
| glances | All-in-one system monitor | sudo apt install glances |
| dstat | Versatile resource stats | sudo apt install dstat |
Tip: For a comprehensive overview in one command, install
glances:```bash
sudo apt install glances -y
glances
```
When to Upgrade Your VPS
Consider upgrading when you consistently observe:
- CPU load average exceeding your core count for extended periods
- Available memory below 10% of total RAM
- Disk usage above 80%
- Swap usage consistently above 50%
- Disk I/O wait (%wa) consistently above 20%
Contact {{COMPANY_NAME}} support to discuss upgrade options for your VPS plan.
Related Articles
- Basic VPS Server Management Commands
- VPS Not Responding: Troubleshooting Guide
- Common VPS Issues and Solutions
Need help with VPS performance? Contact our support team at {{SUPPORT_EMAIL}} or open a ticket at {{SUPPORT_URL}}.