Linux Labs

Observability: metrics, alerts, logs / Stage 2 of 9

PromQL: rate, sum and comparison

Not running Starting usually ~20 s
Leave the lesson

Step 5 of 6 · lab · 20 minmedium

The app's metrics are not in Prometheus

The web team needs the shop app's metrics in Prometheus with the label team="web". Yesterday a colleague added a job and said it was done — yet there is no data. Finish the job without exposing the metrics to the outside.

Situation

This machine runs a shop: the lab-app application behind nginx, the site is http://shop.lab.test/. The office Prometheus runs here too: every 5 seconds it scrapes its own metrics (the prometheus job) and the machine's (the node job).

The application serves its metrics in the Prometheus format. The web team wants to see them in Prometheus with the label team="web" — its graphs and queries are built on that label. Yesterday a colleague took this on and wrote before leaving: "Added the job, reloaded Prometheus." Yet promtool query instant http://localhost:9090 'up{team="web"}' prints nothing.

There is no browser to the machine: queries — promtool query instant http://localhost:9090 '<query>', the Prometheus API — curl -s localhost:9090/api/v1/… and jq. sudo works without a password.

Task

  1. Prometheus scrapes the metrics of the shop application itself: its target has the label team="web", the target is up, and promtool query instant http://localhost:9090 'labapp_build_info{team="web"}' prints a series.
  2. The shop site works as before: http://shop.lab.test/ answers 200, and http://shop.lab.test/metrics answers 403.
  3. The setting lives in /etc/prometheus/prometheus.yml: promtool check config passes, Prometheus runs with what the file says; the prometheus and node jobs are in place and working.

Constraints

  • The application's metrics are not served to the outside: the shop's nginx closes /metrics on purpose — do not change its configuration.
  • Do not change the lab-app application or its service.

Half a minute after the metrics start flowing, the web team will see its requests by response code like this: promtool query instant http://localhost:9090 'sum by (code) (rate(labapp_http_requests_total{team="web"}[1m]))'

Lab · on your own

No commands are given in this lab: type them in the terminal yourself. Goals are checked on the machine after every command.

Goals

0 of 3
  • Prometheus scrapes the shop app's metrics — the target with the label team="web" is up, and labapp_* series with this label exist — not done yet
  • The shop site works as before — / answers 200, and /metrics stays closed to the outside (403) — not done yet
  • The setting lives in prometheus.yml; promtool check config passes, Prometheus runs with what the file says; the prometheus and node jobs are in place — not done yet
Ctrl+Enter
Starts the machine node1 · Ubuntu 24.04

The machine is starting

Hints

0 of 3

Lab goals

0 of 3
  • Prometheus scrapes the shop app's metrics — the target with the label team="web" is up, and labapp_* series with this label exist — not done yet
  • The shop site works as before — / answers 200, and /metrics stays closed to the outside (403) — not done yet
  • The setting lives in prometheus.yml; promtool check config passes, Prometheus runs with what the file says; the prometheus and node jobs are in place — not done yet
node1 Ubuntu 24.04

Lab goals

0 of 3
  • Prometheus scrapes the shop app's metrics — the target with the label team="web" is up, and labapp_* series with this label exist — not done yet
  • The shop site works as before — / answers 200, and /metrics stays closed to the outside (403) — not done yet
  • The setting lives in prometheus.yml; promtool check config passes, Prometheus runs with what the file says; the prometheus and node jobs are in place — not done yet
Loading…