How do you calculate the average request duration during the last 5 minutes from a histogram or summary called http_request_duration_seconds?
In Prometheus, histograms and summaries expose metrics with _sum and _count suffixes to represent total accumulated values and sample counts, respectively. To compute the average request duration over a given time window (for example, 5 minutes), you divide the rate of increase of _sum by the rate of increase of _count:
text{Average duration} = frac{text{rate(http_request_duration_seconds_sum[5m])}}{text{rate(http_request_duration_seconds_count[5m])}}
Here,
http_request_duration_seconds_sum represents the total accumulated request time, and
http_request_duration_seconds_count represents the number of requests observed.
By dividing these rates, you obtain the average request duration per request over the specified time range.
Extracted and verified from Prometheus documentation -- Querying Histograms and Summaries, PromQL Rate Function, and Metric Naming Conventions sections.
Currently there are no comments in this discussion, be the first to comment!