Skip to main content

Data and monitoring · Advanced · 25 min

Alert on SLO burn rate with multi-window alerts in Prometheus

By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · Prometheus 3.16.0 (promtool)

You will have Prometheus 3.16 recording rules for a payments API's error ratio over five windows, a fast-burn page and a slow-burn ticket from the multi-window, multi-burn-rate method, and promtool unit tests proving which incidents page, which open a ticket and which stay quiet.

On this page

An availability SLO of 99.9% gives the payments API an error budget of 0.1% of requests. The question an alert has to answer is not "are there errors?" (there always are a few) but "at this rate, will we spend the budget before the window ends?". That rate is the burn rate: the error ratio you see divided by the ratio the SLO allows. A burn rate of 1 spends the budget exactly over the window. A burn rate of 14.4 spends a 30-day budget in about two days.

A single threshold on a single window is a poor alert. A 5-minute window pages for every short blip; a 6-hour window takes far too long to notice a real outage and keeps firing for hours after it is fixed. The fix, described in the alerting chapter of Google's SRE workbook, is to alert on several burn rates, each checked over a long window and a short one at the same time. The long window says "this has cost a real share of the budget". The short window says "and it is still happening now", so the alert clears soon after recovery.

In this tutorial you write that scheme by hand for the payments API from Define SLOs and error budgets for a service: recording rules for the error ratio over 5 minutes, 30 minutes, 1 hour, 6 hours and 3 days, a page for fast burns and a ticket for slow ones. Then you prove the rules with promtool test rules, which replays made-up traffic through them: a short blip must not page, a sustained outage must page within minutes, and a slow leak must open a ticket. You do not need the payments API running to do any of that. Last, you load the rules into Prometheus.

Step 1 · Work out the thresholds

Every threshold in this tutorial comes from two numbers: the SLO and the length of its window. The workbook's table is built for a 30-day window and picks three budget shares worth acting on:

  • Page if 2% of the budget goes in 1 hour. That is a burn rate of 14.4.
  • Page if 5% goes in 6 hours. That is a burn rate of 6.
  • Open a ticket if 10% goes in 3 days. That is a burn rate of 1.

Each long window gets a short window one twelfth its length (5 minutes for 1 hour, 30 minutes for 6 hours, 6 hours for 3 days). Make a folder for the work and let awk do the arithmetic, so you can rerun it with your own SLO:

Bash
mkdir -p ~/slo-burn-demo
cd ~/slo-burn-demo
awk 'BEGIN {
  budget = 1 - 0.999
  window_hours = 30 * 24
  printf "error budget: %.2f%% of requests\n", budget * 100
  printf "page,   1h at 14.4x: error ratio above %.4f, spends %.0f%% of the budget\n", 14.4 * budget, 100 * 14.4 * 1 / window_hours
  printf "page,   6h at 6x:    error ratio above %.4f, spends %.0f%% of the budget\n", 6 * budget, 100 * 6 * 6 / window_hours
  printf "ticket, 3d at 1x:    error ratio above %.4f, spends %.0f%% of the budget\n", 1 * budget, 100 * 1 * 72 / window_hours
  printf "at 14.4x the whole budget is gone in %.1f days\n", 30 / 14.4
}' | tee thresholds.txt
A chart over three hours: a five-minute blip and a sixty-minute outage. The 5m ratio crosses 1.44% for both, the 1h ratio only for the outage, and the page fires only while both are above
The 1h and 5m pair: the long window ignores the blip, the short window ends the page soon after recovery.

Check it worked

~/slo-burn-demo/thresholds.txt has five lines. The thresholds read 0.0144, 0.0060 and 0.0010, the shares read 2%, 5% and 10%, and the last line says 2.1 days. If your SLO uses the 28-day window from the SLO tutorial, the same factors spend a slightly bigger share of a slightly smaller budget (14.4 for 1 hour is 2.1% of 28 days). That is close enough to keep the workbook's numbers.

Step 2 · Record the error ratio over five windows

The alerts compare error ratios over five windows. Working each one out from raw counters inside the alert would repeat a lot of work on every evaluation, so record each ratio once as its own series. The names follow the level:metric:operations pattern: aggregated by job, the errors-per-request ratio, as a rate over the window.

