Metric Types: Histogram
You'll learn how Prometheus histograms organize observations into buckets to enable efficient quantile calculations for measuring request durations and response sizes.
Understanding Histograms
A histogram samples observations (typically request durations or sizes) and counts them in configurable buckets. Think of it like sorting test scores into grade ranges: 0-59, 60-79, 80-89, 90-100. Instead of storing every individual score, you track how many fall into each bucket.
Prometheus histograms create cumulative buckets, meaning each bucket contains the count of all observations less than or equal to its upper bound. For a duration metric with buckets [0.1, 0.5, 1.0, +Inf] seconds:
le="0.1"counts requests ≤ 100msle="0.5"counts requests ≤ 500ms (including the 0.1s ones)le="1.0"counts requests ≤ 1 secondle="+Inf"counts all requests (the total)
What Histograms Provide
A histogram metric actually exposes three time series:
<metric>_bucket{le="<upper_bound>"}– cumulative counters per bucket<metric>_sum– total sum of all observed values<metric>_count– total count of observations
From these buckets, you can calculate quantiles (like "95% of requests completed within X seconds") using functions like histogram_quantile().
When to Use Histograms
Use histograms when you need to:
- Measure request/response latencies
- Track payload sizes
- Calculate percentiles (p50, p95, p99) across multiple instances
- Aggregate quantile data from distributed systems
Key Takeaway: Histograms bucket observations into predefined ranges, allowing efficient quantile calculations for latency and size measurements without storing every individual value.