Skip to content

Monitoring

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.

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).

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.

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.

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).
LevelActionChannel
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

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.

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: 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?โ€).

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.

  • 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.โ€