Each rule divides the rate of 5xx responses by the rate of all responses. Both rates use the same window and the same samples, so the ratio is the share of requests that failed in that window. 4xx responses are left out on purpose: a customer typing the wrong card number is not the API failing.

Bash
cd ~/slo-burn-demo
cat > payments-burn-rules.yml <<'YAML'
groups:
  - name: payments-api-error-ratios
    rules:
      - record: job:slo_errors_per_request:ratio_rate5m
        expr: |
          sum by (job) (rate(http_requests_total{job="payments-api", code=~"5.."}[5m]))
            / sum by (job) (rate(http_requests_total{job="payments-api"}[5m]))
      - record: job:slo_errors_per_request:ratio_rate30m
        expr: |
          sum by (job) (rate(http_requests_total{job="payments-api", code=~"5.."}[30m]))
            / sum by (job) (rate(http_requests_total{job="payments-api"}[30m]))
      - record: job:slo_errors_per_request:ratio_rate1h
        expr: |
          sum by (job) (rate(http_requests_total{job="payments-api", code=~"5.."}[1h]))
            / sum by (job) (rate(http_requests_total{job="payments-api"}[1h]))
      - record: job:slo_errors_per_request:ratio_rate6h
        expr: |
          sum by (job) (rate(http_requests_total{job="payments-api", code=~"5.."}[6h]))
            / sum by (job) (rate(http_requests_total{job="payments-api"}[6h]))
      - record: job:slo_errors_per_request:ratio_rate3d
        expr: |
          sum by (job) (rate(http_requests_total{job="payments-api", code=~"5.."}[3d]))
            / sum by (job) (rate(http_requests_total{job="payments-api"}[3d]))
YAML
promtool check rules payments-burn-rules.yml

The [3d] rule reads three days of raw samples every time it runs. For one service that is fine. With many services on one Prometheus, move the 6-hour and 3-day rules into a group of their own with a longer interval: (for example 5m), which the group-level field allows.

Check it worked

promtool prints Checking payments-burn-rules.yml and then SUCCESS: 5 rules found. A typo in PromQL makes it print the rule and the parse error instead.

Step 3 · Write the page and the ticket

Add a second group to the same file with two alerts. Rewrite the whole file so it is the same for everyone, whatever you did to it before:

Bash
cd ~/slo-burn-demo
cat > payments-burn-rules.yml <<'YAML'
groups:
  - name: payments-api-error-ratios
    rules:
      - record: job:slo_errors_per_request:ratio_rate5m
        expr: |
          sum by (job) (rate(http_requests_total{job="payments-api", code=~"5.."}[5m]))
            / sum by (job) (rate(http_requests_total{job="payments-api"}[5m]))
      - record: job:slo_errors_per_request:ratio_rate30m
        expr: |
          sum by (job) (rate(http_requests_total{job="payments-api", code=~"5.."}[30m]))
            / sum by (job) (rate(http_requests_total{job="payments-api"}[30m]))
      - record: job:slo_errors_per_request:ratio_rate1h
        expr: |
          sum by (job) (rate(http_requests_total{job="payments-api", code=~"5.."}[1h]))
            / sum by (job) (rate(http_requests_total{job="payments-api"}[1h]))
      - record: job:slo_errors_per_request:ratio_rate6h
        expr: |
          sum by (job) (rate(http_requests_total{job="payments-api", code=~"5.."}[6h]))
            / sum by (job) (rate(http_requests_total{job="payments-api"}[6h]))
      - record: job:slo_errors_per_request:ratio_rate3d
        expr: |
          sum by (job) (rate(http_requests_total{job="payments-api", code=~"5.."}[3d]))
            / sum by (job) (rate(http_requests_total{job="payments-api"}[3d]))

  - name: payments-api-burn-alerts
    rules:
      - alert: PaymentsApiErrorBudgetBurn
        expr: |
          (
              job:slo_errors_per_request:ratio_rate1h{job="payments-api"} > (14.4 * 0.001)
            and
              job:slo_errors_per_request:ratio_rate5m{job="payments-api"} > (14.4 * 0.001)
          )
          or
          (
              job:slo_errors_per_request:ratio_rate6h{job="payments-api"} > (6 * 0.001)
            and
              job:slo_errors_per_request:ratio_rate30m{job="payments-api"} > (6 * 0.001)
          )
        labels:
          severity: page
        annotations:
          summary: "payments-api is burning its error budget fast"
      - alert: PaymentsApiErrorBudgetSlowBurn
        expr: |
          job:slo_errors_per_request:ratio_rate3d{job="payments-api"} > (1 * 0.001)
            and
          job:slo_errors_per_request:ratio_rate6h{job="payments-api"} > (1 * 0.001)
        labels:
          severity: ticket
        annotations:
          summary: "payments-api is spending its error budget faster than the SLO allows"
YAML
promtool check rules payments-burn-rules.yml

How the expressions read:

  • ratio_rate1h > (14.4 * 0.001) keeps the series only while the 1-hour ratio is above 1.44%. Writing the threshold as burn rate times budget keeps the link to the table visible; change 0.001 if your SLO changes.
  • and keeps a result only when the other side has a series with the same labels. Both sides here carry only job="payments-api", so the pair is true only while both windows are above the line.
  • or joins the two page conditions. Either pair is enough to page, and you get one alert, not two.
  • There is no for:. The long window already ignores short spikes, and a for: would only delay a page for an outage that is spending 2% of the budget an hour.
  • severity is what Alertmanager routes on: page goes to whoever is on call, ticket goes to a queue someone reads in working hours. Send alerts with Prometheus Alertmanager shows routing by label.

Check it worked

promtool check rules now reports SUCCESS: 7 rules found: five recording rules and two alerts.

Step 4 · Prove a short blip does not page

A test file names the rule files, feeds them made-up series and states which alerts should be firing at given times. Series values use promtool's expanding notation: 0+1000x4320 means start at 0 and add 1,000 per step, 4,320 times; 500x60 means stay at 500 for 60 steps. With a step of one minute, 4,320 steps is three days.

This test gives the API three clean days at 1,000 requests a minute, so every window, including the 3-day one, has real history. Then 10% of requests fail for five minutes (100 errors and 900 successes a minute), and everything is healthy again:

Bash
cd ~/slo-burn-demo
cat > test-blip.yml <<'YAML'
rule_files:
  - payments-burn-rules.yml

evaluation_interval: 1m

tests:
  - name: a five-minute blip at 10% errors does not page
    interval: 1m
    input_series:
      - series: 'http_requests_total{job="payments-api", code="200"}'
        values: '0+1000x4320 4320900+900x4 4325500+1000x60'
      - series: 'http_requests_total{job="payments-api", code="500"}'
        values: '0x4320 100+100x4 500x60'
    alert_rule_test:
      - eval_time: 3d5m
        alertname: PaymentsApiErrorBudgetBurn
        exp_alerts: []
      - eval_time: 3d30m
        alertname: PaymentsApiErrorBudgetBurn
        exp_alerts: []
      - eval_time: 3d30m
        alertname: PaymentsApiErrorBudgetSlowBurn
        exp_alerts: []
YAML
promtool test rules test-blip.yml

At 3d5m, the end of the blip, the 5-minute ratio is about 10%, far above 1.44%. The 1-hour ratio is 500 errors in about 60,000 requests, roughly 0.83%, so the pair is false. exp_alerts: [] says nothing may be firing. The other checks confirm the blip opens no ticket either: the 3-day ratio stays near 0.01%.

Check it worked

The output starts with Unit Testing: and the file name, and ends with SUCCESS. It takes a few seconds, because promtool evaluates every rule once a minute across the whole three days.

Step 5 · See why the long window is there

To see what the 1-hour window buys you, write a naive alert that looks only at the 5-minute ratio, and run the same blip against it:

Bash
cd ~/slo-burn-demo
cat > naive-alert.yml <<'YAML'
groups:
  - name: naive-short-window-alert
    rules:
      - alert: NaiveFiveMinutePage
        expr: job:slo_errors_per_request:ratio_rate5m{job="payments-api"} > (14.4 * 0.001)
        labels:
          severity: page
