Geavanceerd
Zoeken inHow-to-gidsen
Zo zoek je
  • Typ de taak in je eigen woorden (poort vinden, firewall openen, schijf vol) of plak een foutmelding tussen aanhalingstekens.
  • Kies "Snel antwoord" om alleen de commando's te zien, of een gebied om in één vakgebied te blijven.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

How-to 182Observability · Prometheus

How to define an SLO and an error budget

"The site must never be down" is not a goal anyone can reach. An SLO (service level objective) is a clear, measured promise: "99.9 % of API requests succeed over 30 days". The rest — 0.1 % — is the error budget: room for deploys, experiments and bad luck. When the budget burns fast, you get paged; when it is used up, you slow down releases and fix reliability. This how-to defines an SLO, measures it with Prometheus and alerts on the burn rate.

  • 5 Lessen
  • 2 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

182.1

The quick answer

slo-api.yml
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.yml

182.2

Step by step

  1. 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.
  2. 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.
  3. 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.
  4. Record the error ratio (quick answer) — recording rules make the queries cheap and the alerts readable.
  5. 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.
  6. Show the remaining budget in Grafana:
promql
1 - (
  sum(increase(http_requests_total{job="api",code=~"5.."}[30d]))
  /
  sum(increase(http_requests_total{job="api"}[30d]))
) / 0.001

1 = full budget, 0 = used up, negative = SLO missed.

  1. 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.
  2. Tools — generators such as Sloth or Pyrra write all these rules from a short SLO file.

182.3

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.

182.4

Common problems

ProblemCauseFix
Too many pagesAlerting 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 nightNo 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 goneNo agreed policy.Write the error budget policy with the product owner.
30-day queries are slowincrease(...[30d]) over raw data.Recording rules; longer retention or Thanos/Mimir.

182.5

Go further

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.

Alle commando's in dit hoofdstuk