Skip to main content

slo-kit

Stop hand-rolling SLO alerts. Define SLOs as code and get correct multi-window burn-rate Prometheus alerts for free.

CI PyPI Python Docs License

slo-kit turns raw Prometheus / OpenTelemetry metrics into:

  • SLO definitions as code — SLI query + target + rolling window, in YAML or Python.
  • Live error-budget & burn-rate tracking — consumed, remaining, and time-to-exhaustion.
  • Correct multi-window / multi-burn-rate Prometheus alert rules — per the Google SRE workbook.

SLO math (error budgets, multi-window multi-burn-rate alerting) is subtle and commonly implemented incorrectly. slo-kit packages it correctly and reusably, so you define reliability targets and get paged on budget burn without hand-rolling brittle PromQL.

Install

pip install slokit-sre        # requires Python 3.11+
# or
docker run --rm ghcr.io/akaashhazarika/slo-kit:latest --help

The PyPI distribution is slokit-sre; the import package (slo_kit) and the slo-kit CLI command are unchanged.

Quickstart (< 5 minutes)

1. Define an SLO (checkout_slo.yaml):

apiVersion: slo-kit/v1
name: checkout-availability
service: checkout
description: Checkout API availability
objective: 0.999          # three nines
window: 30d               # rolling 30-day window
sli:
  # {window} is substituted per alert/budget window
  good_query: 'sum(rate(http_requests_total{job="checkout",code!~"5.."}[{window}]))'
  total_query: 'sum(rate(http_requests_total{job="checkout"}[{window}]))'
labels:
  team: payments

2. Validate it:

slo-kit validate checkout_slo.yaml

3. Check live budget & burn rate:

slo-kit status checkout_slo.yaml --source http://localhost:9090

4. Generate correct multi-window burn-rate alerts:

slo-kit gen-alerts checkout_slo.yaml > checkout_rules.yaml

5. Gate deploys on remaining budget (CI):

slo-kit gate checkout_slo.yaml --source http://localhost:9090 --min-budget 0.1
# exits non-zero when < 10% budget remains

From Python

from slo_kit import load_spec, evaluate_status, generate_rules_yaml
from slo_kit import PrometheusSource

slo = load_spec("checkout_slo.yaml")
source = PrometheusSource("http://localhost:9090")

status = evaluate_status(slo, source)
print(f"budget remaining: {status.budget_remaining_pct:.1%}")
print(f"1h burn rate:     {status.burn_rate('1h'):.2f}x")

print(generate_rules_yaml(slo))   # Prometheus alerting rules

Why multi-window multi-burn-rate?

Alerting on a single window forces a bad trade-off: short windows page fast but cry wolf; long windows are stable but slow to fire and slow to reset. The SRE workbook fix is to require two windows at once — a long window that measures how much budget is burning, and a short window (≈1/12 of it) that confirms the burn is still happening right now:

severity long short burn rate budget burned before firing (30d)
page 1h 5m 14.4× 2%
page 6h 30m 5%
ticket 24h 2h 10%

slo-kit implements this in alerts/multiwindow.py and emits the equivalent Prometheus rules from alerts/prometheus_rules.py — validated against an explicit truth table and golden files.

Core concepts

  • SLIgood_events / total_events from a metric query.
  • SLO target — e.g. 0.999 over a rolling window (e.g. 30d).
  • Error budget — allowed failures = (1 - target) × total; track consumed, remaining, remaining %, and time-to-exhaustion.
  • Burn rateobserved_error_rate / (1 - target); a burn rate of 1 exactly exhausts the budget over the window, >1 is too fast.
  • Multi-window multi-burn-rate alerts — fast + slow burn condition sets to balance fast detection against low false positives.

See the documentation for concepts, the full API, and examples.

Development

pip install -e ".[dev]"
ruff check . && ruff format --check .
mypy src/slo_kit
pytest --cov=slo_kit --cov-report=term-missing

License

Apache-2.0.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slokit_sre-1.0.1.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

slokit_sre-1.0.1-py3-none-any.whl (30.2 kB view details)

Uploaded Python 3

File details

Details for the file slokit_sre-1.0.1.tar.gz.

File metadata

  • Download URL: slokit_sre-1.0.1.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for slokit_sre-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ee83281de3bb457d2ad81a1a25394930dca39ce290b6b68a5c7773f2558459b2
MD5 790a551b9173d427a340a4b452422607
BLAKE2b-256 0a456e93b36976d3bfc6102ca654b9db5c484a618012712c324845aaf8996dc3

See more details on using hashes here.

Provenance

The following attestation bundles were made for slokit_sre-1.0.1.tar.gz:

Publisher: release.yml on akaashhazarika/slo-kit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slokit_sre-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: slokit_sre-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 30.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for slokit_sre-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6bed29de2183bb9f7cac0b5bc2c47130edd668f49fe1cd817501bf7b3512c047
MD5 257c6c4a77c395109823c29a28fcc937
BLAKE2b-256 c2be32c3456efb91025ba95610e7f07b716a3191a8fd1b5d8be2242d1948ae7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for slokit_sre-1.0.1-py3-none-any.whl:

Publisher: release.yml on akaashhazarika/slo-kit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page