Developer Stacks

How to Set Up Prometheus and Grafana Server Monitoring on Ubuntu Linux VPS

How to Set Up Prometheus and Grafana Server Monitoring on Ubuntu Linux VPS - CpanelFree Guide
Written by Blog

Why Real-Time Server Observability is Essential for Webmasters

Operating production web servers without continuous monitoring is like flying blind. Hardware failures, disk space exhaustion, memory leaks in PHP-FPM, or rogue MySQL queries can cause critical server outages hours before you receive an email complaint from frustrated customers. Relying on periodic manual SSH checks is insufficient for maintaining 99.99% service level agreements (SLAs).

The industry-standard open-source observability stack combines **Prometheus** (a high-performance time-series metric collector and storage engine), **Node Exporter** (a lightweight kernel telemetry agent), and **Grafana** (a rich visual dashboard suite). Together, this stack gives you real-time visual insight into CPU loads, per-disk NVMe I/O operations, network throughput, memory fragmentation, and automated alerting via Discord, Telegram, or email.

In this technical observability tutorial, we will configure Prometheus, Node Exporter, and Grafana on Ubuntu 24.04/22.04 LTS, create pre-built system dashboards, and protect the monitoring portal behind an Nginx reverse proxy with SSL.

Step 1: Installing Node Exporter Telemetry Agent

Node Exporter collects detailed hardware and OS metrics directly from the Linux kernel:

# Create dedicated system user
sudo useradd --no-create-home --shell /bin/false node_exporter

# Download latest Node Exporter binary
cd /tmp
curl -LO https://github.com/prometheus/node_exporter/releases/download/v1.8.1/node_exporter-1.8.1.linux-amd64.tar.gz
tar -xvf node_exporter-1.8.1.linux-amd64.tar.gz
sudo mv node_exporter-1.8.1.linux-amd64/node_exporter /usr/local/bin/
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter

Create the systemd service file at /etc/systemd/system/node_exporter.service:

[Unit]
Description=Node Exporter Hardware Telemetry Agent
After=network.target

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

[Install]
WantedBy=multi-user.target

Start and enable Node Exporter:

sudo systemctl daemon-reload
sudo systemctl enable --now node_exporter
sudo systemctl status node_exporter --no-pager

Step 2: Installing and Configuring Prometheus TSDB

Prometheus periodically polls (scrapes) metrics from Node Exporter and stores them in a highly compressed time-series database:

# Create dedicated 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 Prometheus binary
cd /tmp
curl -LO https://github.com/prometheus/prometheus/releases/download/v2.52.0/prometheus-2.52.0.linux-amd64.tar.gz
tar -xvf prometheus-2.52.0.linux-amd64.tar.gz
sudo mv prometheus-2.52.0.linux-amd64/prometheus /usr/local/bin/
sudo mv prometheus-2.52.0.linux-amd64/promtool /usr/local/bin/
sudo chown prometheus:prometheus /usr/local/bin/prometheus /usr/local/bin/promtool

Create configuration file /etc/prometheus/prometheus.yml:

global:
  scrape_interval: 15s
  evaluation_interval: 15s

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

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

Create systemd service /etc/systemd/system/prometheus.service:

[Unit]
Description=Prometheus Time-Series Monitoring Engine
After=network.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.listen-address=127.0.0.1:9090

[Install]
WantedBy=multi-user.target

Start Prometheus:

sudo systemctl daemon-reload
sudo systemctl enable --now prometheus

Step 3: Installing Grafana Dashboard Portal

Install the official Grafana enterprise repository on Ubuntu:

# Add Grafana GPG key and APT repository
sudo apt install -y apt-transport-https software-properties-common wget
sudo mkdir -p /etc/apt/keyrings/
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list

sudo apt update && sudo apt install -y grafana
sudo systemctl enable --now grafana-server

Step 4: Nginx Reverse Proxy with SSL for Grafana

Create /etc/nginx/sites-available/monitor.example.com:

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

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Enable the virtual host and acquire an SSL certificate:

sudo ln -s /etc/nginx/sites-available/monitor.example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d monitor.example.com

Step 5: Importing Node Exporter Full Dashboard (ID: 1860)

Log in to your Grafana portal (default user: admin, password: admin), add Prometheus (http://127.0.0.1:9090) as a Data Source, and click Dashboards > Import. Enter Dashboard ID 1860 (Node Exporter Full) to instantly unlock enterprise-grade real-time monitoring charts for CPU cores, RAM allocations, disk I/O, network bandwidth, and system load.

Prometheus & Grafana Observability Matrix

Observability Layer Component Port / Endpoint Resource Overhead
Metrics Collector Node Exporter 127.0.0.1:9100/metrics ~12 MB RAM (< 0.1% CPU)
Time-Series DB Prometheus Server 127.0.0.1:9090 ~45 MB RAM
Visualization Portal Grafana Server 127.0.0.1:3000 ~55 MB RAM

Configuring Prometheus Alertmanager for Discord & Email Alerts

Observability is incomplete without proactive alerting. Alertmanager intercepts metrics from Prometheus and routes real-time notifications to Discord webhooks, Slack channels, or email addresses whenever thresholds are breached (e.g., CPU > 90% for 5 minutes, or disk space < 10%):

# Create Prometheus alert rules file (/etc/prometheus/alert.rules.yml)
groups:
  - name: ServerAlerts
    rules:
      - alert: HighCpuUsage
        expr: 100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 85
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: "High CPU Usage detected on {{ $labels.instance }}"
          description: "CPU load is above 85% for more than 5 minutes."

      - alert: LowDiskSpace
        expr: (node_filesystem_avail_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"}) * 100 < 15
        for: 2m
        labels:
          severity: warning
        annotations:
          summary: "Disk space running low on {{ $labels.instance }}"
          description: "Root partition free space is below 15%."

Securing Prometheus & Node Exporter Behind Internal Localhost

Never expose Prometheus port 9090 or Node Exporter port 9100 to the public internet without authentication. Always bind their listening sockets to 127.0.0.1 and access the monitoring UI exclusively through Grafana behind Nginx SSL.

# Verify listening ports are restricted to loopback
sudo ss -tulpn | grep -E "(9090|9100)"
# Output should show 127.0.0.1:9090 and 127.0.0.1:9100 only

Deploy Monitored High-Performance Cloud VPS on CpanelFree

Gain complete visibility over your cloud infrastructure with dedicated enterprise compute, ultra-low latency NVMe storage, and 100% free hosting options.

Get Free Cloud Hosting Today →

Deploy Fast, Reliable Web Hosting on CpanelFree

Get genuine cPanel control, unmetered NVMe SSD storage, and free AutoSSL at $0 cost forever.

Claim Free Hosting Account

About the author

Blog

DevOps architect and Linux sysadmin specializing in server hardening, OpenLiteSpeed performance optimization, and free cloud hosting infrastructure.

Leave a Comment