Skip to content
Go back

Monitoring VPS with Prometheus + Grafana

Monitoring VPS with Prometheus + Grafana

Introduction

Prometheus collects metrics, and Grafana visualizes them. This guide installs both on a VPS to monitor system and application performance.

Prerequisites

Step 1: Install Prometheus

# Create user
sudo useradd --no-create-home --shell /bin/false prometheus

# Download Prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.42.0/prometheus-2.42.0.linux-amd64.tar.gz
tar xvf prometheus-*.tar.gz
cd prometheus-*

# Move binaries
sudo mv prometheus promtool /usr/local/bin/

# Configure directories
sudo mkdir -p /etc/prometheus /var/lib/prometheus
sudo mv consoles console_libraries /etc/prometheus
sudo mv prometheus.yml /etc/prometheus

# Set permissions
sudo chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus

Step 2: Configure Prometheus Service

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

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
ExecStart=/usr/local/bin/prometheus \
  --config.file=/etc/prometheus/prometheus.yml \
  --storage.tsdb.path=/var/lib/prometheus

[Install]
WantedBy=multi-user.target

Start service:

sudo systemctl daemon-reload
sudo systemctl enable prometheus
sudo systemctl start prometheus

Step 3: Install Node Exporter for System Metrics

wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
tar xvf node_exporter-*.tar.gz
sudo mv node_exporter /usr/local/bin/

# Create user and service
echo '[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=node_exporter
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=default.target' | sudo tee /etc/systemd/system/node_exporter.service

sudo useradd --no-create-home --shell /bin/false node_exporter
sudo systemctl daemon-reload
sudo systemctl enable node_exporter
sudo systemctl start node_exporter

Step 4: Update Prometheus Scrape Config

Edit /etc/prometheus/prometheus.yml:

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

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

Reload Prometheus:

sudo systemctl restart prometheus

Step 5: Install Grafana

sudo apt install -y apt-transport-https software-properties-common wget
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
sudo apt update
sudo apt install grafana
sudo systemctl enable grafana-server
sudo systemctl start grafana-server

Step 6: Configure Grafana Data Source

  1. Login to Grafana: http://<VPS_IP>:3000 (admin/admin).
  2. Add Prometheus data source pointing to http://localhost:9090.

Step 7: Import Dashboards

Use community dashboards: import ID 1860 (Node Exporter Full) or others.

Summary

Prometheus + Grafana on your VPS provides real-time system and app metrics. Use Node Exporter for OS stats and Grafana dashboards for visualization.


Share this post on:

Previous Post
Using Strapi GraphQL API with React Frontend
Next Post
Building a Custom Strapi v5 Plugin for Admin Panel