avhhh
avhhh

Reputation: 271

How to get the 95th percentile of an average in Prometheus?

So I'm aware of some percentile functions in PromQL like histogram_quantile which is used in a case like this:

// Over the past 5 minutes, what's the maximum http response time experienced by 95% of our users
histogram_quantile(0.95, rate(http_request_duration_bucket[5m])

And we can calculate the average this way:

// Over the past 5 mins, what the average http response time?
avg by (webId) (rate(http_request_duration_sum[5m])/rate(http_request_duration_count[5m])

Is it possible to combine these two function to get the query that means the following: Over the past 5 mins, what's the maximum average HTTP response time experienced by 95% of our users? AKA 95 percentile of the AVERAGE?

I tried something like:

histogram_quantile(0.95, avg by (webId) (rate(http_request_duration_sum[5m])/rate(http_request_duration_count[5m]))

But it doesn't seem to work. Any suggestions or gaps in my understanding?

Upvotes: 5

Views: 40867

Answers (2)

RobM
RobM

Reputation: 8935

I found the answers above didn't work for my situation, but quantile_over_time allowed me to extract a percentile from a sum:

quantile_over_time(0.95,
  (sum by (component_name) (
     node_memory_MemTotal_bytes 
     - node_memory_MemFree_bytes 
     - node_memory_Cached_bytes)[2w:]
  )
)

Upvotes: 0

valyala
valyala

Reputation: 17794

Try the following query:

quantile(0.95, avg by (webId) (rate(http_request_duration_sum[5m])/rate(http_request_duration_count[5m])))

It uses quantile() aggregate function for calculating the given quantile over average response times calculated per each webId.

Upvotes: 12

Related Questions