Spaces:
Build error
Build error
| """Prometheus metrics configuration.""" | |
| from prometheus_client import Counter, Histogram, Gauge, generate_latest | |
| from starlette.responses import Response | |
| from app.core.config import settings | |
| # Request metrics | |
| http_requests_total = Counter( | |
| "http_requests_total", | |
| "Total HTTP requests", | |
| ["method", "endpoint", "status"], | |
| ) | |
| http_request_duration = Histogram( | |
| "http_request_duration_seconds", | |
| "HTTP request duration", | |
| ["method", "endpoint"], | |
| buckets=(0.1, 0.5, 1.0, 2.5, 5.0, 10.0, 30.0, 60.0), | |
| ) | |
| # Generation metrics | |
| generation_requests_total = Counter( | |
| "generation_requests_total", | |
| "Total generation requests", | |
| ["type", "status"], | |
| ) | |
| generation_duration = Histogram( | |
| "generation_duration_seconds", | |
| "Generation duration", | |
| ["type"], | |
| buckets=(5.0, 10.0, 30.0, 60.0, 120.0, 300.0), | |
| ) | |
| active_generations = Gauge( | |
| "active_generations", | |
| "Currently active generations", | |
| ["type"], | |
| ) | |
| # System metrics | |
| audio_storage_bytes = Gauge( | |
| "audio_storage_bytes", | |
| "Total audio storage size in bytes", | |
| ) | |
| def setup_metrics() -> None: | |
| """Setup metrics collection.""" | |
| if not settings.ENABLE_METRICS: | |
| return | |
| def metrics_endpoint() -> Response: | |
| """Prometheus metrics endpoint.""" | |
| return Response( | |
| content=generate_latest(), | |
| media_type="text/plain", | |
| ) | |