6fd2f0e689
LLM classify via LiteLLM gigachat-classifier when heuristic confidence is low. CLASSIFIER_MODE=heuristic|hybrid|llm. Metrics classifier_source.
37 lines
928 B
Python
37 lines
928 B
Python
"""Prometheus metrics for gateway tier/lane routing."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from prometheus_client import CONTENT_TYPE_LATEST, Counter, Histogram, generate_latest
|
|
|
|
REQUESTS = Counter(
|
|
"ai_router_requests_total",
|
|
"Total routed requests",
|
|
["tier", "lane", "model", "status"],
|
|
)
|
|
ESCALATIONS = Counter(
|
|
"ai_router_escalations_total",
|
|
"Lane escalations",
|
|
["from_lane", "to_lane", "reason"],
|
|
)
|
|
CLASSIFY = Counter(
|
|
"ai_router_classify_total",
|
|
"Classification results",
|
|
["tier"],
|
|
)
|
|
CLASSIFY_LLM = Counter(
|
|
"ai_router_classify_llm_total",
|
|
"LLM classifier invocations (GigaChat)",
|
|
["tier", "status"],
|
|
)
|
|
DURATION = Histogram(
|
|
"ai_router_request_duration_seconds",
|
|
"Request duration",
|
|
["tier", "model"],
|
|
buckets=(0.1, 0.25, 0.5, 1, 2, 5, 10, 30, 60, 120, 180),
|
|
)
|
|
|
|
|
|
def metrics_payload() -> tuple[bytes, str]:
|
|
return generate_latest(), CONTENT_TYPE_LATEST
|