You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Metrics are the foundation of observability. They are numeric measurements collected at regular intervals and stored as time series — sequences of data points indexed by time. Metrics are lightweight, efficient to store, and ideal for dashboards and alerting.
A time series is a sequence of values recorded at successive points in time:
timestamp value
2025-03-15T10:00:00Z 0.42
2025-03-15T10:00:15Z 0.51
2025-03-15T10:00:30Z 0.38
2025-03-15T10:00:45Z 0.67
Each time series is uniquely identified by a metric name and a set of labels (also called tags or dimensions):
http_request_duration_seconds{service="api", method="GET", endpoint="/users"}
Most metrics systems define four core metric types:
A monotonically increasing value that only goes up (or resets to zero on restart).
http_requests_total{method="GET", status="200"} 14523
Use counters for: total requests, errors, bytes transferred.
A value that can go up or down — a snapshot of a current measurement.
temperature_celsius{location="server-room"} 22.5
Use gauges for: CPU usage, memory usage, queue depth, temperature.
Samples observations (e.g., request latency) and counts them in configurable buckets.
http_request_duration_seconds_bucket{le="0.1"} 24054
http_request_duration_seconds_bucket{le="0.5"} 33025
http_request_duration_seconds_bucket{le="1.0"} 34182
http_request_duration_seconds_bucket{le="+Inf"} 34312
http_request_duration_seconds_sum 8743.12
http_request_duration_seconds_count 34312
Use histograms for: latency distributions, request sizes.
Similar to histograms but calculates quantiles (e.g., p50, p95, p99) on the client side.
http_request_duration_seconds{quantile="0.5"} 0.042
http_request_duration_seconds{quantile="0.95"} 0.23
http_request_duration_seconds{quantile="0.99"} 0.87
Tip: Prefer histograms over summaries — histograms can be aggregated across instances, while summaries cannot.
Labels add dimensions to metrics, enabling powerful filtering and grouping:
http_requests_total{service="api", method="GET", status="200", region="eu-west-1"}
Cardinality is the total number of unique label combinations. High cardinality causes:
| Do | Do Not |
|---|---|
| Use bounded label values (HTTP methods, status codes) | Use user IDs or email addresses as labels |
| Keep label sets small (5-10 labels) | Add labels "just in case" |
| Monitor your active time series count | Ignore cardinality until it is a problem |
The RED method defines three key metrics for request-driven services:
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.