Observability
Production rules
Alerts that wake someone up only when it matters.
A dashboard needs someone looking at it. An alert looks for you: when a number crosses a line for long enough, it sends a message to Slack, email or a pager. The art is to alert on what users feel (errors, slowness, being down), not on every technical blip, or people learn to ignore the alerts.
Generate the rules
File("alerts.yml").writeText(ProductionRules.yaml(
service = "shop-api", errorRatio = 0.05, p95Seconds = 1.0, inFlight = 200, forDuration = "5m"))Or fetch them from a running service: GET /_dashboard/alerts.yml (see Dashboard). Put the file next to prometheus.yml and list it under rule_files:
# prometheus.yml
rule_files: ["alerts.yml"]
alerting:
alertmanagers: [{ static_configs: [{ targets: ["alertmanager:9093"] }] }]The four alerts
| Alert | Fires when | Why it matters | Severity |
|---|---|---|---|
ShopApiHighErrorRate | more than 5% of requests are 5xx for 5 minutes | users are getting errors | page |
ShopApiSlowRequests | p95 latency above 1 s for 5 minutes | the site feels broken even though it "works" | ticket |
ShopApiDown | Prometheus cannot scrape the service for 2 minutes | the process is gone or unreachable | page |
ShopApiRequestsPilingUp | over 200 requests in flight for 2 minutes | requests arrive faster than they finish: a stuck dependency or exhausted pool | ticket |
The for: 5m part means the condition must hold for five minutes, so a single bad second does not wake anyone. ShopApiDown expects your Prometheus job name to equal the service name.
Route alerts to people (Alertmanager)
route:
receiver: slack
routes:
- matchers: [severity="page"]
receiver: pagerduty
receivers:
- name: slack
slack_configs: [{ channel: "#alerts", api_url: "https://hooks.slack.com/services/..." }]
- name: pagerduty
pagerduty_configs: [{ routing_key: "..." }]Make them yours
These are starting points. Tune the numbers to your normal traffic (a service that always has 2% errors needs a different line), and add alerts for what your business needs: payments failing, the outbox dead-letter count above zero, the queue backlog growing.
- alert: OutboxDeadLetters
expr: outbox_dead_total > 0
for: 1m
annotations: { summary: "Messages gave up: look at outbox.deadLetters()" }(Export outbox_dead_total with a gauge on outbox.deadCount(), see Metrics.)
Good alerts
- Every alert should need a human to do something. If it fires and nobody acts, delete it.
- Write down what to do (a runbook link in the annotation).
- Page for user-visible, urgent problems; ticket (a Slack message) for the rest.
- Alert on symptoms (errors, latency) rather than causes (CPU at 80%): high CPU with happy users is not an emergency.