How do you write an availability SLI recording rule in Prometheus?
IntermediateConceptSLIs, SLOs & SLAs
Answer
Record the error ratio (bad / total) per window, so alerts and dashboards reuse it cheaply:
groups:
- name: checkout-sli
rules:
- record: slo:sli_error:ratio_rate5m
labels:
slo: checkout-availability
expr: |
sum(rate(http_requests_total{job="checkout",code=~"5.."}[5m]))
/
sum(rate(http_requests_total{job="checkout"}[5m]))
Repeat for 30m, 1h, 2h, 6h, 1d and 3d windows. The naming convention level:metric:operations makes it obvious what the series is.
More on SLIs, SLOs & SLAs
Define SLI, SLO and SLA with an example of each.BeginnerWhy should the SLA be looser than the SLO?BeginnerWhy are SLIs best expressed as a ratio of good events to valid events?IntermediateWhat is the difference between request-based and time-based (window-based) SLIs?AdvancedWhere should you measure an SLI, and what are the trade-offs?AdvancedWhat types of SLIs exist beyond availability and latency?Intermediate