Files
leocrm/app/routes/metrics.py
T
leocrm-bot 69e91fd5d0 T10: Monitoring, Performance, Documentation & Environment Config — 38 tests, ruff clean, docs OK
- Extended health endpoint: DB+Redis+Storage+Worker checks with degraded status
- Prometheus metrics endpoint: admin-only, text/plain format
- Metrics: http_requests_total, db_pool_connections, arq_jobs_total
- Structured JSON logging (structlog): timestamp, level, method, path, status, duration_ms, tenant_id
- Performance: page_size max 100 enforced (422), streaming CSV export (StreamingResponse)
- Scripts: seed_perf_data.py, check_indexes.py
- Docs: admin-guide.md (Deploy, Backup, Restore, Env-Vars, Troubleshooting), api-overview.md
- README updated: prod setup, API section, env profiles, admin-guide link
- .env.example: added SECRET_KEY, STORAGE_PATH, SMTP_* vars
- 38 new tests, full regression 564/564 pass (0 failures)
- Ruff: all checks passed
2026-07-01 23:15:35 +02:00

30 lines
757 B
Python

"""Prometheus metrics endpoint — admin-only."""
from __future__ import annotations
from fastapi import APIRouter, Depends
from fastapi.responses import PlainTextResponse
from app.core.monitoring import generate_metrics
from app.deps import require_admin
router = APIRouter(tags=["metrics"])
@router.get(
"/api/v1/metrics",
response_class=PlainTextResponse,
dependencies=[Depends(require_admin)],
)
async def metrics():
"""Prometheus metrics endpoint.
Returns Prometheus-formatted text/plain metrics.
Requires admin role — 403 for non-admin users.
"""
data = generate_metrics()
return PlainTextResponse(
content=data.decode("utf-8"),
media_type="text/plain; version=0.0.4; charset=utf-8",
)