INNER CODE UNIT · Python

metrics_endpoint

AleksNeStu/ai-real-estate-assistant · apps/api/api/main.py:677

async def metrics_endpoint():
    """
    Prometheus-compatible metrics endpoint (TASK-017).

    Returns application metrics in Prometheus text format.
    """
    from time import time

    metrics = []
    metrics.append("# HELP api_requests_total Total number of API requests")
    metrics.append("# TYPE api_requests_total counter")

    # Get request metrics from app state
    if hasattr(app.state, "metrics"):
        for key, count in app.state.metrics.items():
            method, path = key.split(" ", 1) if " " in key else ("UNKNOWN", key)
            # Sanitize path for Prometheus label
            safe_path = path.replace("/", "_").strip("_") or "root"

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…