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?

@sadiahmse
Can you please tell me how are you able to fetch the http_server_requests_seconds_sum metrics of your server. I needed to know which exporter to use to fetch the values

@vyshaksekhar
If your use case is fetching the response time of any URL, you can use Blackbox Exporter.
To Monitor the overall response time of the URL, Please try “probe_duration_seconds”.

This will measure the total time taken to complete the probe, including DNS resolution, connection establishment, HTTP request, and response.