Lab 12: Grafana — Dashboards

Time: 45 minutes | Level: Architect | Docker: docker run -it --rm ubuntu:22.04 bash

Overview

Grafana is the industry-standard open-source visualization platform. It connects to data sources (Prometheus, Elasticsearch, InfluxDB, PostgreSQL, etc.) and renders dashboards with panels: time series, stat, gauge, table, heatmap, bar chart, and more. In this lab you download and run Grafana from the official binary, explore dashboard JSON structure, configure provisioning, and set up alerting.

Architecture

┌────────────────────────────────────────────────────────────┐
│                     Grafana Architecture                    │
│                                                            │
│  Browser ──► Grafana Server :3000                         │
│               │                                            │
│               ├── Data Sources                             │
│               │     ├── Prometheus (PromQL)                │
│               │     ├── Elasticsearch (Lucene/ES-DSL)      │
│               │     └── Loki (LogQL)                       │
│               │                                            │
│               ├── Dashboards (JSON model)                  │
│               │     ├── Panels (visualization units)       │
│               │     ├── Variables (template variables)     │
│               │     └── Annotations (event overlays)       │
│               │                                            │
│               ├── Alerting                                  │
│               │     ├── Alert Rules (per panel/query)       │
│               │     ├── Contact Points (email/slack)        │
│               │     └── Notification Policies              │
│               │                                            │
│               └── Provisioning (YAML files on disk)        │
│                     ├── datasources/                       │
│                     ├── dashboards/                        │
│                     └── alerting/                          │
└────────────────────────────────────────────────────────────┘

Step 1: Download and Verify Grafana Binary

📸 Verified Output:

💡 Starting Grafana 10+, the command is grafana server (not grafana-server). The binary in bin/ is a multi-command binary: grafana server, grafana cli, grafana migrate. All configuration lives in conf/defaults.ini — override via conf/custom.ini.


Step 2: Configure grafana.ini

📸 Verified Output:

💡 Grafana uses INI format with sections [section]. The conf/defaults.ini has every possible option with comments. Only override what you need in custom.ini. Use environment variables for secrets: GF_SECURITY_ADMIN_PASSWORD=secret.


Step 3: Provision Data Sources

📸 Verified Output:

💡 Set editable: false in provisioned data sources to prevent users from accidentally modifying the Prometheus URL in the UI. Changes to provisioning files take effect on Grafana restart or via POST /api/admin/provisioning/datasources/reload.


Step 4: Dashboard JSON Structure

📸 Verified Output:

💡 The uid field is critical — it's used in URLs (/d/<uid>/title) and for provisioning references. Keep it short, human-readable, and unique. Use schemaVersion: 38 for Grafana 10.x compatibility.


Step 5: Panel Types Reference

📸 Verified Output:

💡 The Stat panel is ideal for SLO dashboards showing current error rate or availability. The Heatmap panel is perfect for latency distributions from Prometheus histograms — set format to heatmap and legend format to {{le}} to get proper bucket display.


Step 6: Dashboard Provisioning

📸 Verified Output:

💡 Use allowUiUpdates: false to treat dashboards as code — they can only be changed by updating the JSON file. This enforces GitOps for dashboards. Export dashboards from UI via Share → Export → Save to file, then commit to your repo.


Step 7: Grafana Alerting Configuration

📸 Verified Output:

💡 Grafana 10 uses Unified Alerting (vs legacy panel alerting). Alert rules are evaluated by Grafana itself — not the data source. This means alerts fire even if the dashboard isn't open. Configure via UI under Alerting → Alert Rules, then export to YAML for GitOps.


Step 8: Capstone — Production Dashboard Stack

Scenario: Deploy a Grafana instance with provisioned dashboards, Prometheus data source, and alert rules for a production cluster. Validate the binary and directory structure.

📸 Verified Output:

💡 For production, use grafana cli plugins install grafana-piechart-panel to install community plugins. In Docker, mount a persistent volume at /var/lib/grafana to preserve dashboards, user data, and alert states across container restarts.


Summary

Concept
Key Details

Grafana version

10.1.2 (commit 8e428858dd), binary in bin/grafana

Config files

conf/defaults.ini (reference), conf/custom.ini (overrides)

Data sources

Provisioned via conf/provisioning/datasources/*.yaml, editable: false for GitOps

Panel types

timeseries, stat, gauge, table, heatmap, bar chart, histogram, pie chart

Variables

type: query + label_values() for dynamic dropdowns; multi: true for multi-select

Annotations

PromQL-based event overlays; also supports native Grafana annotations via API

Dashboard provisioning

JSON files in options.path; allowUiUpdates: false enforces GitOps

Unified Alerting

Grafana 10 default; evaluates rules server-side; routes via Contact Points

Plugins

grafana cli plugins install <id>; bundled plugins in plugins-bundled/

Production tips

Persistent volume for /var/lib/grafana, env vars for secrets, HTTPS via reverse proxy

Last updated