Install and configure Grafana with Prometheus for system monitoring

Intermediate 45 min Mar 31, 2026 24 views
Ubuntu 24.04 Ubuntu 22.04 Debian 12 AlmaLinux 9 Rocky Linux 9 Fedora 41

Set up a complete monitoring stack with Prometheus for metrics collection and Grafana for visualization. Create dashboards to monitor system performance, set up alerting rules, and secure your monitoring infrastructure.

Prerequisites

  • Root or sudo access
  • At least 2GB RAM
  • Open ports 3000, 9090, 9100

What this solves

Prometheus and Grafana provide a powerful monitoring solution for tracking system metrics, application performance, and infrastructure health. Prometheus collects and stores time-series data while Grafana creates visual dashboards and handles alerting. This combination gives you real-time visibility into your servers and applications with customizable alerts when issues arise.

Step-by-step installation

Update system packages

Start by updating your package manager to ensure you get the latest versions of dependencies.

sudo apt update && sudo apt upgrade -y
sudo dnf update -y

Create system users for monitoring services

Create dedicated users for Prometheus and Grafana to run securely without root privileges.

sudo useradd --no-create-home --shell /bin/false prometheus
sudo useradd --no-create-home --shell /bin/false node_exporter
sudo useradd --system --no-create-home --shell /bin/false grafana

Create directories for Prometheus

Set up the directory structure for Prometheus configuration and data storage.

sudo mkdir -p /etc/prometheus /var/lib/prometheus
sudo chown prometheus:prometheus /etc/prometheus /var/lib/prometheus

Download and install Prometheus

Download the latest Prometheus binary from the official releases and install it to the system.

cd /tmp
wget https://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gz
tar xzf prometheus-2.45.0.linux-amd64.tar.gz
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

Download and install Node Exporter

Node Exporter collects system metrics like CPU, memory, and disk usage that Prometheus will scrape.

wget https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gz
tar xzf 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 node_exporter:node_exporter /usr/local/bin/node_exporter

Configure Prometheus

Create the main Prometheus configuration file that defines what metrics to collect and from where.

global:
  scrape_interval: 15s
  evaluation_interval: 15s

rule_files:
  - "alert_rules.yml"

alerting:
  alertmanagers:
    - static_configs:
        - targets:
          - localhost:9093

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

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

  - job_name: 'grafana'
    static_configs:
      - targets: ['localhost:3000']

Set the correct ownership for the configuration file.

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

Create Prometheus systemd service

Configure Prometheus to run as a system service that starts automatically on boot.

[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 \
    --web.listen-address=0.0.0.0:9090 \
    --web.enable-lifecycle

[Install]
WantedBy=multi-user.target

Create Node Exporter systemd service

Set up Node Exporter to run as a service and collect system metrics continuously.

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

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter --web.listen-address=0.0.0.0:9100

[Install]
WantedBy=multi-user.target

Start Prometheus services

Enable and start both Prometheus and Node Exporter services.

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

Install Grafana

Add the official Grafana repository and install Grafana using your system's package manager.

sudo apt install -y software-properties-common wget
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt update
sudo apt install -y grafana
sudo tee /etc/yum.repos.d/grafana.repo << 'EOF'
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
EOF
sudo dnf install -y grafana

Configure Grafana

Modify the Grafana configuration to set up basic security and access settings.

[server]
http_port = 3000
domain = example.com
root_url = http://example.com:3000

[security]
admin_user = admin
admin_password = SecureP@ssw0rd123
secret_key = your_secret_key_here

[users]
allow_sign_up = false
allow_org_create = false

[auth.anonymous]
enabled = false
Warning: Change the default admin password and secret key before exposing Grafana to the internet.

Start Grafana service

Enable Grafana to start on boot and start the service now.

sudo systemctl enable --now grafana-server
sudo systemctl status grafana-server

Configure firewall rules

Open the necessary ports for Prometheus, Node Exporter, and Grafana to communicate.

sudo ufw allow 9090/tcp comment 'Prometheus'
sudo ufw allow 9100/tcp comment 'Node Exporter'
sudo ufw allow 3000/tcp comment 'Grafana'
sudo ufw reload
sudo firewall-cmd --permanent --add-port=9090/tcp
sudo firewall-cmd --permanent --add-port=9100/tcp
sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --reload

Add Prometheus data source to Grafana

Access Grafana at http://your-server-ip:3000 and log in with admin credentials. Navigate to Configuration > Data Sources and add Prometheus with URL http://localhost:9090.

curl -X POST \
  http://admin:SecureP@ssw0rd123@localhost:3000/api/datasources \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "Prometheus",
    "type": "prometheus",
    "url": "http://localhost:9090",
    "access": "proxy",
    "isDefault": true
  }'

Import system monitoring dashboard

Import a pre-built dashboard for Node Exporter metrics to visualize system performance immediately.

curl -X POST \
  http://admin:SecureP@ssw0rd123@localhost:3000/api/dashboards/import \
  -H 'Content-Type: application/json' \
  -d '{
    "dashboard": {
      "id": 1860,
      "title": "Node Exporter Full"
    },
    "inputs": [{
      "name": "DS_PROMETHEUS",
      "type": "datasource",
      "pluginId": "prometheus",
      "value": "Prometheus"
    }]
  }'

Create basic alerting rules

Set up Prometheus alerting rules for common system issues like high CPU usage and low disk space.

groups:
  • name: system_alerts
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 detected" description: "CPU usage is above 80% for more than 5 minutes" - alert: LowDiskSpace expr: (node_filesystem_avail_bytes / node_filesystem_size_bytes) * 100 < 10 for: 2m labels: severity: critical annotations: summary: "Low disk space" description: "Disk space is below 10%" - alert: HighMemoryUsage expr: (1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)) * 100 > 90 for: 5m labels: severity: warning annotations: summary: "High memory usage" description: "Memory usage is above 90%"

Set correct ownership and reload Prometheus configuration.

sudo chown prometheus:prometheus /etc/prometheus/alert_rules.yml
sudo systemctl reload prometheus

Secure with reverse proxy

For production deployments, consider placing Grafana behind a reverse proxy with SSL termination. You can use Traefik with automatic SSL for this purpose.

[server]
domain = monitoring.example.com
root_url = https://monitoring.example.com
serve_from_sub_path = false

[security]
cookie_secure = true
strict_transport_security = true

Verify your setup

Check that all services are running correctly and collecting metrics.

sudo systemctl status prometheus node_exporter grafana-server
curl http://localhost:9090/metrics
curl http://localhost:9100/metrics
curl http://localhost:3000/api/health

Access the web interfaces to verify functionality.

echo "Prometheus: http://$(curl -s ifconfig.me):9090"
echo "Node Exporter: http://$(curl -s ifconfig.me):9100"
echo "Grafana: http://$(curl -s ifconfig.me):3000"

Common issues

SymptomCauseFix
Prometheus won't startConfiguration syntax errorpromtool check config /etc/prometheus/prometheus.yml
Node Exporter metrics missingService not running or firewall blockingsudo systemctl restart node_exporter && curl localhost:9100/metrics
Grafana login failsIncorrect credentials or service downCheck /var/log/grafana/grafana.log for errors
Data source connection failsPrometheus not accessible from GrafanaVerify Prometheus URL is http://localhost:9090
Alerts not firingAlert rules syntax errorpromtool check rules /etc/prometheus/alert_rules.yml
Permission denied errorsIncorrect file ownershipsudo chown prometheus:prometheus /etc/prometheus/*

Next steps

Automated install script

Run this to automate the entire setup

#grafana #prometheus #monitoring #dashboards #alerting

Need help?

Don't want to manage this yourself?

We handle infrastructure for businesses that depend on uptime. From initial setup to ongoing operations.

Talk to an engineer