Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grafana graphing HTTP requests per minute with http_server_requests_seconds_count

I have a Spring boot app throwing out open metric stats using micrometer.

For each of my HTTP endpoints, I can see the following metric which I believe tracks the number of requests for the given endpoint:

http_server_requests_seconds_count

My question is how do I use this in a Grafana query to present the number number of requests calling my endpoint say every minute?

I tried

http_client_requests_seconds_count{}

and

sum(rate(http_client_requests_seconds_count{}[1m]))

but neither work.

Thanks in advance.

like image 540
KumByYa Avatar asked Jan 25 '23 11:01

KumByYa


1 Answers

rate(http_client_requests_seconds_count{}[1m]) will provide you the number of request your service received at a per-second rate.

However by using [1m] it will only look at the last minute to calculate that number, and requires that you collect samples at a rate quicker than a minute. Meaning, you need to have collected 2 scrapes in that timeframe.

increase(http_client_requests_seconds_count{}[1m]) would return how much that count increased in that timeframe, which is probably what you would want, though you still need to have 2 data points in that window to get a result.

Other way you could accomplish your result:

increase(http_client_requests_seconds_count{}[2m]) / 2 By looking over 2 minutes then dividing it, you will have more data and it will flatten spikes, so you'll get a smoother chart.

rate(http_client_requests_seconds_count{}[1m]) * 60 By multiplying the rate by 60 you can change the per-second rate to a per-minute value.

Here is a writeup you can dig into to learn more about how they are calculated and why increases might not exactly align with integer values: https://promlabs.com/blog/2021/01/29/how-exactly-does-promql-calculate-rates

like image 57
checketts Avatar answered Apr 30 '23 05:04

checketts