# 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.

URL: https://levelrail.com/learn/monitoring/grafana-dashboards-for-cpu-memory-disk/
Updated: 2026-11-27

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](https://levelrail.com/learn/monitoring/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](https://levelrail.com/learn/monitoring/centralize-logs-with-loki-or-rsyslog/)):

```yaml
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](https://levelrail.com/learn/deploy-operate/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):

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

Memory available percent:

```text
node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100
```

Disk free percent for the root filesystem:

```text
node_filesystem_avail_bytes{mountpoint="/",fstype!~"tmpfs|overlay"}
  / node_filesystem_size_bytes{mountpoint="/",fstype!~"tmpfs|overlay"} * 100
```

Network received and sent, in bits per second (unit bits/sec):

```text
rate(node_network_receive_bytes_total{device!~"lo|veth.*|docker.*"}[5m]) * 8
rate(node_network_transmit_bytes_total{device!~"lo|veth.*|docker.*"}[5m]) * 8
```

Set 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](https://levelrail.com/learn/server-basics/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:

```text
label_values(node_uname_info, instance)
```

Tick multi-value and include all. Then change every panel query to filter on it, for example:

```text
node_memory_MemAvailable_bytes{instance=~"$instance"}
  / node_memory_MemTotal_bytes{instance=~"$instance"} * 100
```

Now 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](https://levelrail.com/learn/glossary/#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](https://levelrail.com/learn/domains-https/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 -h` and `df -h` on the server within a few percent.
- The `instance` drop-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`, `overlay` and similar with `fstype!~`, or you will see dozens of lines.
- **Docker network devices.** Virtual interfaces like `veth...` and `docker0` double 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|overlay"` and a mountpoint filter |
| 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](https://levelrail.com/learn/deploy-operate/fix-502-bad-gateway/)) |
| Dashboard lost after container recreation | No volume | Mount a volume at `/var/lib/grafana` |

## Quick reference

```text
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](https://levelrail.com/learn/monitoring/prometheus-and-node-exporter-basics/)): where the data comes from.
- [Alerting without alert fatigue](https://levelrail.com/learn/monitoring/alerting-without-alert-fatigue/)): alert on what these panels show.
- [Container metrics with cAdvisor and docker stats](https://levelrail.com/learn/monitoring/container-metrics-with-cadvisor-and-docker-stats/)): add container panels.
- [Nginx reverse proxy with certbot](https://levelrail.com/learn/domains-https/nginx-reverse-proxy-with-certbot/)): serve Grafana over HTTPS.
- [Build a public status page](https://levelrail.com/learn/monitoring/build-a-public-status-page/)): the public view, separate from Grafana.

## Next

Turn these numbers into notifications in [alerting without alert fatigue](https://levelrail.com/learn/monitoring/alerting-without-alert-fatigue/)).

## 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

- [Grafana documentation](https://grafana.com/docs/grafana/latest/)
- [Grafana, Prometheus data source](https://grafana.com/docs/grafana/latest/datasources/prometheus/)
