Metrics

Metrics Reference

All Prometheus metrics are exposed at the /metrics endpoint by prometheus-fastapi-instrumentator plus custom gauges and counters registered in observability/drift_check.py and observability/anomaly_detection.py. Alert thresholds are defined in observability/alert_rules.yml and are loadable with promtool check rules observability/alert_rules.yml.


HTTP Metrics

Emitted automatically by prometheus-fastapi-instrumentator for every request handled by api/app.py.

MetricTypeLabelsDescription
http_requests_totalCountermethod, route, statusTotal HTTP requests by method, route, and status code
http_request_duration_secondsHistogrammethod, routeRequest latency; used for P95/P99 SLO evaluation

Alert thresholds

AlertThresholdSeverityWindow
APIHighP99LatencyP99 > 2.0swarningfor: 5m
APILatencyCriticalP99 > 5.0scriticalfor: 2m
APIHighErrorRate5xx rate > 5%warningfor: 5m
APICriticalErrorRate5xx rate > 20%criticalfor: 2m
JWTAuthFailureSpike401 rate > 1/swarningfor: 3m
JWTAuthFailureCritical401 rate > 10/scriticalfor: 1m

ML Model Metrics

Registered in observability/drift_check.py and exported via the shared Prometheus registry.

MetricTypeLabelsDescription
ml_psi_scoreGaugemodel, featurePopulation Stability Index for a given model/feature pair. PSI < 0.10 = stable; 0.10–0.20 = minor drift; ≥ 0.20 = major drift
ml_feature_drift_ratioGaugemodel, featureRelative mean deviation (drift ratio) for scalar features
ml_drift_events_totalCountermodel, severityCumulative drift events by severity (minor_drift, major_drift)
ml_anomaly_threshold_breaches_totalCountermodelCumulative anomaly score threshold breaches (score < 0.0)
ml_prediction_latency_secondsHistogrammodelWall-clock time for model.decision_function() calls

Alert thresholds

AlertThresholdSeverityWindow
ModelMinorDriftPSI > 0.10warningfor: 10m
ModelMajorDriftPSI ≥ 0.20criticalfor: 5m
ModelDriftEventSpike> 3 major events in 30mcriticalfor: 0m
AnomalyBreachRateHigh> 0.5 breaches/s (10m avg)warningfor: 5m
PredictionVolumeSilence0 predictions in 15mcriticalfor: 10m
PredictionLatencyDegradedp95 > 1.0swarningfor: 5m

Infrastructure Metrics

Emitted by kube-state-metrics and the Redis exporter where applicable.

MetricTypeLabelsDescription
alembic_migration_head_lagGaugejobNumber of unapplied Alembic migrations on the running DB head
redis_memory_used_bytesGaugejobRedis heap used (bytes); denylist and rate-limit data
redis_memory_max_bytesGaugejobRedis maxmemory ceiling (bytes)
kube_pod_container_status_restarts_totalCounternamespace, pod, containerKubernetes pod restart counter

Alert thresholds

AlertThresholdSeverityWindow
AlembicMigrationLaghead_lag > 0warningfor: 5m
RedisHighMemoryUsagemem_used / mem_max > 85%warningfor: 5m
PodRestartLoop> 3 restarts in 15mcriticalfor: 0m

PSI Reference

The Population Stability Index thresholds used in drift_check.py and alert_rules.yml follow the financial-industry standard:

PSI RangeInterpretationRecommended Action
< 0.10StableMonitor normally
0.10 – 0.20Minor driftInvestigate; schedule retraining evaluation
≥ 0.20Major driftOpen P1 ML incident; halt serving if confidence threshold breached

All alerts include a runbook_url annotation pointing to the live runbooks at mlops.zrl.dev: