Metric Types: Histograms and Summaries
You'll learn how histograms and summaries help you measure distributions and percentiles, going beyond simple counts and snapshots.
Why Counters and Gauges Aren't Enough
In the previous lesson, you learned about counters (cumulative totals) and gauges (point-in-time values). But what if you need to know how your values are distributed? For example, knowing the average API response time is useful, but it hides crucial details: are most requests fast with a few slow outliers, or is performance consistently mediocre?
Histograms: Bucketing Your Data
A histogram groups observations into predefined buckets (ranges). Think of sorting exam scores into letter grades: 90-100 is an A, 80-89 is a B, and so on.
For response times, you might create buckets:
- 0-100ms
- 100-250ms
- 250-500ms
- 500ms+
Each request increments the appropriate bucket counter. This lets you calculate percentiles later (like "95% of requests finished under 500ms") and see the shape of your distribution.
Trade-off: Histograms are cheap to collect but require choosing buckets upfront. Choose poorly, and you lose precision.
Summaries: Pre-Calculated Percentiles
A summary calculates percentiles (like p50, p95, p99) as data arrives, storing those exact values. It's like having a smart assistant who tracks "the 95th-slowest request out of every 100" in real-time.
Trade-off: Summaries give exact percentiles but are more expensive computationally and can't be aggregated across multiple servers easily.
Which to Use?
Use histograms when you need flexible querying and can aggregate across instances. Use summaries when exact percentiles matter more than aggregation flexibility.
Key Takeaway: Histograms bucket measurements for flexible percentile calculation; summaries pre-compute exact percentiles. Both capture distribution data that counters and gauges miss.