Metrics, Dashboards and Alerting

Measure rates, errors and latency with Prometheus-style metrics, build dashboards and alert on user-visible symptoms.

Intermediate · about 5 hours · difficulty 3/5

Learn first: Structured Logging

Logs tell you what happened to one request; metrics tell you how the whole system is behaving right now. They are cheap numeric time series you can graph and alert on.

Metric types

  • Counter: only goes up (http_requests_total). You graph its rate.
  • Gauge: goes up and down (queue_depth, db_pool_in_use).
  • Histogram: buckets of observed values (http_request_duration_seconds) so you can compute percentiles.

Add labels (route, method, status code) but keep them low-cardinality; a label per user id can take down your metrics system.

What to measure

  • RED for services: Rate, Errors, Duration of requests.
  • USE for resources: Utilization, Saturation, Errors of CPU, memory, disks, pools.
  • Google's four golden signals: latency, traffic, errors, saturation.
  • Business metrics too: signups, checkouts, failed payments.

Percentiles, not averages

An average latency of 100 ms can hide a p99 of 5 seconds that frustrates your best customers. Watch p50, p95 and p99.

Tooling

Prometheus scrapes a /metrics endpoint from each instance and stores time series; Grafana builds dashboards. Hosted options include Grafana Cloud, Datadog and CloudWatch. OpenTelemetry can export metrics to any of them.

Alerting well

  • Alert on symptoms users feel (error rate above 2 percent, p99 above 1 s) rather than every cause (CPU at 80 percent).
  • Define SLOs (for example 99.9 percent of requests succeed) and alert on error-budget burn rate.
  • Every alert should be actionable and link to a runbook; noisy alerts get ignored.

You are ready to move on when your service exposes RED metrics, a Grafana dashboard shows p95 latency per route, and one symptom-based alert fires in a test.

Key concepts

  • Counters, gauges and histograms
  • Labels and cardinality
  • RED and USE methods
  • Percentile latency
  • Prometheus and Grafana
  • SLIs, SLOs and error budgets
  • Symptom-based alerting and runbooks

Mini project

Instrument your API with request count and latency histograms, run Prometheus and Grafana with Docker Compose, build a RED dashboard and configure an alert for a high error rate.

Check yourself

Why is alerting on high CPU usually worse than alerting on elevated error rate or latency?

Free resources