Monitoring
๐ฆ 1. The Service-Oriented Approach
Section titled โ๐ฆ 1. The Service-Oriented ApproachโDonโt monitor โserversโ; monitor Services. A server might be at 99% CPU, but if the service is still responding in 50ms and users are happy, itโs not an emergencyโitโs high efficiency.
The RED Method (For Services)
Section titled โThe RED Method (For Services)โPopularized for microservices, this focuses on what the user experiences:
- Rate: The number of requests per second.
- Errors: The number of failed requests.
- Duration: The time those requests take (Latency).
The USE Method (For Resources)
Section titled โThe USE Method (For Resources)โUsed for the underlying infrastructure (CPU, Memory, Disk):
- Utilization: The average time the resource was busy.
- Saturation: The degree to which the resource has extra work it canโt service (queuing).
- Errors: The count of error events.
๐จ 2. Alerting: Signal vs. Noise
Section titled โ๐จ 2. Alerting: Signal vs. NoiseโThe biggest threat to a Programmer is Alert Fatigue. If your team receives 50 alerts a day, they will eventually ignore the one that actually matters.
Symptom-Based Alerting
Section titled โSymptom-Based AlertingโNever alert on a cause; alert on a symptom.
- Bad Alert (Cause): โDatabase CPU is 90%.โ (The DB might be designed to run high).
- Good Alert (Symptom): โ500 Errors are > 1%.โ (Something is definitely broken for the user).
Alert Categorization (Severity)
Section titled โAlert Categorization (Severity)โ| Level | Action | Channel |
|---|---|---|
| Critical (P1) | Immediate intervention required. System is down. | PagerDuty / Phone Call |
| Warning (P2) | Potential issue, but system is degraded, not down. | Slack / Email (Next Business Day) |
| Info (P3) | For record-keeping or non-urgent optimization. | Dashboard only |
๐ 3. Service Level Objectives (SLOs)
Section titled โ๐ 3. Service Level Objectives (SLOs)โThis is the most critical concept. You must define what โGood Enoughโ looks like.
- SLI (Indicator): The metric (e.g., โHTTP Request Latencyโ).
- SLO (Objective): The target (e.g., โ99% of requests < 300msโ).
- SLA (Agreement): The legal contract (e.g., โIf we miss our SLO, we pay the customer back moneyโ).
- Error Budget: If your SLO is 99.9%, you have a 0.1% โbudgetโ for failure. If you havenโt used your budget, you can deploy risky new features. If your budget is empty, you must freeze deployments and focus on stability.
๐ ๏ธ 4. Advanced Monitoring Patterns
Section titled โ๐ ๏ธ 4. Advanced Monitoring PatternsโSynthetic Monitoring (Uptime Checks)
Section titled โSynthetic Monitoring (Uptime Checks)โDonโt wait for a user to find a bug.
- Strategy: Use โCanaryโ scripts that act like users. Every 60 seconds, a script logs in, adds an item to the cart, and checks out. If this fail, you know the entire stack is broken before the first real customer complains.
White-box vs. Black-box
Section titled โWhite-box vs. Black-boxโ- White-box: Metrics from inside the app (e.g., Go routines, Thread pool size, GC pause time).
- Black-box: Testing the app from the outside (e.g., โCan I reach the URL?โ).
Health Endpoints (/healthz)
Section titled โHealth Endpoints (/healthz)โEvery service should have a /health or /ready endpoint.
- Programmerโs Move: Donโt just return
200 OK. Have the endpoint check the connection to the Database and the Cache. If the DB is down, the service should report itself as โUnhealthyโ so the Load Balancer stops sending it traffic.
โ๏ธ The Monitoring Stack
Section titled โโ๏ธ The Monitoring Stackโ- Collection: Prometheus (Pull-based) or OpenTelemetry (Push-based).
- Storage: VictoriaMetrics or InfluxDB (Time-series data).
- Visualization: Grafana.
- Alert Routing: Alertmanager (Prometheus) or Opsgenie.
๐ก Note: Every alert should have a Runbook link in the description. When an engineer is woken up at 3:00 AM, they shouldnโt have to guess. The alert should say: โThis is what is broken, here is the dashboard to look at, and here is the command to fix it.โ