Query to display total number of successful request

Hi,

Trying to display the total successful count for a specific endpoint in Grafana but the query below shows some metrics however when a longer date range is selected the count decreases, and I would expect the count to increase.

sum(http_server_requests_seconds_count{uri=“/api/v1/student/{studentId}”, status=“200”})

Is there any other way to display the count of total requests in Grafana?

As this looks to be a counter you should use the “increase” function.

Thanks. Tried replacing the sum to increase function but no data is displayed. Also is there a way to capture the count irrespective of pod restart? It seems to be when pods restarted then the counter resets to 0.

increase(http_server_requests_seconds_count{uri=“/api/v1/student/{studentId}”, status=“200”})

For a counter the absolute value has no real meaning. It is how it changes which is important. As you say it might reset to zero at any point, so you should be looking at either the increase() which tells you how much it has increased by over a period of time, or rate() which returns the rate of change (basically the increase divided by the time period).

The reason the increase didn’t work for you is because you didn’t specify the time period to calculate it over. The example in the docs (Query functions | Prometheus) uses a period of 5 minutes.

Thank you. I tried with the time period in the increase function it works but many values are displayed eg: 0 0 3 5 .Do I need to sum up as I just need only the total count.?

What time period are you using, what is the time period for your dashboard, and are you using a single stat panel or a graph?

increase(http_server_requests_seconds_count{uri=“/api/v1/student/{studentId}”, status=“200”}[5m])

The dashboard time period selected is 15mins, 12 hours,24 hours,1 month, and so on.

When I select 1 month time period in the dashboard the count should have been increased but the count is low and 24 hours count shows more. It looks like the counter reset when the pod restarts and shows fewer numbers when I increased the period in the dashboard.

It is a single stat panel.

In which case you need to use the duration of the dashboard instead of 5m. I think Grafana has a variable called something like $__interval