Goal
Turn raw access logs into the numbers a reliability review asks for. You generate a day of web traffic with a short outage, measure availability and the 95th / 99th latency percentile, set an SLO, calculate how much of the error budget was burned, and write a burn-rate alert rule with a runbook link instead of a noisy "5xx > 0" alert.
Before you start
- Make the folder
~/slo-lab. Generate a log of 100,000 requests (one day) with a 20-minute outage at 14:00:gen.pyimport random random.seed(7) with open("access.log", "w") as f: for i in range(100_000): sec = int(i * 86400 / 100_000) hh, mm, ss = sec // 3600, sec % 3600 // 60, sec % 60 outage = 14 * 3600 <= sec < 14 * 3600 + 1200 status = 503 if outage and random.random() < 0.6 else (500 if random.random() < 0.002 else 200) ms = int(random.lognormvariate(4.6, 0.5)) + (900 if outage else 0) f.write(f"2026-11-14T{hh:02d}:{mm:02d}:{ss:02d} GET /api/orders {status} {ms}\n")
Tasks
Tick a task when it is done. Only your browser remembers it.
- Count all requests and the bad ones (status 5xx). Calculate availability in percent.
- Calculate the p95 and p99 latency for the whole day and for the outage window only.
- Define two SLOs for this API: availability 99.5 % over 30 days, and 99 % of requests faster than 500 ms.
- Error budget: how many bad requests does 99.5 % allow for this day? What share of today's budget was burned?
- Find the worst 5-minute window and its error rate. What is the burn rate (error rate ÷ allowed error rate)?
- Write a Prometheus alert that fires on a fast burn (burn rate above 14.4 over 1 hour and 5 minutes), with
severity: pageand arunbook_url. - Write down which two of the five alert anti-patterns from the chapter this alert avoids.
Check your work
awk '{n++} $4>=500{b++} END{printf "requests=%d bad=%d availability=%.3f%%\n", n, b, 100*(n-b)/n}' access.log
cat slo.md
grep -c "runbook_url" burn-alert.yml- 100,000 requests and about 1,000 bad ones; availability about 99.0 % — below the SLO for this day.
- The daily p95 is about 240 ms (fine), but the daily p99 is near 1 second: the 20-minute outage alone breaks the latency SLO. During the outage p95 and p99 are above 1,100 ms.
- The worst 5-minute window (14:15) has an error rate near 62 %, a burn rate of about 124.
burn-alert.ymlhas one alert with two windows and a runbook link.
Hints
Show the hints
- awk: column 4 is the status, column 5 the time in ms.
- Percentiles:
sort -nthe times and take the line at 95 % / 99 % of the count. - Allowed error rate = 1 − 0.995 = 0.005. Budget for the day = requests × 0.005.
- 5-minute window: the first 15 characters of the time stamp (
2026-11-14T14:0) group by 10 minutes; for 5 minutes usesubstr($1,12,2)hour andint(substr($1,15,2)/5). - Google SRE multi-window rule: page when burn rate > 14.4 for 1 h and for 5 min (2 % of a 30-day budget in one hour).
Solution
Show the solution
- Availability.
awk '{n++} $4>=500{b++} END{printf "requests=%d bad=%d availability=%.3f%%\n", n, b, 100*(n-b)/n}' access.log - Percentiles (whole day, then the outage window 14:00–14:19).
- Error budget and the worst window.
awk '{n++} $4>=500{b++} END{allow=n*0.005; printf "budget=%d used=%d burned=%.0f%% of today\n", allow, b, 100*b/allow}' access.log awk '{w=substr($1,12,2)":"sprintf("%02d",int(substr($1,15,2)/5)*5); n[w]++} $4>=500{b[w]++} END{for(w in n) printf "%s %.3f\n", w, b[w]/n[w]}' access.log | sort -k2 -nr | head -1Burn rate of the worst window = its error rate ÷ 0.005, here 0.618 ÷ 0.005 ≈ 124: at that speed the whole 30-day budget is gone in under 6 hours. The day used about 1,025 bad requests of a budget of 500: 205 %.
- The alert.burn-alert.yml
groups: - name: slo-orders-api rules: - alert: OrdersApiErrorBudgetFastBurn expr: | (sum(rate(http_requests_total{job="orders",code=~"5.."}[1h])) / sum(rate(http_requests_total{job="orders"}[1h]))) > (14.4 * 0.005) and (sum(rate(http_requests_total{job="orders",code=~"5.."}[5m])) / sum(rate(http_requests_total{job="orders"}[5m]))) > (14.4 * 0.005) labels: severity: page annotations: summary: "Orders API burns its 30-day error budget 14x too fast" runbook_url: "https://wiki.example.com/runbooks/orders-api-errors" - The SLO note.slo.md
SLO orders API (30 days): availability 99.5 %, latency 99 % < 500 ms. Today: 99.0 % available, p99 974 ms -> 205 % of the daily error budget burned (outage 14:00-14:20). Alert: multi-window burn rate (1h + 5m) instead of "any 5xx": it pages on real user impact, not on single errors (anti-pattern: alert on causes, not symptoms), and every page has a runbook link (anti-pattern: alerts nobody knows how to handle).
My notes
No notes yet.