Labs · DevOps
Lab: Run Node Exporter, Prometheus and Grafana with Docker Compose, Build a Disk Panel and Trigger a Real Disk Alert
Course: DevOps · Chapter 13: Monitoring Basics · Lesson: 13.13 Lab: disk metric path and a triggered alert
Chapter 13 explains golden signals and the Prometheus path; this lab builds it on one machine.
Chala mitrano! Customer cha phone yenyaadhi dashboard var laal disla pahije. Aaj ek disk alert muddam fire karuya.
Suppose we are…
Suppose we are on the operations team of a Netflix-style app and a server once stopped because its disk filled up with logs. Nobody noticed until users complained. One metric and one alert would have warned us an hour earlier.
In this lab we run Node Exporter (host metrics), Prometheus (stores metrics and checks rules) and Grafana (dashboards) on one Linux machine, then fill the disk a little on purpose so the alert fires.
Goal of this lab
By the end you will have:
- Prometheus scraping Node Exporter (Status → Targets shows UP).
- A Grafana panel with disk used percent.
- An alert rule that goes from
InactivetoFiringand back.
What you need
- A Linux machine or VM with Docker and Compose (Node Exporter needs Linux to read the real host disk).
- Ports 3000 and 9090 free.
- About 2 GB free disk for the test file.
- 50 minutes.
Part 1: Config files
Create the folder and the Prometheus config:
prometheus.yml
global: scrape_interval: 15s evaluation_interval: 15s rule_files: - /etc/prometheus/alerts.yml scrape_configs: - job_name: node static_configs: - targets: ["node-exporter:9100"]mkdir mon && cd monCreate the alert rule. For the lab the threshold is low so you can trigger it; in real life use 80 or 90:
alerts.yml
groups: - name: host rules: - alert: DiskAlmostFull expr: 100 * (1 - node_filesystem_avail_bytes{mountpoint="/",fstype!="tmpfs"} / node_filesystem_size_bytes{mountpoint="/",fstype!="tmpfs"}) > LAB_LIMIT for: 1m labels: severity: warning annotations: summary: "Disk on / is above LAB_LIMIT percent"Run
df -h /, note your Use%, and replace bothLAB_LIMITvalues with that number plus 2 (for example 47 if you are at 45%).Create the compose file:
compose.yaml
services: node-exporter: image: prom/node-exporter:latest command: ["--path.rootfs=/host"] pid: host volumes: - /:/host:ro,rslave prometheus: image: prom/prometheus:latest ports: ["127.0.0.1:9090:9090"] volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro - ./alerts.yml:/etc/prometheus/alerts.yml:ro grafana: image: grafana/grafana:latest ports: ["127.0.0.1:3000:3000"]Ports bind to
127.0.0.1so only this machine can open the dashboards.
Part 2: Start and check targets
Start the stack:
docker compose up -d docker compose psWhat you should see: three services running.
Open
http://localhost:9090→ Status → Targets.What you should see:
nodewith state UP.In the Prometheus Graph page run this query:
100 * (1 - node_filesystem_avail_bytes{mountpoint="/",fstype!="tmpfs"} / node_filesystem_size_bytes{mountpoint="/",fstype!="tmpfs"})What you should see: one number close to the Use% from
df -h /.
Part 3: Grafana panel
Open
http://localhost:3000, log in withadmin/adminand set a new password when asked.- Connections → Data sources → Add → Prometheus, URL
http://prometheus:9090, Save & test.What you should see:
Successfully queried the Prometheus API. - Dashboards → New → Add visualization, choose the Prometheus source, paste the disk query, set unit Percent (0-100), title Disk used /, save the dashboard.
What you should see: a line near your disk percentage.
Part 4: Fire the alert
Create a 2 GB test file to push disk usage over the lab limit:
fallocate -l 2G ~/fill-test.img df -h /Open Prometheus Alerts and wait about 1–2 minutes.
What you should see:
DiskAlmostFullgoes Pending and then Firing; the Grafana panel jumps up.Remove the file:
rm ~/fill-test.imgWhat you should see: after a minute the alert returns to Inactive.
Clean up
Stop and remove the stack:
docker compose down ls ~/fill-test.img 2>/dev/null || echo "test file removed"
Ravindra Bagale's Tip
One alert that matters beats twenty that nobody reads. Start with disk, then add more only when you know who will act on them.
Common mistakes
| Mistake | What happens | Fix |
|---|---|---|
Target DOWN | No data in queries | Use the service name node-exporter:9100, not localhost |
Data source URL http://localhost:9090 in Grafana | Grafana cannot reach Prometheus | Use http://prometheus:9090 |
| Forgetting to delete the fill file | Disk stays high | rm ~/fill-test.img |
| Opening 3000/9090 to the internet | Dashboards visible to everyone | Bind to 127.0.0.1 or put them behind login and HTTPS |
Self-check checklist
0 of 5 done
Try-at-home challenge
Add Alertmanager to the compose file and route severity: warning to an email or chat webhook you own. Then add a CPU panel with 100 - avg(rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100.
Samajla ka? Metric, panel, alert, and someone who acts on it. Aata pudhe jaauya Kubernetes.