🎓 A1Learner
🔍
0 of 50 lessons completed

Prometheus: Histograms and Summaries

A histogram is a metric that sorts measurements into buckets by size. A summary is a metric that reports percentiles directly from the measured process.

Buckets on the metrics page

Each bucket line counts requests that finished within its limit.

http_request_duration_seconds_bucket{le="0.005"} 248
http_request_duration_seconds_bucket{le="0.1"} 254
http_request_duration_seconds_bucket{le="+Inf"} 254

The sum and the count

Two extra lines carry the total time and the total number of requests.

http_request_duration_seconds_sum 0.317278
http_request_duration_seconds_count 254

Reading one bucket

248 of 254 requests finished within five milliseconds.

http_request_duration_seconds_bucket{le="0.005"} 248

Example

curl -s http://localhost:18102/metrics | grep http_request_duration_seconds

Key points

  • A bucket counts every measurement that finished within its upper limit.
  • The label le names the upper limit of a bucket, like le="0.1" for a tenth of a second.
  • Bucket counts grow towards larger limits, so the last bucket holds every measurement.
  • The _sum series holds the total of all measured values in seconds.
  • The _count series holds the total number of measurements taken.
  • A histogram lets Prometheus work out percentiles later, from the stored buckets.
  • A summary reports percentiles at scrape time, so Prometheus cannot recombine them.

In this example, the histogram shows 254 real requests from the running shop. Almost all of them finished within a tenth of a second, and the sum says they took 0.317278 seconds in total. The buckets hold the shape of the latency, which one single number never could.

Note

A gauge cannot give a percentile, because it holds one current value and no history of sizes.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

What does the _count series of a histogram hold?