CD9: Monitoring, alerts and scaling

Lesson 2 of 5 · reading 15–25 minutes; practice and project time is on the module page

Prometheus and PromQL

🎯You'll be able to

Collect metrics with Prometheus, find every copy automatically, and write PromQL queries for request rate, error share and percentiles.

🏠The everyday picture

A meter reader visits every house on the list every month and writes down the reading. The reading on its own means little; what matters is the difference since last month. And if a new house is built, it has to be added to the list.

📘What it really is

📝A worked example

Input: in the finished kit, terraform apply -var monitoring=true -var app_count=3, then open http://localhost:9090 and run count(up{job="routerani"} == 1) and, while node tools/load.js http://localhost:8080/api/routes 60 5 runs, the error-share query above.

Expected output: the count is 3, one per copy. The error share is 0 (or shows "no data" until requests arrive). With the starter's static_configs target, the count is 1 however many copies run. That's Project 3 test 3.

🌍Where it's used

📝Case scenario

A team added user_id as a label to their request counter to see which users had errors. Within a week, Prometheus held 4 million series, used all its memory and crashed during an incident, when it was needed most. They removed the label, kept per-user detail in logs and traces, and added a limit that rejects scrapes with too many series.

🖱️Try it

In Prometheus, compare http_requests_total (the raw counter) with rate(http_requests_total[1m]) on a graph while load runs, then stop the load. Success: the raw counter only ever climbs, while the rate rises with the load and falls back towards 0 when it stops.

⚠️Common mistakes

🛠️For your project

Project 3 test 3 runs 3 copies and expects 3 healthy targets, which needs dns_sd_configs (or similar) instead of one fixed address.

✅Quick check

Why use rate() on a counter?

Show the answer

A counter only rises; rate() turns it into a per-second speed and handles restarts.

What does histogram_quantile(0.95, ...) give you?

Show the answer

An estimate of the time 95% of requests finished within.

← PreviousWhat to measure, and how good is good enough
ProLearners Assist