Search code examples
prometheuspromql

PromQL: I want to calculate total http calls for specific time period grouped by status code


We have had an incident and I want to get total number of HTTP requests to a specific endpoint for a specific time period grouped by status code. For instance I want to know how many 500 response codes, 200 response codes, 400 response codes and so forth.

I have a query like the following:

sum by (status_code) (sum_over_time(http_requests_total{namespace="prod" , path="/register"}[3h20m]))

I do not know how to get it to ignore counts that happened before and after the incident. Is this even possible.


Solution

  • Just substitute sum_over_time() with increase(), because http_requests_total is a counter metric.

    For example, the following query should return the number of requests to /register path at namespace="prod" during the last 3 hours and 20 minutes grouped by status_code:

    sum by (status_code) (
      increase(http_requests_total{namespace="prod" , path="/register"}[3h20m])
    )