YAML
cat > test-naive.yml <<'YAML'
rule_files:
  - payments-burn-rules.yml
  - naive-alert.yml

evaluation_interval: 1m

tests:
  - name: the same five-minute blip against a short-window-only alert
    interval: 1m
    input_series:
      - series: 'http_requests_total{job="payments-api", code="200"}'
        values: '0+1000x4320 4320900+900x4 4325500+1000x60'
      - series: 'http_requests_total{job="payments-api", code="500"}'
        values: '0x4320 100+100x4 500x60'
    alert_rule_test:
      - eval_time: 3d5m
        alertname: NaiveFiveMinutePage
        exp_alerts: []
YAML
promtool test rules test-naive.yml || echo "test-naive.yml failed, as expected"

Check it worked

This time promtool prints FAILED and something like the alert name and the time 3d5m, with an empty exp: list next to a got: list holding NaiveFiveMinutePage with job="payments-api". The last line is test-naive.yml failed, as expected. A five-minute blip that spent about 1% of the month's budget would have woken someone. Delete the two naive files once you have seen it:

Bash
rm ~/slo-burn-demo/naive-alert.yml ~/slo-burn-demo/test-naive.yml

Step 6 · Prove an outage pages within minutes

Now a real incident: after the same three clean days, 20% of requests fail for an hour (200 errors a minute), then the API recovers for 40 minutes. The test checks three moments: three minutes in, six minutes in, and 40 minutes after recovery.

Bash
cd ~/slo-burn-demo
cat > test-outage.yml <<'YAML'
rule_files:
  - payments-burn-rules.yml

evaluation_interval: 1m

tests:
  - name: a 60-minute outage at 20% errors pages within minutes and clears after
    interval: 1m
    input_series:
      - series: 'http_requests_total{job="payments-api", code="200"}'
        values: '0+1000x4320 4320800+800x59 4369000+1000x40'
      - series: 'http_requests_total{job="payments-api", code="500"}'
        values: '0x4320 200+200x59 12000x40'
    alert_rule_test:
      - eval_time: 3d3m
        alertname: PaymentsApiErrorBudgetBurn
        exp_alerts: []
      - eval_time: 3d6m
        alertname: PaymentsApiErrorBudgetBurn
        exp_alerts:
          - exp_labels:
              job: payments-api
              severity: page
            exp_annotations:
              summary: "payments-api is burning its error budget fast"
      - eval_time: 3d1h40m
        alertname: PaymentsApiErrorBudgetBurn
        exp_alerts: []
YAML
promtool test rules test-outage.yml

Three minutes in, the 1-hour window holds about 600 errors in 60,000 requests, 1%, still under 1.44%. By six minutes it holds about 1,200, 2%, and the page fires with exactly the labels and summary in exp_alerts. Forty minutes after recovery the 1-hour and 6-hour ratios are still high, but the 5-minute and 30-minute ratios are back to zero, so both pairs are false and the page has cleared. That is the short window's job. With the 1-hour pair alone, the page would clear five minutes after recovery; the 6-hour pair keeps it up to about 30 minutes, which is why the test checks at 40.

Three panels. A blip of 10% errors for 5 minutes gives no page and no ticket. An outage of 20% errors for 60 minutes pages after about 5 minutes and clears within 30 minutes of recovery. A slow leak of 0.3% errors never pages but opens a ticket after about a day
The three test scenarios and the outcome each test asserts.

Check it worked

The output starts with Unit Testing: and the file name, and ends with SUCCESS. To see a failure message, change 3d6m to 3d3m in the second check and rerun: promtool shows the empty got: list next to the alert it expected. Change it back afterwards.

Step 7 · Prove a slow leak opens a ticket

The hardest problem to notice is the small one that never stops: a bad deploy that fails 3 requests in every 1,000. Nobody's phone should ring for 0.3% errors, but at three times the allowed rate it would spend the month's budget in ten days. This test runs the leak for 30 hours after the clean history:

Bash
cd ~/slo-burn-demo
cat > test-leak.yml <<'YAML'
rule_files:
  - payments-burn-rules.yml

evaluation_interval: 1m

