1
---
2
name: grafana-dashboards
3
description: Create and manage production Grafana dashboards for real-time visualization of system and application metrics. Use when building monitoring dashboards, visualizing metrics, or creating operational observability interfaces.
4
---
5
6
# Grafana Dashboards
7
8
Create and manage production-ready Grafana dashboards for comprehensive system observability.
9
10
## Purpose
11
12
Design effective Grafana dashboards for monitoring applications, infrastructure, and business metrics.
13
14
## When to Use
15
16
- Visualize Prometheus metrics
17
- Create custom dashboards
18
- Implement SLO dashboards
19
- Monitor infrastructure
20
- Track business KPIs
21
22
## Dashboard Design Principles
23
24
### 1. Hierarchy of Information
25
26
```
27
┌─────────────────────────────────────┐
28
│ Critical Metrics (Big Numbers) │
29
├─────────────────────────────────────┤
30
│ Key Trends (Time Series) │
31
├─────────────────────────────────────┤
32
│ Detailed Metrics (Tables/Heatmaps) │
33
└─────────────────────────────────────┘
34
```
35
36
### 2. RED Method (Services)
37
38
- **Rate** - Requests per second
39
- **Errors** - Error rate
40
- **Duration** - Latency/response time
41
42
### 3. USE Method (Resources)
43
44
- **Utilization** - % time resource is busy
45
- **Saturation** - Queue length/wait time
46
- **Errors** - Error count
47
48
## Dashboard Structure
49
50
### API Monitoring Dashboard
51
52
```json
53
{
54
"dashboard": {
55
"title": "API Monitoring",
56
"tags": ["api", "production"],
57
"timezone": "browser",
58
"refresh": "30s",
59
"panels": [
60
{
61
"title": "Request Rate",
62
"type": "graph",
63
"targets": [
64
{
65
"expr": "sum(rate(http_requests_total[5m])) by (service)",
66
"legendFormat": "{{service}}"
67
}
68
],
69
"gridPos": { "x": 0, "y": 0, "w": 12, "h": 8 }
70
},
71
{
72
"title": "Error Rate %",
73
"type": "graph",
74
"targets": [
75
{
76
"expr": "(sum(rate(http_requests_total{status=~\"5..\"}[5m])) / sum(rate(http_requests_total[5m]))) * 100",
77
"legendFormat": "Error Rate"
78
}
79
],
80
"alert": {
81
"conditions": [
82
{
83
"evaluator": { "params": [5], "type": "gt" },
84
"operator": { "type": "and" },
85
"query": { "params": ["A", "5m", "now"] },
86
"type": "query"
87
}
88
]
89
},
90
"gridPos": { "x": 12, "y": 0, "w": 12, "h": 8 }
91
},
92
{
93
"title": "P95 Latency",
94
"type": "graph",
95
"targets": [
96
{
97
"expr": "histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[5m])) by (le, service))",
98
"legendFormat": "{{service}}"
99
}
100
],
101
"gridPos": { "x": 0, "y": 8, "w": 24, "h": 8 }
102
}
103
]
104
}
105
}
106
```
107
108
## Panel Types
109
110
### 1. Stat Panel (Single Value)
111
112
```json
113
{
114
"type": "stat",
115
"title": "Total Requests",
116
"targets": [
117
{
118
"expr": "sum(http_requests_total)"
119
}
120
],
121
"options": {
122
"reduceOptions": {
123
"values": false,
124
"calcs": ["lastNotNull"]
125
},
126
"orientation": "auto",
127
"textMode": "auto",
128
"colorMode": "value"
129
},
130
"fieldConfig": {
131
"defaults": {
132
"thresholds": {
133
"mode": "absolute",
134
"steps": [
135
{ "value": 0, "color": "green" },
136
{ "value": 80, "color": "yellow" },
137
{ "value": 90, "color": "red" }
138
]
139
}
140
}
141
}
142
}
143
```
144
145
### 2. Time Series Graph
146
147
```json
148
{
149
"type": "graph",
150
"title": "CPU Usage",
151
"targets": [
152
{
153
"expr": "100 - (avg by (instance) (rate(node_cpu_seconds_total{mode=\"idle\"}[5m])) * 100)"
154
}
155
],
156
"yaxes": [
157
{ "format": "percent", "max": 100, "min": 0 },
158
{ "format": "short" }
159
]
160
}
161
```
162
163
### 3. Table Panel
164
165
```json
166
{
167
"type": "table",
168
"title": "Service Status",
169
"targets": [
170
{
171
"expr": "up",
172
"format": "table",
173
"instant": true
174
}
175
],
176
"transformations": [
177
{
178
"id": "organize",
179
"options": {
180
"excludeByName": { "Time": true },
181
"indexByName": {},
182
"renameByName": {
183
"instance": "Instance",
184
"job": "Service",
185
"Value": "Status"
186
}
187
}
188
}
189
]
190
}
191
```
192
193
### 4. Heatmap
194
195
```json
196
{
197
"type": "heatmap",
198
"title": "Latency Heatmap",
199
"targets": [
200
{
201
"expr": "sum(rate(http_request_duration_seconds_bucket[5m])) by (le)",
202
"format": "heatmap"
203
}
204
],
205
"dataFormat": "tsbuckets",
206
"yAxis": {
207
"format": "s"
208
}
209
}
210
```
211
212
## Variables
213
214
### Query Variables
215
216
```json
217
{
218
"templating": {
219
"list": [
220
{
221
"name": "namespace",
222
"type": "query",
223
"datasource": "Prometheus",
224
"query": "label_values(kube_pod_info, namespace)",
225
"refresh": 1,
226
"multi": false
227
},
228
{
229
"name": "service",
230
"type": "query",
231
"datasource": "Prometheus",
232
"query": "label_values(kube_service_info{namespace=\"$namespace\"}, service)",
233
"refresh": 1,
234
"multi": true
235
}
236
]
237
}
238
}
239
```
240
241
### Use Variables in Queries
242
243
```
244
sum(rate(http_requests_total{namespace="$namespace", service=~"$service"}[5m]))
245
```
246
247
## Alerts in Dashboards
248
249
```json
250
{
251
"alert": {
252
"name": "High Error Rate",
253
"conditions": [
254
{
255
"evaluator": {
256
"params": [5],
257
"type": "gt"
258
},
259
"operator": { "type": "and" },
260
"query": {
261
"params": ["A", "5m", "now"]
262
},
263
"reducer": { "type": "avg" },
264
"type": "query"
265
}
266
],
267
"executionErrorState": "alerting",
268
"for": "5m",
269
"frequency": "1m",
270
"message": "Error rate is above 5%",
271
"noDataState": "no_data",
272
"notifications": [{ "uid": "slack-channel" }]
273
}
274
}
275
```
276
277
## Dashboard Provisioning
278
279
**dashboards.yml:**
280
281
```yaml
282
apiVersion: 1
283
284
providers:
285
- name: "default"
286
orgId: 1
287
folder: "General"
288
type: file
289
disableDeletion: false
290
updateIntervalSeconds: 10
291
allowUiUpdates: true
292
options:
293
path: /etc/grafana/dashboards
294
```
295
296
## Common Dashboard Patterns
297
298
### Infrastructure Dashboard
299
300
**Key Panels:**
301
302
- CPU utilization per node
303
- Memory usage per node
304
- Disk I/O
305
- Network traffic
306
- Pod count by namespace
307
- Node status
308
309
### Database Dashboard
310
311
**Key Panels:**
312
313
- Queries per second
314
- Connection pool usage
315
- Query latency (P50, P95, P99)
316
- Active connections
317
- Database size
318
- Replication lag
319
- Slow queries
320
321
### Application Dashboard
322
323
**Key Panels:**
324
325
- Request rate
326
- Error rate
327
- Response time (percentiles)
328
- Active users/sessions
329
- Cache hit rate
330
- Queue length
331
332
## Best Practices
333
334
1. **Start with templates** (Grafana community dashboards)
335
2. **Use consistent naming** for panels and variables
336
3. **Group related metrics** in rows
337
4. **Set appropriate time ranges** (default: Last 6 hours)
338
5. **Use variables** for flexibility
339
6. **Add panel descriptions** for context
340
7. **Configure units** correctly
341
8. **Set meaningful thresholds** for colors
342
9. **Use consistent colors** across dashboards
343
10. **Test with different time ranges**
344
345
## Dashboard as Code
346
347
### Terraform Provisioning
348
349
```hcl
350
resource "grafana_dashboard" "api_monitoring" {
351
config_json = file("${path.module}/dashboards/api-monitoring.json")
352
folder = grafana_folder.monitoring.id
353
}
354
355
resource "grafana_folder" "monitoring" {
356
title = "Production Monitoring"
357
}
358
```
359
360
### Ansible Provisioning
361
362
```yaml
363
- name: Deploy Grafana dashboards
364
copy:
365
src: "{{ item }}"
366
dest: /etc/grafana/dashboards/
367
with_fileglob:
368
- "dashboards/*.json"
369
notify: restart grafana
370
```
371
372
373
## Related Skills
374
375
- `prometheus-configuration` - For metric collection
376
- `slo-implementation` - For SLO dashboards
377