Skip to main content

Grafana Hands-on Exercises — Build the Dashboard

Time to stop reading and start doing. These exercises use Docker to run Grafana and Prometheus locally.

How to follow

Run each command, open the Grafana UI at http://localhost:3000, and follow the steps.

Exercise 0 · Setup — Install the Dashboard​

Start Grafana with Prometheus
cat > docker-compose.yml << 'EOF'
services:
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
volumes:
- grafana-data:/var/lib/grafana

prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml

node-exporter:
image: prom/node-exporter:latest
ports:
- "9100:9100"
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
command:
- '--path.procfs=/host/proc'
- '--path.sysfs=/host/sys'
- '--path.rootfs=/rootfs'

volumes:
grafana-data:
EOF
Create prometheus.yml
cat > prometheus.yml << 'EOF'
global:
scrape_interval: 15s

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

- job_name: 'node'
static_configs:
- targets: ['node-exporter:9100']
EOF
Start everything
docker compose up -d

Open http://localhost:3000 → Login with admin / admin.

Remember

Grafana runs on port 3000. Default credentials are admin/admin. Change the password after first login.

Exercise 1 · Connect Prometheus​

  1. Click Gear icon → Data sources → Add data source
  2. Select Prometheus
  3. Set URL to http://prometheus:9090
  4. Click Save & Test

You should see "Data source is working."

Remember

Inside Docker, use service names (prometheus) not localhost. Grafana and Prometheus must be on the same Docker network.

Exercise 2 · Create Your First Panel​

  1. Click + → New Dashboard → Add visualization
  2. Select Prometheus
  3. Enter query: 100 - (avg(rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
  4. Set visualization to Gauge
  5. Set Min: 0, Max: 100
  6. Add thresholds: green < 70, yellow 70-90, red > 90
  7. Click Apply

You should see a gauge showing current CPU usage.

Remember

The Gauge panel is perfect for percentages. The thresholds make it visually obvious when CPU is high.

Exercise 3 · Build a Full Dashboard​

Add these panels to your dashboard:

Panel 1: CPU Usage (Gauge)

100 - (avg(rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)

Panel 2: Memory Usage (Gauge)

(1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) * 100

Panel 3: Request Rate (Time Series)

sum(rate(http_requests_total[5m])) by (job)

Panel 4: Active Targets (Stat)

count(up == 1)
Remember

Arrange panels logically: gauges at the top for quick overview, time series below for trend analysis.

Exercise 4 · Add Variables​

  1. Go to Dashboard Settings → Variables → Add variable
  2. Name: instance, Type: Query
  3. Query: label_values(up, instance)
  4. Click Apply

Now use $instance in panel queries:

rate(http_requests_total{instance="$instance"}[5m])

A dropdown appears at the top of the dashboard. Select different instances to filter.

Remember

Variables make dashboards reusable. One dashboard works for every server, service, or environment.

Exercise 5 · Import a Community Dashboard​

  1. Click + → Import
  2. Enter dashboard ID: 1860 (Node Exporter Full)
  3. Select your Prometheus data source
  4. Click Import

You now have a production-ready dashboard with dozens of panels.

Remember

Don't reinvent the wheel. Grafana's community dashboards are battle-tested and comprehensive.

Exercise 6 · Clean Up​

Stop everything
docker compose down -v
rm -f docker-compose.yml prometheus.yml
Remember

Remove containers after exercises. In production, use persistent volumes for Grafana data.