Sum up request duration correctly

40 views
Skip to first unread message

ofir y

unread,
Apr 30, 2023, 5:24:46 AM4/30/23
to Prometheus Users
I have a Prometheus server which scrapes data from my API metrics endpoint that is populated using  Prometheus.net library . the scraping interval set to 15 seconds. I'm publishing a request duration summary metric to it. this metric is published at random times to the endpoint. but the scrape interval makes Prometheus thinks it is a new value every 15 seconds, even if no new data was published. this causes the _count & _sum values of the metric to be wrong, as they consider every 15 seconds to be a new point.

my goal is to be able to count & to sum up all requests actions. so if I had 3 requests over a period of 2 minutes like so:
00:00 request 1: duration 1 sec
00:30 request 2: duration 1 sec
01:55 request 3: duration 2 sec

the _count will be 3, and the _sum will be 4 seconds. can I achieve this somehow by using labels or something else?

Stuart Clark

unread,
Apr 30, 2023, 5:35:14 AM4/30/23
to ofir y, Prometheus Users
It sounds like you are trying to use Prometheus to store events, which
won't work as Prometheus is a metric system.

Normally what you would expose from your application are counters giving
the total number of the event being monitored as well as the total
duration of all of that event.

Once scraped you can then show things like the number of events over a
given period of time, as well as the average durations of those events
over that period. What you cannot do with a metric system is know
anything specific about an individual event. To do that you need an
event system, such as Loki, Elasticsearch or a SQL database.

--
Stuart Clark

Reply all
Reply to author
Forward
0 new messages