name, description
name
description
monitoring
Monitoring and observability best practices — Prometheus, Grafana, alerts, dashboards, uptime monitoring, and incident response. Use when setting up monitoring infrastructure, designing dashboards, defining alerts. Triggers from project files and configuration, not just keyword matching."
Monitoring Best Practices
Core Concepts
SLI (Service Level Indicator) — what you measure (latency, error rate, uptime).
SLO (Service Level Objective) — target value (p99 < 500ms, error rate < 0.1%).
SLA (Service Level Agreement) — contractual commitment. Usually looser than SLO.
Rule: Set SLOs tighter than SLAs so you detect problems before customers do.
Prometheus Setup (this repo)
Key Metrics to Export
Every service should expose a /metrics endpoint:
Recording Rules
Grafana Dashboards
Dashboard Components
Panel
Metric
Good
RPS
rate(http_requests_total[5m])
Matches traffic patterns
Error rate
service:error_rate_5m
< 1%
Latency
service:latency_p99_5m
< 500ms
CPU
process_cpu_seconds_total
< 80% sustained
Memory
process_resident_memory_bytes
Steady, no leaks
Active connections
http_requests_in_flight
< configured max
Open file descriptors
process_open_fds
< 50% of limit
Dashboard Design Rules
Single pane of glass — most important metrics visible without scrolling.
Red/yellow/green thresholds — at a glance status.
Time range controls — last 15m, 1h, 6h, 1d, 7d.
Template variables — select by service, host, environment.
Annotations — mark deployments, config changes on timeline.
Alerting Rules
Severity Levels
Level
Response
Time to Acknowledge
P1 (Critical)
Pages on-call
5 min
P2 (High)
Alerts team during business hours
30 min
P3 (Medium)
Ticket, next business day
8 hours
P4 (Low)
Backlog, no deadline
N/A
Uptime Monitoring
Synthetic checks — test critical user journeys every minute.
SSL certificate expiry — alert when <30 days remaining.
Blackbox monitoring — external service checking your endpoints.
Heartbeat — cron job pings a Dead Man's Switch — if it stops, on-call is paged.
Incident Response
Runbook Template
IR Checklist
Acknowledge — confirm you're investigating.
Mitigate — stop the bleeding (rollback, disable feature flag, scale up).
Resolve — apply the fix, verify metrics return to baseline.
Review — postmortem (blameless). What happened? Why? How to prevent?
Logging Integration
Structured logs (JSON) indexed by Loki or ELK.
Correlate logs with metrics — trace_id in both.
Error sampling — capture 100% of errors, 1-10% of successful requests.
This Repo's Monitoring Stack
Component
Role
Prometheus
Metrics + alerting (Docker SD auto-discovery)
Jaeger
Tracing (OTLP receiver, all-in-one)
Traefik
Exposes metrics (--metrics.prometheus=true)
Docker labels
prometheus.io/scrape=true for auto-discovery
Dashboard
/dashboard (auto-refresh 15s)
Dashboard API
/api/dashboard — JSON with containers, traces, metrics
Anti-patterns
❌ No SLOs — "everything should be fast" is not a target
❌ Dashboard overload — metrics vomit with no narrative
❌ Alert fatigue — 100 alerts per day means none are actionable
❌ No runbooks — "what do I do when this alert fires?"
❌ Only monitoring infrastructure — no business metrics (orders/min, signups)
❌ Not monitoring after hours — 24/7 service needs 24/7 monitoring
❌ No log retention policy — infinite logs = infinite cost