Skip to main content

Server Monitoring

This guide explains how to monitor your Linux VPS performance with different tools.

Command Line Tools​

htop - Interactive Monitor​

htop is an improved version of top with a colorful and interactive interface.

# Installation
sudo apt update
sudo apt install htop

# Launch
htop

htop Shortcuts:

KeyAction
F2Configuration
F3Search for a process
F5Tree view
F6Sort by column
F9Kill a process
F10Quit
uFilter by user

Other Useful Commands​

# Memory usage
free -h

# Disk space
df -h

# Usage by folder
du -sh /var/*

# System load
uptime

# Network connections
ss -tuln

# Processes consuming the most RAM
ps aux --sort=-%mem | head

# Processes consuming the most CPU
ps aux --sort=-%cpu | head

Netdata - Real-Time Dashboard​

Netdata offers a web dashboard with real-time metrics.

Installation​

# Automatic installation
bash <(curl -Ss https://get.netdata.cloud/kickstart.sh)

Access​

Open http://YOUR_IP:19999 in your browser.

Secure Access​

By default, Netdata is publicly accessible. To secure it:

sudo nano /etc/netdata/netdata.conf
[web]
bind to = 127.0.0.1

Then use an Nginx reverse proxy with authentication:

server {
listen 80;
server_name monitoring.example.com;

auth_basic "Monitoring";
auth_basic_user_file /etc/nginx/.htpasswd;

location / {
proxy_pass http://127.0.0.1:19999;
proxy_set_header Host $host;
}
}

Create the password file:

sudo apt install apache2-utils
sudo htpasswd -c /etc/nginx/.htpasswd admin

Grafana + Prometheus - Advanced Monitoring​

For more complete monitoring with history and alerts.

Installation with Docker Compose​

version: '3.8'

services:
prometheus:
image: prom/prometheus:latest
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
ports:
- "9090:9090"
restart: unless-stopped

node-exporter:
image: prom/node-exporter:latest
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
command:
- '--path.procfs=/host/proc'
- '--path.sysfs=/host/sys'
- '--path.rootfs=/rootfs'
ports:
- "9100:9100"
restart: unless-stopped

grafana:
image: grafana/grafana:latest
volumes:
- grafana_data:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_PASSWORD=your_password
ports:
- "3000:3000"
restart: unless-stopped

volumes:
prometheus_data:
grafana_data:

Prometheus Configuration​

Create prometheus.yml:

global:
scrape_interval: 15s

scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']

- job_name: 'node'
static_configs:
- targets: ['node-exporter:9100']

Launch​

docker compose up -d

Grafana Configuration​

  1. Access http://YOUR_IP:3000
  2. Log in (admin / your_password)
  3. Add Prometheus as a data source:
    • URL: http://prometheus:9090
  4. Import a dashboard:
    • Dashboard ID: 1860 (Node Exporter Full)

Email Alerts​

With Grafana​

  1. Configuration > Alerting > Contact points
  2. Add an email contact point
  3. Create alert rules on your dashboards

Simple Alert Script​

#!/bin/bash
# /root/scripts/alert.sh

# Thresholds
CPU_THRESHOLD=90
MEM_THRESHOLD=90
DISK_THRESHOLD=80

# CPU check
CPU=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}' | cut -d'.' -f1)
if [ $CPU -gt $CPU_THRESHOLD ]; then
echo "CPU Alert: ${CPU}%" | mail -s "VPS Alert" your@email.com
fi

# Memory check
MEM=$(free | grep Mem | awk '{print int($3/$2 * 100)}')
if [ $MEM -gt $MEM_THRESHOLD ]; then
echo "Memory Alert: ${MEM}%" | mail -s "VPS Alert" your@email.com
fi

# Disk check
DISK=$(df / | tail -1 | awk '{print $5}' | sed 's/%//')
if [ $DISK -gt $DISK_THRESHOLD ]; then
echo "Disk Alert: ${DISK}%" | mail -s "VPS Alert" your@email.com
fi

Add to cron:

*/5 * * * * /root/scripts/alert.sh

Tool Comparison​

ToolComplexityHistoryInterfaceIdeal for
htopSimpleNoTerminalQuick debugging
NetdataEasyLimitedWebBasic monitoring
GrafanaAdvancedYesWebProduction
Tip

Start with htop and Netdata. Move to Grafana/Prometheus when you have multiple servers to monitor.