Set Up Grafana
Grafana is the last piece. It shows what Prometheus and Loki have stored.
Table of Contents
Why
Grafana is the "screen" in The Grafana Stack. It stores no data itself. It asks Prometheus and Loki when you open a page.
Before it can draw anything, you tell it where Prometheus and Loki are. These are called data sources. The next page, Dashboards and Alerts, uses them by name, so use the names below exactly.
How: start Grafana
Use the same terminal as before, so NET is still set.
docker run -d --name grafana --network "$NET" -p 3001:3000 grafana/grafana:13.2.3
Check:
curl -s -o /dev/null -w '%{http_code}\n' localhost:3001/login
Expected:
200
How: log in
- Open
http://localhost:3001. - Log in with user
adminand passwordadmin. - Grafana asks for a new password. Set one, or click Skip.
How: add the data sources
Prometheus
- Go to Connections, then Data sources, then Add data source.
- Choose Prometheus.
- Name:
Prometheus. - URL:
http://prometheus:9090. - Click Save & test.
Expected: a green message that starts with Successfully queried the Prometheus API.
Loki
- Add data source again and choose Loki.
- Name:
Loki. - URL:
http://loki:3100. - Click Save & test.
Expected: a green message Data source successfully connected.
How: check it in Explore
Open Explore in the left menu.
Metrics. Pick the Prometheus data source, switch to the Code editor, paste this and run it:
rate(container_cpu_usage_seconds_total{service="api"}[1m])
Expected: a line for the api container. Open the playground in the browser and click around, and the line moves.
Logs. Pick the Loki data source, switch to the Code editor, paste this and run it:
{service="api"}
Expected: log lines from the api container.
Tips
- Grafana is on port 3001, not 3000. Port
localhost:3000is already the pizza shop. If you start Grafana on 3000 by mistake, it clashes. - In the data source URLs use the container names (
prometheus,loki), neverlocalhost. Grafana runs inside the Docker network, andlocalhostthere means Grafana itself. - If Save & test fails, check that the containers are running with
docker psand that they share the playground network. - If the Explore line is empty, widen the time range to the last 15 minutes. If it is still empty, go back to Set Up Alloy and run its checks.
- To stop the stack, start it again after a restart, or remove it, see
monitoring/sample/commands.md.docker stopanddocker startkeep the history. If the playground wasdocker compose down-ed while monitoring was stopped, recreate the four containers. - Grafana has no volume here.
docker rmerases your data sources and dashboards, so you add them again.
Next: Dashboards and Alerts.