Prometheus Grafana Real-time Server Monitoring

As your infrastructure grows beyond a few servers, manual monitoring via SSH becomes impractical. Prometheus + Grafana is the industry-standard open-source solution for monitoring and visualization. Prometheus acts as a time-series database that collects metrics from your servers and applications. Grafana is the beautiful, interactive frontend that transforms raw metrics into insightful dashboards. Together, they enable real-time monitoring, historical analysis, and intelligent alerting—all crucial for running reliable systems.

Why Prometheus + Grafana?

The traditional approach of logging into each server via SSH to run top, df, and free -h doesn't scale. Prometheus and Grafana solve multiple problems at once:

Prerequisites

Step 1 — Install Prometheus

Create prometheus user and directories

sudo useradd --no-create-home --shell /bin/false prometheus
sudo mkdir -p /etc/prometheus /var/lib/prometheus
sudo chown prometheus:prometheus /etc/prometheus /var/lib/prometheus

Download and extract Prometheus

cd /tmp
wget https://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gz
tar -xvf prometheus-2.45.0.linux-amd64.tar.gz

# Copy binaries to system path
sudo cp prometheus-2.45.0.linux-amd64/prometheus /usr/local/bin/
sudo cp prometheus-2.45.0.linux-amd64/promtool /usr/local/bin/
sudo chown prometheus:prometheus /usr/local/bin/prometheus /usr/local/bin/promtool

# Copy console files
sudo cp -r prometheus-2.45.0.linux-amd64/consoles /etc/prometheus
sudo cp -r prometheus-2.45.0.linux-amd64/console_libraries /etc/prometheus
sudo chown -R prometheus:prometheus /etc/prometheus

Create Prometheus configuration file

sudo tee /etc/prometheus/prometheus.yml > /dev/null << 'EOF'
global:
  scrape_interval: 15s
  evaluation_interval: 15s

alerting:
  alertmanagers:
    - static_configs:
        - targets: []

rule_files:
  - '/etc/prometheus/alert.rules.yml'

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

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

  - job_name: 'remote-vps-1'
    static_configs:
      - targets: ['192.168.1.100:9100']

  - job_name: 'remote-vps-2'
    static_configs:
      - targets: ['192.168.1.101:9100']

EOF
sudo chown prometheus:prometheus /etc/prometheus/prometheus.yml

Create systemd service for Prometheus

sudo tee /etc/systemd/system/prometheus.service > /dev/null << 'EOF'
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
  --config.file=/etc/prometheus/prometheus.yml \
  --storage.tsdb.path=/var/lib/prometheus/ \
  --web.console.templates=/etc/prometheus/consoles \
  --web.console.libraries=/etc/prometheus/console_libraries

Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus

Verify Prometheus is running

curl -s http://localhost:9090
# Should return HTML response
# Access dashboard at http://YOUR_VPS_IP:9090

Note: Prometheus can monitor itself, but to monitor other servers you must install Node Exporter on each target server.

Step 2 — Install Node Exporter (on each monitored server)

cd /tmp
wget https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gz
tar -xvf node_exporter-1.6.1.linux-amd64.tar.gz

sudo cp node_exporter-1.6.1.linux-amd64/node_exporter /usr/local/bin/
sudo chown root:root /usr/local/bin/node_exporter

# Create systemd service
sudo tee /etc/systemd/system/node_exporter.service > /dev/null << 'EOF'
[Unit]
Description=Node Exporter
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/node_exporter

Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl enable node_exporter

Verify Node Exporter

curl -s http://localhost:9100/metrics | head -20
# Should display metrics like node_cpu_seconds_total, node_memory_MemTotal_bytes, etc.

Step 3 — Install Grafana

Add Grafana repository and install

sudo apt-get install -y software-properties-common
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
sudo apt-get update
sudo apt-get install -y grafana

Start Grafana service

sudo systemctl start grafana-server
sudo systemctl enable grafana-server

sudo systemctl status grafana-server

Access Grafana dashboard

# Open http://YOUR_VPS_IP:3000 in browser
# Default credentials:
#   Username: admin
#   Password: admin
# Change password on first login

Step 4 — Add Prometheus as Data Source

  1. In Grafana: Configuration (gear icon) → Data Sources
  2. Click "Add data source"
  3. Select "Prometheus"
  4. Set URL to: http://localhost:9090
  5. Click "Save & test" → should show "Data source is working"

Step 5 — Create Your First Dashboard

Option A: Create from scratch

Go to Dashboards → Create → Dashboard → Add panels with PromQL queries

Option B: Import pre-built dashboard (recommended for beginners)

# In Grafana: + (plus) → Import
# Enter Dashboard ID: 1860 (Node Exporter Full)
# Select Prometheus data source
# Click Import
# Now you have a complete dashboard showing CPU, Memory, Disk, Network metrics

Step 6 — Set Up Alert Rules

Create alert rules file

sudo tee /etc/prometheus/alert.rules.yml > /dev/null << 'EOF'
groups:
  - name: System Alerts
    interval: 30s
    rules:
      - alert: HighCPUUsage
        expr: (100 - (avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)) > 80
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "High CPU usage on {{ $labels.instance }}"
          description: "CPU usage is {{ $value }}% on {{ $labels.instance }}"

      - alert: HighMemoryUsage
        expr: (1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)) * 100 > 85
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "High memory usage on {{ $labels.instance }}"

      - alert: HighDiskUsage
        expr: (1 - (node_filesystem_avail_bytes{fstype!~"tmpfs"} / node_filesystem_size_bytes)) * 100 > 90
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: "Disk usage is {{ $value | humanize }}% on {{ $labels.instance }}"

EOF
sudo chown prometheus:prometheus /etc/prometheus/alert.rules.yml

Reload Prometheus

sudo systemctl reload prometheus

# Verify alerts: http://YOUR_VPS_IP:9090/alerts

Troubleshooting Common Issues

Prometheus cannot connect to Node Exporter

# Check Prometheus logs
sudo journalctl -u prometheus -n 50

# Allow firewall if remote server
sudo ufw allow 9100/tcp

# Validate config syntax
sudo -u prometheus /usr/local/bin/promtool check config /etc/prometheus/prometheus.yml

Grafana shows "No data"

# Verify time range is large enough (default: last 6 hours)
# Check PromQL syntax in panel query
# Confirm Prometheus has data: curl http://localhost:9090/api/v1/targets

Alerts not triggering

# Validate alert rules syntax
sudo -u prometheus /usr/local/bin/promtool check rules /etc/prometheus/alert.rules.yml

# Test expression in Prometheus UI
# Visit http://YOUR_VPS_IP:9090/graph
# Try query: avg(rate(node_cpu_seconds_total{mode="user"}[5m]))

Next Steps: Configure Alertmanager

The alert rules above trigger locally in Prometheus but don't send notifications. To send alerts to Slack, Email, or PagerDuty, you need Alertmanager—a companion component that handles alert routing and notifications. This is a more advanced topic, but Prometheus + Grafana + Node Exporter as shown above provides solid foundation monitoring for most use cases.

Need a VPS for Prometheus + Grafana?

AsiaGB offers powerful Linux VPS with full root access and SSD storage, perfect for running monitoring infrastructure. Starting at just 500 THB/month with 99% uptime guarantee.

View VPS Plans

View all affordable VPS Thailand plans →