📈
Monitoring & Observability

Grafana

Visualization and dashboard platform for metrics, logs, and traces

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

What is this?

Grafana turns server metrics into charts and dashboards so you can see what's happening at a glance.

📁

Config files for Grafana

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

  • /etc/grafana/grafana.ini

    Location: Grafana server

    Server URL, auth, and data sources path

📥

Step 01

Install Grafana

(01)Run with Docker

Linux
1docker run -d --name grafana -p 3000:3000 grafana/grafana
2# UI: http://localhost:3000 (admin/admin)

(02)Package install

Linux
1sudo apt-get install -y software-properties-common
2sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
3sudo apt-get update && sudo apt-get install grafana
4sudo systemctl enable grafana-server
⚙️

Step 02

Configure Grafana

(01)Add data sources and dashboards

Linux
1# Web UI: http://localhost:3000
2# 1. Configuration → Data Sources → Prometheus → URL: http://prometheus:9090
3# 2. Dashboards → Import → ID 1860 (Node Exporter)
4# 3. Alerting → Contact points → Email/Slack

(02)Provisioning via config files

Linux
1# datasources.yml:
2cat > provisioning/datasources/ds.yml << 'EOF'
3apiVersion: 1
4datasources:
5 - name: Prometheus
6 type: prometheus
7 url: http://prometheus:9090
8 isDefault: true
9EOF
10# Mount to /etc/grafana/provisioning/datasources/

Step 03

Verify

(01)Health check

Linux
1curl http://localhost:3000/api/health

Step 04

Manage Grafana

(01)Add Prometheus data source

Linux
1# In Grafana UI: Configuration → Data Sources → Add Prometheus
2# URL: http://prometheus:9090 (Docker network) or http://localhost:9090
🔧

Step 05

Common Problems

#1Grafana can't connect to Prometheus/Loki

Linux
1curl http://localhost:9090/-/healthy
2sudo journalctl -u grafana-server -n 30
3# Settings → Data sources → Test connection in UI

📋Config templates

2 YAML templates for Grafana. Copy and deploy after setup.

2 ready-to-copy templates. Expand one, copy the YAML, then run the deploy commands.

docker-compose.yml

yaml
1services:
2 prometheus:
3 image: prom/prometheus:latest
4 ports:
5 - "9090:9090"
6 volumes:
7 - ./prometheus.yml:/etc/prometheus/prometheus.yml
8 - prom_data:/prometheus
9
10 grafana:
11 image: grafana/grafana:latest
12 ports:
13 - "3000:3000"
14 environment:
15 GF_SECURITY_ADMIN_PASSWORD: admin
16 volumes:
17 - grafana_data:/var/lib/grafana
18 depends_on:
19 - prometheus
20
21volumes:
22 prom_data:
23 grafana_data:

prometheus.yml

yaml
1global:
2 scrape_interval: 15s
3
4scrape_configs:
5 - job_name: prometheus
6 static_configs:
7 - targets: ["localhost:9090"]
📄

Step 01

Run Prometheus + Grafana

(01)Start stack

Linux
1docker compose up -d --build
2docker compose ps
3docker compose logs -f

(02)Stop

Linux
1docker compose down