StarDomain

Monitoring VPS Resources (CPU, RAM, Disk)

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:

bash
# 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):

bash
$ uptime
 14:30:05 up 45 days,  2:15,  1 user,  load average: 0.50, 0.75, 0.60

Interpreting 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

bash
top

Key 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 1 to show per-core CPU usage
  • Press M to sort by memory
  • Press P to sort by CPU
  • Press q to quit

htop (Enhanced Process Viewer)

bash
sudo apt install htop -y
htop

htop 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

bash
sudo apt install sysstat -y

# CPU stats every 2 seconds, 5 times
mpstat 2 5

# Per-core breakdown
mpstat -P ALL 2 5

Memory (RAM) Monitoring

free Command

bash
free -h

Sample output:

              total        used        free      shared  buff/cache   available
Mem:          3.8Gi       1.2Gi       512Mi       45Mi       2.1Gi       2.3Gi
Swap:         2.0Gi          0B       2.0Gi

Key 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

bash
# Top 10 processes by memory usage
ps aux --sort=-%mem | head -n 11

# Detailed memory breakdown
cat /proc/meminfo

Monitoring Swap Usage

bash
# Check swap usage
swapon --show

# Monitor swap activity
vmstat 2 5

The 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

bash
# 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 -20

Disk I/O Monitoring

bash
# Install iostat (part of sysstat)
sudo apt install sysstat -y

# Disk I/O statistics
iostat -x 2 5

Key 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)

bash
sudo apt install smartmontools -y
sudo smartctl -a /dev/sda

Tip: On VPS instances, SMART data may not be available as the underlying hardware is managed by the host.


Network Monitoring

Bandwidth Usage

bash
# Install nload for real-time bandwidth
sudo apt install nload -y
nload

# Alternative: iftop for per-connection bandwidth
sudo apt install iftop -y
sudo iftop

Connection Monitoring

bash
# 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 -10

Setting Up Alerts

Simple Monitoring Script

Create a script that alerts you when resources are running low:

bash
sudo nano /usr/local/bin/resource-alert.sh
bash
#!/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]
fi
bash
sudo chmod +x /usr/local/bin/resource-alert.sh

# Run every 5 minutes via cron
sudo crontab -e
# Add:
*/5 * * * * /usr/local/bin/resource-alert.sh

Lightweight Monitoring Tools

ToolPurposeInstall
htopInteractive process viewersudo apt install htop
nloadReal-time network bandwidthsudo apt install nload
iotopDisk I/O per processsudo apt install iotop
glancesAll-in-one system monitorsudo apt install glances
dstatVersatile resource statssudo 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:

  1. CPU load average exceeding your core count for extended periods
  2. Available memory below 10% of total RAM
  3. Disk usage above 80%
  4. Swap usage consistently above 50%
  5. Disk I/O wait (%wa) consistently above 20%

Contact {{COMPANY_NAME}} support to discuss upgrade options for your VPS plan.


  • 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}}.