Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
The quick answer
groups:
- name: slo-api
rules:
- record: job:slo_errors:ratio_rate5m
expr: sum(rate(http_requests_total{job="api",code=~"5.."}[5m])) / sum(rate(http_requests_total{job="api"}[5m]))
- record: job:slo_errors:ratio_rate1h
expr: sum(rate(http_requests_total{job="api",code=~"5.."}[1h])) / sum(rate(http_requests_total{job="api"}[1h]))
- alert: ApiErrorBudgetFastBurn
expr: job:slo_errors:ratio_rate1h > (14.4 * 0.001) and job:slo_errors:ratio_rate5m > (14.4 * 0.001)
labels:
severity: page
annotations:
summary: "API burns its 30-day error budget 14x too fast"
runbook_url: "https://wiki.example.com/runbooks/api-errors"promtool check rules slo-api.ymlStep by step
- Pick the SLI (what you measure) from the user's view — share of good requests (status not 5xx), share of requests faster than 300 ms, or share of successful jobs.
- Pick the target and window — for example 99.9 % over 30 days. Start a bit below what you reach today; raise it later. Not every service needs three nines.
- Do the budget maths — 30 days = 43,200 minutes. 99.9 % allows 43.2 minutes of full outage, or 0.1 % of requests failing. 99.5 % allows 3.6 hours.
- Record the error ratio (quick answer) — recording rules make the queries cheap and the alerts readable.
- Alert on burn rate, not on single errors — burn rate 1 = the budget lasts exactly 30 days. 14.4 = 2 % of the monthly budget gone in one hour → page now. Both a long (1h) and a short (5m) window must be over the limit, so the alert stops soon after the problem is fixed. Add a slower alert for a ticket: burn rate 6 over 6h (and 30m), or 1 over 3 days.
- Show the remaining budget in Grafana:
1 - (
sum(increase(http_requests_total{job="api",code=~"5.."}[30d]))
/
sum(increase(http_requests_total{job="api"}[30d]))
) / 0.0011 = full budget, 0 = used up, negative = SLO missed.
- Agree on the policy — write down what happens when the budget is gone (for example: only fixes and reliability work until it recovers). Without this the SLO is just a number.
- Tools — generators such as Sloth or Pyrra write all these rules from a short SLO file.
Check that it worked
promtool check rules reports SUCCESS; in Prometheus job:slo_errors:ratio_rate5m returns a value; a short error test in staging (return 500 for a few minutes) fires ApiErrorBudgetFastBurn and it clears after the fix.
Common problems
| Problem | Cause | Fix |
|---|---|---|
| Too many pages | Alerting on every error spike. | Burn-rate alerts with two windows. |
| SLO always 100 % | The metric misses failures (timeouts at the load balancer). | Measure at the edge (load balancer / ingress) too. |
| Division by zero at night | No traffic → empty ratio. | Normal; alert only when traffic exists (and sum(rate(...)) > 0). |
| Health checks count as traffic | /healthz in the metric. | Exclude them with a label filter. |
| Nobody cares when the budget is gone | No agreed policy. | Write the error budget policy with the product owner. |
| 30-day queries are slow | increase(...[30d]) over raw data. | Recording rules; longer retention or Thanos/Mimir. |
Go further
- Command pages: promtool, amtool.
- Next how-tos: Write a runbook for on-call, Send alerts to Slack or email, Load test an API with k6, Monitor a Linux server with Prometheus.
- Learn it: Observability tools at work — alerts, DevOps map — DORA metrics. Full guide: Prometheus.
1How much downtime does a 99.9 % SLO over 30 days allow?
About 43 minutes (0.1 % of 43,200 minutes), or the same share of failed requests.
2Why alert on burn rate instead of every error?
Burn rate shows how fast the monthly budget is being used, so you page only for problems that really threaten the SLO.