Skip to main content

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​

  1. Open http://localhost:3001.
  2. Log in with user admin and password admin.
  3. Grafana asks for a new password. Set one, or click Skip.

How: add the data sources​

Prometheus

  1. Go to Connections, then Data sources, then Add data source.
  2. Choose Prometheus.
  3. Name: Prometheus.
  4. URL: http://prometheus:9090.
  5. Click Save & test.

Expected: a green message that starts with Successfully queried the Prometheus API.

Loki

  1. Add data source again and choose Loki.
  2. Name: Loki.
  3. URL: http://loki:3100.
  4. 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:3000 is 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), never localhost. Grafana runs inside the Docker network, and localhost there means Grafana itself.
  • If Save & test fails, check that the containers are running with docker ps and 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 stop and docker start keep the history. If the playground was docker compose down-ed while monitoring was stopped, recreate the four containers.
  • Grafana has no volume here. docker rm erases your data sources and dashboards, so you add them again.

Next: Dashboards and Alerts.