Turn Prometheus data into dashboards. Connect Grafana to Prometheus, build panels from PromQL, make them reusable with variables, and save dashboards as code.
Why: Grafana visualizes data from a "data source". Open Grafana (http://localhost:3000, login admin/admin), then add Prometheus as a data source pointing at its in-network URL. Once connected, every panel you build queries Prometheus with PromQL.
Grafana is on http://localhost:3000 (default login: admin / admin) Add a data source: Connections → Data sources → Add → Prometheus URL: http://prometheus:9090 (the Compose service name) Save & test → "Data source is working"
Why: a panel is one visualization driven by a query. Create a dashboard, add a panel, pick the Prometheus data source, and enter a PromQL expression — the same queries you tested in the expression browser. Choose a visualization (time series, stat, gauge) to match the data.
# Panel query: requests per second by status
sum by (status) (rate(http_requests_total[5m]))
# Panel query: 95th-percentile latency
histogram_quantile(0.95, sum by (le) (rate(app_request_seconds_bucket[5m])))Why: hardcoding an instance or job into every panel means a new dashboard per server. A template variable (e.g. $instance) turns into a dropdown at the top of the dashboard; reference it in queries and one dashboard serves every host. Define variables in dashboard Settings → Variables, often populated by a label_values query.
# Variable definition (query type), to list all instances:
label_values(node_cpu_seconds_total, instance)
# Use the variable in a panel query:
node_memory_MemAvailable_bytes{instance="$instance"}Why: a dashboard built by clicking lives only in Grafana's database. Export it to JSON (dashboard settings → JSON Model, or the Share button) and commit it to git, so dashboards are versioned and reproducible. Grafana provisioning can auto-load these JSON files on startup — dashboards as code, like everything else.
# grafana/provisioning/dashboards/dashboards.yml
apiVersion: 1
providers:
- name: default
type: file
options:
path: /var/lib/grafana/dashboards # drop exported .json files here