Grouping of records on day basis

22 views
Skip to first unread message

sunils...@gmail.com

unread,
Oct 27, 2020, 10:58:36 AM10/27/20
to Prometheus Users
Hi , 

I have metrics for http request count . I want to display the number of success counts by each day . 

http_request{probe="success"} 3500

I want to find the http_request sum grouped by day . eg.

Oct 27 : 300
Oct 26 : 350
Oct 25 : 325
Oct 24 : 375 .. etc 

Is it possible to group this way on day basis using promql . 

Thanks ,

Bjoern Rabenstein

unread,
Nov 3, 2020, 5:21:05 PM11/3/20
to sunils...@gmail.com, Prometheus Users
The PromQL query for "how many HTTP requests over the last day" would
look like this:

increase(http_request{probe="success"}[1d])

However, that's not for the last calendar day, but just for the last
24 hours back from the evaluation time.

The Prometheus UI (or similar things in Grafana etc.) allow you to set
the evaluation time to midnight of a specific day. Then you get your
result for the calendar day preceding that timestamp.

From within PromQL, you cannot (yet) set a fixed evaluation time. But
you could craft a call to the Prometheus HTTP API and use it with
`curl`. The `query_range` endpoint will allow you to get those
values. See
https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries
in the docs.

In your case, you'll probably end up with something like:

curl 'http://localhost:9090/api/v1/query_range?query=increase%28http_request%7Bprobe%3D%22success%22%7D%5B1d%5D%29&start=2020-10-25T00:00:00Z&end=2020-10-28T00:00:00Z&step=86400s'

--
Björn Rabenstein
[PGP-ID] 0x851C3DA17D748D03
[email] bjo...@rabenste.in
Reply all
Reply to author
Forward
0 new messages