Slicing the metrics scraped by HAPROXY Exporter.

25 views
Skip to first unread message

Yagyansh S. Kumar

unread,
Apr 21, 2020, 2:20:03 AM4/21/20
to Prometheus Users
Hi. I am using HAPROXY for configuring my LB-Rules and using HAPROXY Exporter to get the metrics. Now, majorly I want to keep track of the Requests coming to my LB and the responses served by my LB that is configured on the HAPROXY.

Now,
haproxy_frontend_http_requests_total
haproxy_frontend_http_responses_total
haproxy_backend_http_responses_total

All these give me the cumulative numbers right from when the HAPROXY Exporter started scraping the metrics. I want to get the numbers for specific time interval like last 24hours, 2 days etc. Can someone help here?

Thanks in advance.

Julius Volz

unread,
Apr 21, 2020, 3:35:02 AM4/21/20
to Yagyansh S. Kumar, Prometheus Users
HAProxy does not output historic data about past requests (nor would Prometheus be able to scrape it), so you'd have to scrape the HAProxy exporter for 24h, 2 days, etc., to get that amount of history into Prometheus.

Then you can query for e.g. the average request rate per second over 24h ("rate(haproxy_frontend_http_requests_total[1d]") or the total number of requests happening in 2d ("increase(haproxy_frontend_http_requests_total[2d])").

Yagyansh S. Kumar

unread,
Apr 21, 2020, 3:41:58 AM4/21/20
to Prometheus Users

HAProxy does not output historic data about past requests (nor would Prometheus be able to scrape it), so you'd have to scrape the HAProxy exporter for 24h, 2 days, etc., to get that amount of history into Prometheus. >>>
    I think I didn't get this part properly. I am already scraping the metrics continuously. Can you please help a little on understanding this?
    Thanks.

Brian Candler

unread,
Apr 21, 2020, 3:49:43 AM4/21/20
to Prometheus Users
Those metrics like haproxy_frontend_http_requests_total are counters.

If you want see much they've increased in the last 24 hours, then you need to use this function:

increase(haproxy_frontend_http_requests_total[24h])

which is equivalent to

rate(haproxy_frontend_http_requests_total[24h]) * 86400

Yagyansh S. Kumar

unread,
Apr 21, 2020, 5:16:45 AM4/21/20
to Prometheus Users
Thanks a lot Brain, this works.

Yagyansh S. Kumar

unread,
Apr 21, 2020, 5:26:47 AM4/21/20
to Prometheus Users
One more query regarding this.

If I want to see the number of requests that increased on let say 17th April. How to approach that?

On Tuesday, April 21, 2020 at 1:19:43 PM UTC+5:30, Brian Candler wrote:

Brian Candler

unread,
Apr 21, 2020, 6:21:56 AM4/21/20
to Prometheus Users
On Tuesday, 21 April 2020 10:26:47 UTC+1, Yagyansh S. Kumar wrote:
If I want to see the number of requests that increased on let say 17th April. How to approach that?


If querying through the API: choose an instant for your query which is 00:00:00 on 18th April.

Or do this via your frontend (e.g. Grafana).  If you draw
increase(haproxy_frontend_http_requests_total[24h])
as a graph, then the value at a given point is for the 24 hour period up to that point.

Yagyansh S. Kumar

unread,
Apr 21, 2020, 6:51:05 AM4/21/20
to Prometheus Users
Oh, yes.

Thanks a lot, Brain.

Yagyansh S. Kumar

unread,
Apr 21, 2020, 6:52:33 AM4/21/20
to Prometheus Users
Is there a significant time difference in query evaluation while querying directly through API?

Brian Candler

unread,
Apr 21, 2020, 7:32:23 AM4/21/20
to Prometheus Users
Not sure what you mean - time difference between what and what?

Yagyansh S. Kumar

unread,
Apr 21, 2020, 7:54:29 AM4/21/20
to Prometheus Users
Sorry posted it in the wrong thread.

Thanks for your help.
Reply all
Reply to author
Forward
0 new messages