Logo
Bearhost Logo

How to Monitor VPS Resource Usage

By Elliot, BearHost·

Monitoring your VPS resources helps you spot problems before they affect your services. This guide covers command-line tools, the VirtFusion panel, and automated alerts.

Quick Reference

| What to Check | Command | What It Shows | |---|---|---| | CPU and RAM live | htop | Interactive process manager | | Memory summary | free -m | RAM usage in megabytes | | Disk space | df -h | Filesystem usage | | Disk I/O | iotop | Per-process I/O usage | | Bandwidth | vnstat | Network traffic history | | System overview | top | Basic process list |

Using htop

Install and launch htop:

sudo apt install htop -y
htop

Key Shortcuts

  • F5: Tree view (see parent/child processes)
  • F6: Sort by column (CPU%, MEM%, etc.)
  • F9: Kill a process
  • F10 or q: Quit
  • M: Sort by memory usage
  • P: Sort by CPU usage

The bars at the top show CPU core usage and memory. Green = normal processes, red = kernel, blue = low priority.

Understanding Memory with free -m

free -m

Example output:

              total   used   free   shared   buff/cache   available
Mem:           3932   1205    412       28         2314        2432
Swap:          2048    128   1920

Important: The available column is what matters, not free. Linux uses spare RAM for disk caching (buff/cache), which is released when applications need it. If available is low, you are running out of memory.

Checking Disk Space

df -h

If disk is getting full, find the largest directories:

sudo du -sh /* 2>/dev/null | sort -rh | head -10
sudo du -sh /var/log/* | sort -rh | head -10

Common space eaters: old logs (/var/log), old backups, Docker images, and package caches. Clean up with:

sudo apt autoremove -y
sudo apt clean
sudo journalctl --vacuum-size=100M

Monitoring Disk I/O

sudo apt install iotop -y
sudo iotop -o

The -o flag shows only processes actively performing I/O. High I/O wait can slow your entire server even when CPU and RAM look fine.

Bandwidth Monitoring with vnstat

sudo apt install vnstat -y
sudo systemctl enable vnstat
sudo systemctl start vnstat

After vnstat collects data (give it a few minutes initially):

vnstat              # Summary
vnstat -h           # Hourly stats
vnstat -d           # Daily stats
vnstat -m           # Monthly stats
vnstat -l           # Live traffic monitor

VirtFusion Panel Resource Graphs

Your BearHost VPS includes VirtFusion, which provides graphical resource monitoring:

  1. Log in to VirtFusion from your BearHost dashboard
  2. Select your VPS
  3. Navigate to the Graphs tab
  4. View CPU usage, memory usage, disk I/O, and network traffic over time

These graphs are useful for spotting trends and correlating spikes with events.

Automated Email Alerts

Set up alerts so you are notified when resources run high.

Install a Lightweight Mail Client

sudo apt install msmtp msmtp-mta -y

Configure /etc/msmtprc with your SMTP settings to enable sending email from the server.

Create a Monitoring Script

sudo nano /opt/monitor.sh
#!/bin/bash
ALERT_EMAIL="you@example.com"
CPU_THRESHOLD=90
MEM_THRESHOLD=90
DISK_THRESHOLD=85

CPU=$(top -bn1 | grep "Cpu(s)" | awk '{print 100 - $8}' | cut -d. -f1)
MEM=$(free | awk '/Mem/{printf("%d"), $3/$2 * 100}')
DISK=$(df / | tail -1 | awk '{print $5}' | tr -d '%')

HOSTNAME=$(hostname)
ALERT=""

[ "$CPU" -gt "$CPU_THRESHOLD" ] && ALERT="$ALERT
CPU usage: $CPU%"
[ "$MEM" -gt "$MEM_THRESHOLD" ] && ALERT="$ALERT
Memory usage: $MEM%"
[ "$DISK" -gt "$DISK_THRESHOLD" ] && ALERT="$ALERT
Disk usage: $DISK%"

if [ -n "$ALERT" ]; then
  echo -e "Resource alert on $HOSTNAME:
$ALERT" | mail -s "VPS Alert: $HOSTNAME" $ALERT_EMAIL
fi
chmod +x /opt/monitor.sh
sudo crontab -e

Add: */5 * * * * /opt/monitor.sh to check every 5 minutes.

When to Upgrade

| Symptom | Likely Cause | Action | |---|---|---| | Consistent CPU > 80% | CPU bottleneck | Upgrade to more cores | | Available RAM < 10% | Memory bottleneck | Upgrade RAM or add swap | | Disk > 85% full | Storage full | Clean up or add storage | | High I/O wait | Disk bottleneck | Upgrade to faster SSD | | Bandwidth maxed | Network bottleneck | Upgrade plan or add CDN |

If you are regularly hitting resource limits, consider upgrading your BearHost VPS plan for more CPU, RAM, and storage.

Tags:#monitoring#htop#vnstat#disk-space#cpu#ram#alerts#vps#virtfusion