- Бэкенд: FastAPI + SQLAlchemy async + PostgreSQL, JWT-аутентификация, Qdrant multi-tenant векторное хранилище, Celery воркер - Фронтенд: React + Vite + TypeScript SPA (логин, регистрация, дашборд, поиск по коллекциям, настройки) - Инфраструктура: docker-compose, Helm-чарт, GitHub Actions CI, Prometheus/Grafana мониторинг - Embedding через OpenRouter (nvidia/llama-nemotron-embed-vl-1b-v2:free) - LLM: google/gemma-4-31b-it:free через OpenRouter
34 lines
1 KiB
Python
34 lines
1 KiB
Python
from prometheus_client import Counter, Histogram, generate_latest, CONTENT_TYPE_LATEST
|
|
from starlette.middleware.base import BaseHTTPMiddleware
|
|
from starlette.requests import Request
|
|
from starlette.responses import Response
|
|
|
|
from app.config import settings
|
|
|
|
http_requests = Counter(
|
|
"http_requests_total",
|
|
"Total HTTP requests",
|
|
["method", "path", "status"],
|
|
)
|
|
|
|
http_duration = Histogram(
|
|
"http_request_duration_seconds",
|
|
"HTTP request duration in seconds",
|
|
["method", "path"],
|
|
)
|
|
|
|
|
|
class MetricsMiddleware(BaseHTTPMiddleware):
|
|
async def dispatch(self, request: Request, call_next):
|
|
method = request.method
|
|
path = request.url.path
|
|
|
|
with http_duration.labels(method=method, path=path).time():
|
|
response = await call_next(request)
|
|
|
|
http_requests.labels(method=method, path=path, status=response.status_code).inc()
|
|
return response
|
|
|
|
|
|
async def metrics_endpoint(request: Request):
|
|
return Response(content=generate_latest(), media_type=CONTENT_TYPE_LATEST)
|