tests:
  - name: a slow leak at 0.3% errors opens a ticket but never pages
    interval: 1m
    input_series:
      - series: 'http_requests_total{job="payments-api", code="200"}'
        values: '0+1000x4320 4320997+997x1800'
      - series: 'http_requests_total{job="payments-api", code="500"}'
        values: '0x4320 3+3x1800'
    alert_rule_test:
      - eval_time: 3d12h
        alertname: PaymentsApiErrorBudgetSlowBurn
        exp_alerts: []
      - eval_time: 4d6h
        alertname: PaymentsApiErrorBudgetSlowBurn
        exp_alerts:
          - exp_labels:
              job: payments-api
              severity: ticket
            exp_annotations:
              summary: "payments-api is spending its error budget faster than the SLO allows"
      - eval_time: 4d6h
        alertname: PaymentsApiErrorBudgetBurn
        exp_alerts: []
YAML
promtool test rules test-leak.yml

After 12 hours the 6-hour ratio is 0.3%, above the 0.1% line, but the 3-day window still holds two and a half clean days, so its ratio is about 0.05% and there is no ticket. The 3-day ratio crosses 0.1% after about a day of leaking; at 30 hours it is about 0.125% and the ticket is open. The page never fires, because 0.3% is far below both page lines.

Check it worked

The output ends in SUCCESS, after about ten seconds. Run all three tests together, as you would in CI after any change to the rules:

Bash
cd ~/slo-burn-demo
promtool test rules test-blip.yml test-outage.yml test-leak.yml

Each file gets its own Unit Testing: line followed by SUCCESS. If any fails, promtool exits non-zero, which is what makes it useful in a pipeline.

Step 8 · Load the rules into Prometheus

Copy the rules file into Prometheus's rules folder. Only the rules go there; the test files stay with your code:

Bash
sudo install -d -o root -g root -m 0755 /etc/prometheus/rules
sudo install -o root -g root -m 0644 ~/slo-burn-demo/payments-burn-rules.yml /etc/prometheus/rules/payments-burn-rules.yml

If /etc/prometheus/prometheus.yml has no rule_files: list yet, open it with sudo nano /etc/prometheus/prometheus.yml and add this block at the top level, below global:. If the list is already there (from the SLO or Alertmanager tutorials) and already includes /etc/prometheus/rules/*.yml, that glob covers the new file; if it names individual files instead, add the glob line below to the list:

YAML
rule_files:
  - /etc/prometheus/rules/*.yml

Check the configuration, which also loads every rules file it names, then reload Prometheus:

Bash
promtool check config /etc/prometheus/prometheus.yml
Bash
sudo systemctl reload prometheus

Check it worked

Ask Prometheus which of the new rules it loaded and whether they evaluate cleanly:

Bash
curl -s http://127.0.0.1:9090/api/v1/rules | jq -r '.data.groups[] | select(.name | startswith("payments-api")) | .rules[] | "\(.name) \(.health)"'

You see the five job:slo_errors_per_request:ratio_rate... names and the two alert names, each followed by ok. Right after a reload a rule can show unknown until its first evaluation, which comes within a minute. Once Prometheus scrapes the payments API, query job:slo_errors_per_request:ratio_rate1h in the Prometheus web page to see the live ratio; until then the rules return no series, which is not an error.

Low traffic

The ratios assume enough requests to be meaningful. A regional service that serves a handful of payments a minute overnight, say a shop whose customers are all in one time zone, can see one failed request be 20% of a 5-minute window. The 1-hour window absorbs most of that, but if your quietest hour has only a few dozen requests, read the low-traffic section of the workbook chapter before trusting the page, and consider adding a minimum request rate to the alert.

If you were only trying this out

Remove the rules file and the demo folder, then run promtool check config and reload Prometheus as above:

Bash
sudo rm /etc/prometheus/rules/payments-burn-rules.yml
rm -rf ~/slo-burn-demo

Next steps

Writing these rules by hand once is the best way to understand them. For many services, generate them instead: Sloth turns a short SLO file into the same kind of recording and alerting rules, and Pyrra does the same with a web page showing each SLO's remaining budget. Run your promtool tests against whatever they generate.

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.