What Is Grafana? Your First Dashboard, Hands-On
Prometheus answers every PromQL question you have learned, but nobody wants to type histogram_quantile() mid-incident. Your team wants one screen that already shows request rate, errors and latency, and keeps itself current. So what is Grafana, and how do you build that screen? This lesson covers what Grafana does, its core ideas and your first live panel.
Grafana stores no metrics: it asks and draws
Grafana is an open-source tool for building dashboards: web pages of charts and numbers about your systems. As the stack map showed, it keeps no telemetry of its own. Each chart holds a query. When you open the page, Grafana sends that query to a data source, its saved connection to a system that stores data, such as Prometheus, and draws whatever comes back.
Grafana does have a small database, SQLite by default, but it holds dashboards, users and settings, not samples. Delete Grafana and every metric is still in Prometheus; stop Prometheus and the panels have nothing to draw. Later labs add Jaeger for traces and Elasticsearch for logs as data sources.
Core concepts: data source, dashboard, panel, query, time range and refresh
Six words cover most of what you will click in Grafana:
- Data source: that saved connection, with its type, URL and settings; one Grafana can have many.
- Dashboard: a page of panels with a title, saved in Grafana's database or loaded from a file.
- Panel: one box on a dashboard: one or more queries and a visualization.
- Query: the question a panel sends, in the data source's own language; for Prometheus, the PromQL from lesson 5.
- Time range: the period every panel shows, set with the time picker at the top right, such as Last 15 minutes.
- Refresh: running every query again. Grafana does not refresh a dashboard by default; the refresh picker beside the time picker can repeat it, for example every 10 seconds.
The time range belongs to the whole dashboard: change it once and every panel asks again for the new period. For a time series, Grafana sends Prometheus a range query over that period, the kind the Graph tab ran in lesson 5. Inside a panel, five parts matter for now:
A visualization is the way a panel draws its answer: a time series is a line over time, and a stat panel shows one big number. A unit tells Grafana how to label values, such as seconds. A threshold is a value where the colour changes; new panels start with green, then red from 80. The next lesson covers choosing them well.
The lab: Grafana with Prometheus provisioned from a file
The lab is course-labs/open-source-observability-stack/03-grafana. It runs the same shop-demo, loadgen, node exporter and Prometheus as section 2, with all three scrape jobs in place, plus grafana/grafana:13.3.2 on port 3000. Run docker compose down in the previous lab's folder first: both labs publish ports 8000, 9090 and 9100.
You could set Grafana up by clicking through its UI, but here it is provisioned: configured from files it reads when it starts. The file grafana/provisioning/datasources/prometheus.yml creates the data source, shown here without its comments and jsonData block:
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
uid: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
editable: false
The url uses the service name, which works as a host name on the obs-lab network. access: proxy means the Grafana server sends the queries, not your browser. isDefault preselects Prometheus in new panels, and editable: false stops the UI from changing what the file defines.
Start the lab with the commands from lesson 2, then check the containers:
cd course-labs/open-source-observability-stack/03-grafana
docker compose up -d
docker compose ps
You should see six services Up, and 127.0.0.1:3000->3000/tcp beside grafana. The sixth, webhook, is the alert receiver for lesson 11 and publishes no port. The first start downloads the images, so give it a minute. curl localhost:3000/api/health then returns a short JSON object containing "database": "ok". If up fails with port is already allocated, another lab is still running.
Build your first panel: requests per second
Your first panel answers a question from lesson 6: how many requests per second does shop-demo handle? sum(rate(http_requests_total[5m])) turns each counter into a per-second rate, then adds the series into one line. loadgen sends about 5 requests a second, so the line should sit near 5.
The query editor has two modes. Builder assembles PromQL from drop-downs, and Code lets you type it; both produce the same query. The flowchart shows the clicks; the try-it adds what you see at each step.
Explore for questions, dashboards for habits
Explore, in the left menu at http://localhost:3000/explore, is a page for running queries without building a dashboard. Use it for one-off questions during an investigation, such as "did errors rise after 10:05?": click Run query, change the query, run it again. The URL follows your query, so you can paste it to a teammate.
A dashboard is for the questions you ask every day, such as request rate and error ratio for each service. When an Explore query proves useful, its Add button puts it on a dashboard.
Saving, sharing and provisioned dashboards
Saving a dashboard stores its definition, a JSON document, in Grafana's database: in the lab, the grafana-data volume. Give it a name that says what it watches, such as Shop traffic, and use folders once you have many. docker compose down -v deletes that volume, and every dashboard saved in the UI goes with it.
To share one, click Share > Share internally > Copy link. Lock time range is on by default, so the link opens the period you were looking at, and your teammate sees the same spike.
Provisioning works for dashboards too. A dashboard provider file, grafana/provisioning/dashboards/dashboards.yml, tells Grafana to load every JSON file in a folder. Trimmed, it reads:
providers:
- name: shop-dashboards
type: file
updateIntervalSeconds: 10
allowUiUpdates: false
options:
path: /etc/grafana/dashboards
The lab mounts its dashboards folder there, so dashboards/shop-overview.json appears as Shop Overview. Change it in the UI and click Save, and Grafana shows Cannot save provisioned dashboard: the file is the source of truth. Edit the file instead. Grafana watches the folder, but change events do not always cross Docker bind mounts, so docker compose restart grafana, which rereads provisioning files, is the sure way. Files can live in Git, get reviewed and survive down -v.
To turn a dashboard built in the UI into such a file, use the Export icon, then Export as code, and save the JSON into dashboards. The provisioning reference lists every option.
Check yourself
A teammate runs docker compose down -v in the lab. Which survives: the request metrics, your saved dashboard, or Shop Overview?
Only Shop Overview comes back. -v deletes both volumes, so Prometheus's samples and the dashboard saved in Grafana's database are gone, while Shop Overview is reloaded from its file at the next start.
You want to check once whether /report got slower after this morning's deploy. Explore or a new dashboard?
Explore. It is a one-off question with nothing worth saving; if you find yourself asking it every day, add the query to a dashboard.
Why does editing the provisioned data source in the UI not work, and where do you change its URL?
The file sets editable: false, so the file stays the single source of truth. Change url in grafana/provisioning/datasources/prometheus.yml and restart Grafana, which reads provisioning files at startup.