Skip to main content

The Grafana Stack

The four steps from Monitoring in General are collect, store, show and alert. In this module each step is done by one open-source tool. Together they are called the Grafana stack.

Table of Contents


Why​

These tools are free, run in Docker on a laptop and are common in real teams. Learning them here carries over to most companies.

You do not need to know how they work inside. You need to know what each one is for, so that when a graph is empty you know which piece to check.


How: four pieces​

PieceJobPatient monitor equivalent
AlloyCollects: reads the numbers and log lines and sends them onThe sensors on the finger and chest
PrometheusStores metrics: numbers over timeThe monitor's memory of the last hours
LokiStores logs: written lines about eventsThe nurse's notes
GrafanaShows and alerts: graphs, dashboards and alarmsThe screen and the alarm

How: how data moves​

Alloy reads container metrics and logs from the Docker socket and Postgres stats from the db, then pushes metrics to Prometheus and logs to Loki. k6 pushes results to Prometheus. Grafana queries Prometheus and Loki.

  1. The playground containers run as usual. They are not changed.
  2. Alloy reads the Docker socket. From it, it gets CPU and memory per container (network metrics are missing on OrbStack), and every container's log lines.
  3. Alloy also asks the Postgres database for its own stats: connections, locks and transactions.
  4. Alloy pushes the metrics to Prometheus and the log lines to Loki.
  5. k6 pushes its test results to Prometheus too. Watch a Load Test uses this.
  6. Grafana asks Prometheus and Loki for data when you open a dashboard. You open Grafana in the browser on port 3001.

Pull and push, in short. Prometheus normally pulls: it visits each target on a schedule and scrapes the numbers. Here, Alloy collects and pushes to Prometheus by remote write, and k6 does the same. Prometheus itself only scrapes itself and Alloy's health. Loki always receives pushes.


How: what we can see without changing the app​

WhatCan we see it?Where it comes from
Container CPU, memoryYesAlloy, from the Docker socket
Container logsYesAlloy, from the Docker socket
Postgres connections, locks, transactionsYesAlloy, asking the database
JVM details (heap, garbage collection, threads)NoNeeds a change in the app. See What Needs the Dev Team

Tips​

  • Old guides say "Grafana Agent". Alloy replaced it. The idea is the same, so the guides still help.
  • One Alloy per server is enough. It collects for every container on that machine.
  • InfluxDB appears in JMeter guides, through the Backend Listener. That is a different path to a different store. See Backend Listener.
  • If a graph is empty, follow the arrows in the diagram. Is the data reaching Prometheus or Loki at all, or is the problem only in Grafana?

Next: Set Up Prometheus starts the first piece.