Search code examples
prometheusgrafanapromql

How to visualize average response time of all requests


I have a metric http_request_duration_seconds which is a histogram based on Action,

http_request_duration_seconds The duration of HTTP requests processed by an ASP.NET Core application. TYPE http_request_duration_seconds histogram

which data is :

http_request_duration_seconds_sum{code="200",method="GET",controller="Player",action="Load"} 0.4301564
http_request_duration_seconds_count{code="200",method="GET",controller="Player",action="Load"} 1
http_request_duration_seconds_sum{code="200",method="POST",controller="Auth",action="Token"} 0.2790333
http_request_duration_seconds_count{code="200",method="POST",controller="Auth",action="Token"} 1

Now in Grafana, I want to visualize the average of response time of all my actions in a specified time frame for example 5 minutes.

In this example data, my desired output for this moment should be (0.43 + 0.27) / ( 1 + 1)

What is the promql query to do that?


Solution

  • Try

    sum(rate(http_request_duration_seconds_sum[5m])) / sum(rate(http_request_duration_seconds_count[5m]))

    See Prometheus docs for more details.