LochStudios  /  Help Centre  /  VPS & Linux  /  Monitor Server Resources (htop, df, free, top)

Monitor Server Resources (htop, df, free, top)

Use built-in Linux tools to monitor CPU, memory, disk, and process usage on your VPS.

Updated

Monitoring server resources helps you spot bottlenecks, manage capacity, and catch runaway processes before they crash your VPS. This guide covers the most practical tools: htop, top, free, and df. These work on Ubuntu, Debian, and RHEL/CentOS.

Prerequisites

  • SSH access to your VPS
  • sudo privileges (optional, for some commands)

Install monitoring tools

Most systems have top, free, and df pre-installed. Install htop for a better experience:

Ubuntu/Debian:
CODE0

RHEL/CentOS:
CODE1

1. Quick memory and swap check with free

See RAM and swap usage instantly:

free -h

Output shows total, used, available, and free memory in human-readable format (KB/MB/GB). Repeat updates:

free -h -s 2

(Updates every 2 seconds; press Ctrl+C to stop.)

Key columns:
- total: Total installed memory
- used: Memory currently in use
- available: Memory available to start new processes
- Swap: Virtual memory on disk

2. Disk space with df

Check filesystem usage across all mounted disks:

df -h

Shows each filesystem's total size, used space, available space, and mount point.

Check a specific directory:
CODE5

Watch disk usage grow over time:
CODE6

(Updates every 5 seconds.)

3. Real-time process monitoring with top

Launch the interactive process monitor:

top

Shows CPU, memory, and process details. Key controls:

  • q — Exit
  • P — Sort by CPU usage (descending)
  • M — Sort by memory usage (descending)
  • u — Filter by username (press u, type username)
  • k — Kill a process (press k, enter PID)
  • 1 — Toggle per-CPU cores view

Example: Sort by memory to find memory hogs:
CODE8

One-shot view (non-interactive):
CODE9

4. Better process monitoring with htop

htop is more user-friendly than top:

htop

Key features:

  • Color-coded output — Easier to read
  • Tree view — See process hierarchy (press F5)
  • Search — Press F3 to search for a process
  • Kill processes — Select one with arrow keys, press F9
  • Sort columns — Click column headers (or arrow to column, press Shift+Right)
  • Per-CPU display — Shows all cores by default

Example: View processes from a specific user:
CODE11

5. CPU load with uptime

Quick CPU load summary:

uptime

Output: load average: 0.5, 0.8, 1.2

These are average CPU loads over 1, 5, and 15 minutes. If your server has 4 cores:
- Load ~1.0 per minute = moderate usage
- Load >4.0 = sustained high CPU usage

6. Detailed process list with ps

List all running processes:

ps aux

Find a specific process:
CODE14

Show process tree (parent-child relationships):
CODE15

7. Monitor disk I/O with iostat

Install sysstat to get iostat:

Ubuntu/Debian:
CODE16

RHEL/CentOS:
CODE17

Check disk read/write rates:

iostat -x 1

(Updates every 1 second.)

Continuous monitoring script

Create a simple script to log resource usage:

cat > monitor.sh << 'EOF'
#!/bin/bash
while true; do
  echo "=== $(date) ==="
  echo "Memory:"
  free -h | grep Mem
  echo "Disk (/home):"
  df -h /home | grep /home
  echo "Load:"
  uptime | grep 'load average'
  echo ""
  sleep 60
done
EOF

chmod +x monitor.sh
./monitor.sh

Press Ctrl+C to stop. Logs update every 60 seconds.

Tips

  • Memory alerts: If available drops below 10% of total RAM, add swap or upgrade RAM.
  • Disk alerts: If any filesystem is >90% full, you risk stability issues; clean up or expand.
  • CPU spikes: Use htop to identify the process, then kill -9 <PID> if necessary.
  • Zombie processes: Shown as <defunct> in ps output; restart the parent process or reboot.
  • I/O waits: High iowait % in top means disk is slow; consider SSD upgrades or reduce concurrent I/O.

Regularly monitoring these metrics keeps your VPS healthy and prevents surprise outages.


Was this article helpful?

← Back to VPS & Linux