Reference library

Observability & SRE

Structured logging, metrics, tracing, health checks, and SLO-friendly instrumentation.

2 matches
Observability & SRE easy

How to Calculate SLO Error Budget in Python

Simulate an SLO error budget by computing allowed downtime from a target availability percentage and mocking monthly incidents.

slo error-budget monitoring
Python
```python
import random


def calculate_error_budget(total_seconds: int, target_availability: float) -> float:
    return (1.0 - target_availability) * total_seconds


def simulate_monthly_availability(seconds_in_month: int, budget_seconds: float) -> float:
    # Mock: randomly consume a fraction of the error budget i…
15 0 Open
Observability & SRE medium

How to Implement an Error Budget Policy in Python

This code implements a mock error budget policy that decides whether to freeze deployments based on a simulated error rate and monthly freeze limits.

error-budget sre deploy-freeze
Python
from datetime import datetime, timedelta

class ErrorBudgetPolicy:
    FREEZE_WINDOW_HOURS = 24
    MAX_FREEZES_PER_MONTH = 3

    def __init__(self, budget_percentage=99.9):
        self.budget_percentage = budget_percentage
        self.freeze_count = 0
        self.last_freeze_start = None
        self.freeze_enabl…
13 0 Open

Browse by section

Each section groups closely related Python snippets.

Observability & SRE — Python code examples

What you will find here

This page collects observability & sre snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.

Samples vs tutorials and challenges

Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.