Sub topic 12
Building a Server Dashboard
This chapter assumes that Prometheus already scrapes node_exporter, that you can write basic PromQL, and that Grafana is running. The goal is a dashboard that shows CPU, memory, and disk usage for one or more Linux servers.
Plan the dashboard around questions
A useful dashboard answers operational questions quickly:
- Is the server busy?
- Is memory pressure increasing?
- Which filesystem is filling up?
- Which server does this panel describe?
Avoid adding every available metric. Start with a small set of panels and add detail only when it helps diagnose a real problem.
A typical server dashboard contains:
| Panel | Purpose | Useful display |
|---|---|---|
| CPU utilisation | Shows recent processor demand | Time series or gauge |
| Memory in use | Shows available memory pressure | Time series |
| Disk used | Shows filesystem capacity | Time series or table |
Create the dashboard
In Grafana, select Dashboards, choose New, and create a dashboard with a Prometheus data source. Add a Time series panel for CPU utilisation. Enter this query:
100 * (1 - avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])))The rate function calculates the recent per-second change in a counter. The query averages idle time across CPU cores, subtracts it from one, and converts the result to a percentage.
For memory usage, add another time-series panel:
100 * (1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)Set the unit to Percent (0-100). Set the legend to show {{instance}}, so each line identifies its server.
For disk usage, use a table or time-series panel:
100 * (1 - node_filesystem_avail_bytes{fstype!~"tmpfs|overlay"} / node_filesystem_size_bytes{fstype!~"tmpfs|overlay"})The label matcher excludes temporary and container filesystems. Display the instance and mountpoint labels in the legend. Otherwise, a full filesystem may be confused with a virtual mount.
Add a server variable
A variable lets a viewer switch servers without editing every panel. Open Dashboard settings, choose Variables, and create a query variable named instance.
Configure it to obtain values from the instance label. Enable Multi-value only if the panels should compare several servers. Enable Include All when the dashboard should also support an overview of every server.
Add {instance=~"$instance"} to each metric selector. For example:
100 * (1 - avg by (instance) (rate(node_cpu_seconds_total{mode="idle", instance=~"$instance"}[5m])))Use a regular-expression matcher because Grafana can substitute several selected values into $instance.
Test and refine panels
Choose a time range that includes recent scrapes. Inspect the panel's query response and confirm that each series has the expected labels. Set sensible units, decimal precision, legends, and thresholds. Save the dashboard only after testing both one server and multiple servers.
Exercise
Why should a dashboard variable use instance=~"$instance" instead of instance="$instance" when multi-value selection is enabled?
Show answer
The =~ matcher accepts a regular expression containing several selected label values, while = expects one exact value.