Grafana Hands-on Exercises — Build the Dashboard
Time to stop reading and start doing. These exercises use Docker to run Grafana and Prometheus locally.
Run each command, open the Grafana UI at http://localhost:3000, and follow the steps.
Exercise 0 · Setup — Install the Dashboard
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
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
docker compose up -d
Open http://localhost:3000 → Login with admin / admin.
Grafana runs on port 3000. Default credentials are admin/admin. Change the password after first login.
Exercise 1 · Connect Prometheus
- Click Gear icon → Data sources → Add data source
- Select Prometheus
- Set URL to
http://prometheus:9090 - Click Save & Test
You should see "Data source is working."
Inside Docker, use service names (prometheus) not localhost. Grafana and Prometheus must be on the same Docker network.
Exercise 2 · Create Your First Panel
- Click + → New Dashboard → Add visualization
- Select Prometheus
- Enter query:
100 - (avg(rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) - Set visualization to Gauge
- Set Min: 0, Max: 100
- Add thresholds: green < 70, yellow 70-90, red > 90
- Click Apply
You should see a gauge showing current CPU usage.
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)
Arrange panels logically: gauges at the top for quick overview, time series below for trend analysis.
Exercise 4 · Add Variables
- Go to Dashboard Settings → Variables → Add variable
- Name:
instance, Type: Query - Query:
label_values(up, instance) - 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.
Variables make dashboards reusable. One dashboard works for every server, service, or environment.
Exercise 5 · Import a Community Dashboard
- Click + → Import
- Enter dashboard ID: 1860 (Node Exporter Full)
- Select your Prometheus data source
- Click Import
You now have a production-ready dashboard with dozens of panels.
Don't reinvent the wheel. Grafana's community dashboards are battle-tested and comprehensive.
Exercise 6 · Clean Up
docker compose down -v
rm -f docker-compose.yml prometheus.yml
Remove containers after exercises. In production, use persistent volumes for Grafana data.