Grafana is where metrics, logs and traces become something a person can read during an incident. The SRE track covered building panels; this lesson looks at Grafana as software you operate, from grafana/grafana: how it is put together, how to run it reliably, how to keep data sources and dashboards in code instead of in someone's browser, how variables make one dashboard serve every service, and how to build a dashboard for an LLM-serving fleet.
- Describe Grafana's backend, frontend, plugin and database layers
- Run Grafana with an external database and configuration from environment variables
- Provision data sources and dashboards from files, or sync them with Git
- Use template variables, repeats and the right interval macros in queries
- Build an inference dashboard around latency, throughput, queueing and errors
Inside the repository
Grafana is a Go backend and a React frontend in one repository, licensed AGPL-3.0. pkg/ holds the server: HTTP API, authentication, the alerting engine, query routing and the storage layer. public/app/ is the web application. packages/ publishes the libraries that plugin authors use, such as @grafana/ui and @grafana/data. conf/defaults.ini lists every setting with its default, and conf/provisioning/ shows sample provisioning files.
- Data source plugins translate Grafana queries into Prometheus, Loki, Tempo, PostgreSQL, Elasticsearch and many more. Grafana stores no metrics itself; it queries the systems that do.
- Panel plugins draw things: time series, stat, gauge, table, heatmap, logs, traces, node graph.
- App plugins bundle pages, data sources and dashboards into one installable product.
- The Grafana database stores users, organisations, dashboards, folders, alert rules and settings. It is SQLite by default; MySQL and PostgreSQL are supported for production and required to run more than one Grafana replica.
Every setting in defaults.ini can be overridden with an environment variable named GF_<SECTION>_<KEY>, for example GF_DATABASE_TYPE=postgres. That is the cleanest way to configure Grafana in containers.
Running Grafana for real
A Grafana on its default SQLite file inside a container loses every dashboard when the pod is rescheduled. For a shared instance, point it at a managed database, run two or more replicas behind a load balancer, and keep secrets out of the config file.
docker run -d --name grafana -p 3000:3000 \
-e GF_DATABASE_TYPE=postgres \
-e GF_DATABASE_HOST=db.internal:5432 \
-e GF_DATABASE_NAME=grafana \
-e GF_DATABASE_USER=grafana \
-e GF_DATABASE_PASSWORD="$GRAFANA_DB_PASSWORD" \
-e GF_SECURITY_ADMIN_PASSWORD="$GRAFANA_ADMIN_PASSWORD" \
-v "$PWD/provisioning:/etc/grafana/provisioning" \
grafana/grafana:13.2.3- Pin the image tag; the default port is 3000 and the default login is admin/admin until you change it.
- Configure SSO (OAuth or SAML) and map identity-provider groups to Grafana teams and roles instead of creating local users.
- Use service accounts with tokens for automation; personal API keys tied to people break when people leave.
- Grafana-managed alerting with several replicas needs those replicas to find each other (HA alerting settings), so alerts are not sent twice.
Dashboards and data sources as code
Dashboards clicked together in the UI drift, get deleted, and differ between staging and production. Grafana offers several ways to keep them in version control. The oldest and simplest is file provisioning: YAML files in provisioning/datasources/ and provisioning/dashboards/ that Grafana reads at start-up and, for dashboards, keeps watching.
apiVersion: 1
datasources:
- name: Prometheus
uid: prom-main
type: prometheus
access: proxy
url: http://prometheus.monitoring.svc:9090
isDefault: true
jsonData:
timeInterval: 30sapiVersion: 1
providers:
- name: platform
folder: Platform
type: file
allowUiUpdates: false
options:
path: /var/lib/grafana/dashboards
foldersFromFilesStructure: trueGive data sources a fixed uid so dashboard JSON can reference them reliably across environments. Newer options build on the same idea: Git Sync (generally available since Grafana 13) connects a folder to a Git repository two ways, so saving in the UI can open a pull request and merging in Git updates Grafana; the Foundation SDK generates dashboard JSON from Go, TypeScript, Python, Java or PHP; and the gcx CLI pushes resources through Grafana's newer REST APIs from CI. Terraform's Grafana provider remains a good fit if the rest of your stack is Terraform.
Variables: one dashboard for every service
A template variable is a dropdown whose value is substituted into every query on the dashboard. A query variable fills itself from your data, for example label_values(up, namespace) for Prometheus, and variables can chain, so choosing a namespace narrows the list of services. Repeat a panel or row over a multi-value variable to get one per selected model, region or pod.
sum by (model) (
rate(inference_requests_total{namespace="$namespace", model=~"$model"}[$__rate_interval])
)- Use
$__rate_intervalinrate()andincrease(): it stays at least four scrape intervals wide (from the data source's scrape interval setting), so zooming out never produces empty or jagged graphs. $__intervalis the time per data point for the current zoom; good for_over_timefunctions, not forrate().- Use
=~with multi-value variables, because Grafana expands several selections into a regex such as(a|b). - Filters (formerly called ad hoc filters) add label matchers to every query without editing each panel.
An LLM-serving dashboard
A good service dashboard answers "is it healthy, and if not, where?" in the top row, then lets you drill down. For an inference fleet built on vLLM or a similar engine, lay it out like this, one row per question, with $model as the repeat variable:
| Row | Panels | Query idea |
|---|---|---|
| Is it up and fast? | Stat: request rate, error ratio, p95 time to first token | histogram_quantile(0.95, ...time_to_first_token...) |
| Is demand outrunning capacity? | Time series: requests running vs waiting | vllm:num_requests_running, vllm:num_requests_waiting |
| Is the GPU memory full? | Gauge: KV cache usage per pod | vllm:kv_cache_usage_perc |
| What does it cost? | Time series: prompt and generated tokens per second | rate(vllm:prompt_tokens_total[$__rate_interval]) |
Add an annotation query for deploys so a latency step lines up visibly with the release that caused it, and link each panel to the matching Tempo traces or Loki logs through data links. Keep it to one screen of headline panels; anything below the fold is for investigation, not for spotting trouble.