Search code examples
prometheuspromql

Promql: Is it possible to get total count in Query_Range


For example, I have a prometheus query which return "1" on HTTP status 200 and "0" on HTTP status other than 200. Now, I am using the query_range api where I pass the time range (start and end) and the step.

API-Endpoint: http://my-prometheus.com/api/v1/query_range
Query: http_response_ok{appname="XXX"}
Start: 2020-06-17T00:00:00
end:2020-06-17T23:59:59
step: 300000ms     (=5min)

The above query return me the data of every 5mins for the entire day in a form of "0" and "1". Total 289 point approx.

Is it possible to get the total count of all "1" and "0" for that specific time period ? I have tried count_over_time which gives the total count. How to add a filter so that it returns the count when value == 0 or 1

count_over_time(http_response_ok{appname="XXX"}[24h])

FYI, Actual query is not http_request and I can' use http_request_total


Solution

  • After doing some research I was able to find the answer. Basically inside the {} we are doing checks b/w label. Outside the {} we can put the condition for values.

    So, to find the total counts where value is ==1 in past 24hrs, the query should be like this:

    count_over_time(http_response_ok{appname="XXX"==1}[24h:])
    

    And to find the total counts where value is ==0 in past 24hrs, the query should be like this:

    count_over_time(http_response_ok{appname="XXX"==0}[24h:])