← Back to Index

16. Monitoring & Observability

AI systems require monitoring at two levels: infrastructure (is the system healthy?) and model (is the model still making good predictions?).

Infrastructure Metrics

MetricDescriptionAlert Threshold
Latency (p50, p95, p99)End-to-end inference timep99 > 500ms for 5min
Throughput (req/s)Requests per secondSudden drop > 50%
Error rateNon-200 responses / total> 1% for 2min
GPU utilizationPercentage of GPU compute used> 95% persistent (may need scaling)
CPU / MemoryPer-instance resource usage> 85% for 10min
Connection pool usageDB, Redis, queue connections> 80% of pool max

Model Performance Metrics

# Drift detection example (Evidently AI)
Feature: "transaction_amount"
Training mean: 125.4, std: 89.2
Serving mean: 178.1, std: 112.5
KS statistic: 0.23 (threshold: 0.1)
→ ALERT: transaction_amount feature has drifted significantly
→ Possible causes: new merchant category, seasonal effect, data pipeline bug

Prometheus + Grafana Stack

Standard open-source monitoring stack for AI systems:

Distributed Tracing

Trace requests across microservices to identify bottlenecks:

# Trace: single inference request
Span 1: API Gateway → 5ms
Span 2: Auth → 3ms
Span 3: Feature fetch → 22ms (Redis)
Span 4: Feature compute → 15ms
Span 5: Model inference → 87ms (GPU)
Span 6: Post-process → 8ms
Span 7: Log to Kafka → 2ms (async)
Total: ~142ms

Logging Strategy

# Structured log entry (JSON)
{
  "timestamp": "2026-06-15T10:30:00Z",
  "request_id": "req_abc123",
  "model_id": "fraud-detection-v3",
  "latency_ms": 142,
  "input_features": {"amount": 299.99, "merchant": "amazon", ...},
  "prediction": {"fraud_score": 0.12, "action": "approve"},
  "cache_hit": false,
  "fallback_used": false
}
Exercise: Design the monitoring dashboard for a real-time language translation service. List 6 panels you would include in your Grafana dashboard. For each panel, specify: metric source (Prometheus/application logs), aggregation (p50, p95, rate), and alert threshold if applicable. Include at least one model-drift-specific panel.