📊
Monitoring & Observability

Prometheus + Grafana Stack

Full observability stack — metrics collection with Prometheus and dashboards in Grafana

🐧 Linux🍎 Mac🪟 Windows
Reviewed: Tested on: Kubernetes 1.29 · Terraform 1.8 · Ubuntu 22.04

What is this?

Together, Prometheus collects the data and Grafana shows it in easy-to-read dashboards.

📁

Config files for Prometheus + Grafana Stack

Where to create or edit the main configuration — paths below match the setup steps.

  • prometheus.yml

    Location: Prometheus config directory

    Metrics scrape configuration

  • grafana provisioning/

    Location: Grafana /etc/grafana/provisioning/

    Datasources and dashboards as code

📥

Step 01

Install Prometheus + Grafana

(01)Docker Compose full stack

Linux
1mkdir prometheus-grafana && cd prometheus-grafana
2
3cat > docker-compose.yml << 'EOF'
4services:
5 prometheus:
6 image: prom/prometheus:latest
7 ports: ["9090:9090"]
8 volumes:
9 - ./prometheus.yml:/etc/prometheus/prometheus.yml
10 - prom_data:/prometheus
11
12 grafana:
13 image: grafana/grafana:latest
14 ports: ["3000:3000"]
15 environment:
16 GF_SECURITY_ADMIN_PASSWORD: admin
17 volumes:
18 - grafana_data:/var/lib/grafana
19 depends_on: [prometheus]
20
21 node-exporter:
22 image: prom/node-exporter:latest
23 ports: ["9100:9100"]
24
25volumes:
26 prom_data:
27 grafana_data:
28EOF
29
30cat > prometheus.yml << 'EOF'
31global:
32 scrape_interval: 15s
33scrape_configs:
34 - job_name: prometheus
35 static_configs:
36 - targets: ["localhost:9090"]
37 - job_name: node
38 static_configs:
39 - targets: ["node-exporter:9100"]
40EOF
41
42docker compose up -d
⚙️

Step 02

Configure Stack

(01)Add Prometheus data source in Grafana

Linux
1# Open http://localhost:3000 (admin/admin)
2# Configuration → Data Sources → Add Prometheus
3# URL: http://prometheus:9090 (Docker network)
4# Or: http://host.docker.internal:9090
5
6# Save & Test → should show "Data source is working"

(02)Import Node Exporter dashboard

Linux
1# In Grafana UI:
2# Dashboards → New → Import
3# Dashboard ID: 1860 (Node Exporter Full)
4# Select Prometheus data source → Import
5
6# Custom PromQL queries:
7# node_memory_MemAvailable_bytes
8# rate(node_cpu_seconds_total{mode="idle"}[5m])

(03)Add alert rules in Prometheus

Linux
1# prometheus.yml — add rule_files:
2rule_files:
3 - /etc/prometheus/alert.rules.yml
4
5# alert.rules.yml:
6groups:
7 - name: example
8 rules:
9 - alert: HighCPU
10 expr: 100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80
11 for: 5m
12 labels:
13 severity: warning
14 annotations:
15 summary: "High CPU on {{ $labels.instance }}"
16
17docker compose restart prometheus

Step 03

Verify Stack

(01)Check all services

Linux
1curl http://localhost:9090/-/healthy
2curl http://localhost:3000/api/health
3curl http://localhost:9100/metrics | head
4# Prometheus targets: http://localhost:9090/targets

Step 04

Manage Stack

(01)Add scrape targets and backup

Linux
1# Add target to prometheus.yml:
2# - job_name: myapp
3# static_configs:
4# - targets: ["app:8080"]
5
6docker compose restart prometheus
7
8# Backup Grafana dashboards:
9# Export JSON from UI or use grafana-cli