What You'll Learn
How to use Grafana to visualize metrics from Prometheus, CloudWatch, or Elasticsearch. Best practices for dashboard design, variables, and PromQL panels.
What is Grafana?
While Prometheus is the brain that stores data, Grafana is the beautiful face. It connects to multiple data sources (Prometheus, InfluxDB, AWS CloudWatch, MySQL) and lets you build interactive dashboards with graphs, tables, heatmaps, and alerts.
Connecting Prometheus to Grafana
Grafana uses "Data Sources" to know where to fetch metrics.
- Go to Configuration (gear icon) → Data Sources.
- Click Add data source and select Prometheus.
- Set the URL (e.g.,
http://prometheus:9090if running in Docker network). - Click Save & Test.
Creating Your First Dashboard Panel
Let's create a panel to track CPU usage. When you add a new Panel, you'll enter a query. If Prometheus is the data source, you'll write PromQL.
Query Field (Metrics browser):
100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
Legend Format:
{{instance}} CPU
This makes the labels look clean, like "web-server-1 CPU" instead of the raw JSON label block.
Template Variables (Dynamic Dashboards)
Instead of hardcoding server names, you can use variables to create a drop-down menu at the top of your dashboard. This lets one dashboard serve hundreds of servers.
| Setting | Value | Purpose |
|---|---|---|
| Type | Query | Fetches values dynamically from Prometheus |
| Name | server | The variable used in queries as $server |
| Query | label_values(node_uname_info, instance) | Gets a list of all server 'instance' IPs/names |
| Multi-value | True | Allows selecting multiple servers at once |
Once created, update your panel query to use the variable:
rate(node_network_receive_bytes_total{instance=~"$server"}[5m])
The Ultimate Cheat Code: Grafana Dashboard Templates
Don't build everything from scratch! Grafana has a massive community sharing pre-built dashboards.
- Go to grafana.com/dashboards
- Search for "Node Exporter Full" (ID: 1860) or "Kubernetes Cluster" (ID: 315)
- In your Grafana, click + → Import
- Paste the ID, select your Prometheus data source, and BOOM — a world-class dashboard in 10 seconds.