How can I display HTTP average response time, when the rate() function results in NaN

Hi there,

I have a query, which calculates the average HTTP response time for a given URI:

avg(rate(http_server_requests_seconds_sum{status=~“2…|3…”, namespace="$namespace", method=“GET”, pod_name=~"$pod_name", uri="/doitt"}[$interval])/rate(http_server_requests_seconds_count{status=~“2…|3…”, namespace="$namespace", method=“GET”, pod_name=~"$pod_name", uri="/doit"}[$interval]))

However, when breaking this query down within the Thanos web interface, I notice that the rate() function produces a really small number, close to 0. As a result we get the calculation avg(0/0) and 0/0, of course, is undefined in Mathematics. This is the reason why I see NaN as the outcome of this calculation.

How can I prevent the rate()/rate() calculation from rounding the number down to 0?

Have you read this: https://www.robustperception.io/get-thee-to-a-nannary

Hi @daniellee - thank you. I will have a read :slight_smile:

I’ve changed my query (above) to:

sum by (pod_name)(rate(http_server_requests_seconds_sum{status=~“2…”, namespace="$namespace", method=“GET”, pod_name=~"$pod_name", uri="/doitt"}[$interval]))/ sum by (pod_name) (rate(http_server_requests_seconds_count{status=~“2…”, namespace="$namespace", method=“GET”, pod_name=~"$pod_name", uri="/doitt"}[$interval]))

However, the graph doesn’t seem to look right :confused:

Could anyone help?