Monitoring and Metrics
Knowing it works.
You can't fix what you can't see. Monitoring means collecting numbers about your system, all the time, so you know it's healthy, and get alerted when it isn't.

- Can't fix what you can't see
- Collect numbers constantly
- Alert when unhealthy
The four golden signals
A good starting point is the four golden signals. Latency, how long requests take. Traffic, how many requests arrive. Errors, how many fail. And saturation, how full your resources are, like CPU, memory, or queue length. Watch these four for every service.
| key | value |
|---|---|
| Latency | how long requests take |
| Traffic | requests per second |
| Errors | how many fail |
| Saturation | how full resources are |
Alerting on error rate
Alerts should fire on symptoms users feel, like a high error rate, not on every small blip. Here we check each minute's error rate against a two percent limit. Run it. Minutes four and five cross the line, so someone gets paged. The single failed request in minute two is ignored.
minutes = [
(1, 1000, 0), (2, 1100, 1), (3, 1050, 4),
(4, 1200, 60), (5, 1150, 90), (6, 1000, 3),
]
LIMIT = 0.02
for minute, total, errors in minutes:
rate = errors / total
flag = " <- ALERT" if rate > LIMIT else ""
print(f"minute {minute}: {rate:.1%} errors{flag}")minute 1: 0.0% errors minute 2: 0.1% errors minute 3: 0.4% errors minute 4: 5.0% errors <- ALERT minute 5: 7.8% errors <- ALERT minute 6: 0.3% errors
Summary
Monitor latency, traffic, errors, and saturation for every service, and alert on symptoms users feel. Next, following a single request through many services.
Key takeaways- Four golden signals
- Alert on symptoms
- Dashboards for each service