Grafana dashboards for CPU, memory and disk
Grafana draws Prometheus data as graphs: add Prometheus as a data source, write one PromQL query per panel, add an instance variable and keep Grafana behind HTTPS with a changed admin password.
- Updated Nov 27, 2026
- Markdown
Build a dashboard with CPU, memory, disk and network panels, and lock Grafana down behind HTTPS.
- Prometheus scraping node_exporter
- Grafana installed on a server or in Docker
Grafana turns Prometheus queries into graphs. Add Prometheus as a data source, create one panel per PromQL query (CPU busy percent, memory available, disk free percent, network traffic), add an instance variable so one dashboard serves every server, then change the default admin password and serve Grafana through a reverse proxy with HTTPS.
How it works#
Grafana stores no metrics. It sends your PromQL to Prometheus each time a panel refreshes and draws the result. A dashboard is a saved set of panels with a time range and optional variables. The flow is exporter, Prometheus, Grafana, as in Prometheus and node exporter basics. That means Grafana can be rebuilt freely as long as you keep the dashboard JSON, and that any panel is only as good as its query.
Step 1: Add the Prometheus data source#
Run Grafana on a private port first. With Docker Compose, bind it to localhost, as in centralize logs with Loki or rsyslog:
services:
grafana:
image: grafana/grafana:latest
ports:
- "127.0.0.1:3000:3000"
volumes:
- grafana-data:/var/lib/grafana
volumes:
grafana-data:Pin the image to a specific version for real use. Open Grafana, log in, and go to Connections, then Data sources, then Add data source, and choose Prometheus. Set the URL (http://127.0.0.1:9090 on the same host, or http://prometheus:9090 by Compose service name) and click Save and test.
On the first login Grafana asks for the admin password. Change it right away to a long unique one, and never leave the default. See also environment variables and secrets for passing it in without writing it in a file you commit.
Step 2: Create the panels#
Create a new dashboard and add a panel for each query. Set the visualization to Time series, and the unit shown in brackets.
CPU busy percent (unit Percent 0-100):
100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)Memory available percent:
node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100Disk free percent for the root filesystem:
node_filesystem_avail_bytes{mountpoint="/",fstype!~"tmpfs|overlay"}
/ node_filesystem_size_bytes{mountpoint="/",fstype!~"tmpfs|overlay"} * 100Network received and sent, in bits per second (unit bits/sec):
rate(node_network_receive_bytes_total{device!~"lo|veth.*|docker.*"}[5m]) * 8
rate(node_network_transmit_bytes_total{device!~"lo|veth.*|docker.*"}[5m]) * 8Set the panel title to what it answers, for example “Disk free %”, and add a threshold color so a low value is red. Memory available matters more than “free” memory, because Linux uses spare memory for cache, as explained in check disk, memory and CPU usage.
Step 3: Add an instance variable#
Open Dashboard settings, then Variables, and add a Query variable named instance with the query:
label_values(node_uname_info, instance)Tick multi-value and include all. Then change every panel query to filter on it, for example:
node_memory_MemAvailable_bytes{instance=~"$instance"}
/ node_memory_MemTotal_bytes{instance=~"$instance"} * 100Now one dashboard works for every server in your scrape list, and a drop-down at the top selects which one.
Step 4: Import a community dashboard#
Grafana has a public dashboard library, and node exporter dashboards are among the most shared. Use Dashboards, then New, then Import, enter the dashboard ID or paste its JSON, and pick your Prometheus data source. Treat it as a starting point. Open the panels, read the queries, and delete anything that confuses you. A dashboard with 40 panels you never look at hides the 4 that matter.
Step 5: Put Grafana behind HTTPS#
Do not publish port 3000 to the internet. Place a reverse proxy in front, terminate HTTPS there, and proxy to 127.0.0.1:3000. The proxy part is covered in nginx reverse proxy with certbot. Validate nginx with sudo nginx -t before reloading. Also consider limiting access by IP or a VPN, since a Grafana login page is a target for password guessing.
Check it worked#
- The data source page says the query succeeded after Save and test.
- Each panel shows a line, not “No data”.
- CPU, memory and disk values match
top,free -handdf -hon the server within a few percent. - The
instancedrop-down lists your servers and the panels change when you pick one. - The login page loads only over HTTPS and the default password no longer works.
Edge cases and gotchas#
- Wrong memory metric. MemFree looks low on healthy servers. Use MemAvailable.
- Pseudo filesystems pollute disk graphs. Exclude
tmpfs,overlayand similar withfstype!~, or you will see dozens of lines. - Docker network devices. Virtual interfaces like
veth...anddocker0double count traffic. Filter them out. - Time range and rate window. Zooming out to months with a 5 minute rate window works, but queries get heavier. Keep ranges reasonable.
- Dashboards are not backed up automatically. The Grafana volume holds them. Export JSON and keep it in git, without secrets.
- Anonymous access. Check that anonymous viewing is off unless you chose it, since graphs reveal hostnames and usage.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
Post "http://localhost:9090/api/v1/query": dial tcp: connect: connection refused | Grafana in a container cannot reach host localhost | Use the Compose service name or the host’s private IP |
Panel shows No data | Query label or metric wrong | Run the query in Prometheus first and fix names |
| Disk panel has many lines | Pseudo filesystems included | Add `fstype!~“tmpfs |
| CPU always near 0 or 100 | Wrong mode label | Use mode="idle" and the subtraction form |
| Variable list empty | Metric absent | Use label_values(up, instance) instead |
| Login loop behind the proxy | Wrong root URL or headers | Set the root URL in Grafana’s config and forward headers |
502 Bad Gateway from the proxy | Grafana not running | See fix 502 bad gateway |
| Dashboard lost after container recreation | No volume | Mount a volume at /var/lib/grafana |
Quick reference#
CPU busy %: 100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
Memory avail: node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100
Disk free %: node_filesystem_avail_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"} * 100
Variable: label_values(node_uname_info, instance)Related lessons#
- Prometheus and node exporter basics: where the data comes from.
- Alerting without alert fatigue: alert on what these panels show.
- Container metrics with cAdvisor and docker stats: add container panels.
- Nginx reverse proxy with certbot: serve Grafana over HTTPS.
- Build a public status page: the public view, separate from Grafana.
Next#
Turn these numbers into notifications in alerting without alert fatigue.
Check what you learned
Frequently asked questions
How do I connect Grafana to Prometheus?
In Grafana open Connections, then Data sources, add Prometheus and enter its URL, for example http://127.0.0.1:9090 or the Compose service name. Save and test, and Grafana reports whether it can query.
What PromQL shows CPU busy percent?
100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100). It subtracts the idle share from 100 per instance.
Should I build dashboards or import one?
Importing a community node exporter dashboard is a fast start. Read what each panel queries and remove what you do not need, then build your own for the checks you actually alert on.
How do I secure Grafana?
Change the default admin password on first login, put Grafana behind a reverse proxy with HTTPS, and do not publish port 3000 directly to the internet.
Sources
Keep going: guides and tutorials
- Our Health Check Failed and the Deploy Went Live Anyway A postmortem from our own dogfood run: a failed readiness probe still received traffic. What broke, why two correct parts added up to a bug, and the fix.
- Zero Downtime Deploy for Docker Apps, With Rollback How a Docker deploy waits for readiness before cutover, holds the previous release for rollback, rolls back on its own, and how to rehearse it.