Using day_of_month() as time-vector

698 views
Skip to first unread message

bgut...@avarteq.de

unread,
Jun 29, 2018, 7:50:16 AM6/29/18
to Prometheus Users
Hi,

does anybody know if it is possible to somehow use the function `day_of_month()` as a time-vector, e.g. sum(<metric> [day_of_month()d]).
I already tried different ways of writing the query but the closest thing to a working query was `sum(<metric> [(day_of_month())])' which leads to a 'missing unit character in duration' error.

Any ideas on this topic?


Brian Brazil

unread,
Jun 29, 2018, 7:54:26 AM6/29/18
to Benjamin Guttmann, Prometheus Users
Can you tell us more about what you're trying to do? 

--

bgut...@avarteq.de

unread,
Jun 29, 2018, 8:12:05 AM6/29/18
to Prometheus Users
Hi Brian,

I am trying to create a recording rule the calculates a sum for the previous days of a month.
That means if we got the 12th of a month, I want to calculate the sum of the metric for these 12days.

So my idea was to get the current day of the month with the day_of_month function and somehow use this as the time-vector for my calculation. 

I hope this makes it a bit clearer. 

Brian Brazil

unread,
Jun 29, 2018, 8:42:13 AM6/29/18
to Benjamin Guttmann, Prometheus Users
That's not possible within PromQL. This sort of report generation is best done outside of Prometheus with a script pulling data via the API.

--

bgut...@avarteq.de

unread,
Jul 3, 2018, 5:13:46 AM7/3/18
to Prometheus Users
Hey,

thanks for your answer.
I found a solution to this problem but another one occurred that seems quite similar to me.
Is it possible to define a time interval between to points, that means instead of '1d' get the values betweens 00:00 - 23:59?

Thanks for your help.

Brian Brazil

unread,
Jul 3, 2018, 5:27:43 AM7/3/18
to Benjamin Guttmann, Prometheus Users
On 3 July 2018 at 10:13, <bgut...@avarteq.de> wrote:
Hey,

thanks for your answer.
I found a solution to this problem but another one occurred that seems quite similar to me.
Is it possible to define a time interval between to points, that means instead of '1d' get the values betweens 00:00 - 23:59?

If you ask for query endpoint for x[1d] at midnight the next day you'll get that. You'll need to discard the midnight point (if any) though as ranges are inclusive.

Brian
 

Thanks for your help.


Am Freitag, 29. Juni 2018 14:42:13 UTC+2 schrieb Brian Brazil:
On 29 June 2018 at 13:12, <bgut...@avarteq.de> wrote:
Hi Brian,

I am trying to create a recording rule the calculates a sum for the previous days of a month.
That means if we got the 12th of a month, I want to calculate the sum of the metric for these 12days.

So my idea was to get the current day of the month with the day_of_month function and somehow use this as the time-vector for my calculation. 

I hope this makes it a bit clearer. 

That's not possible within PromQL. This sort of report generation is best done outside of Prometheus with a script pulling data via the API.

--

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/52b91f8e-e50e-46a2-a24b-1028336c54d4%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Milon James

unread,
Mar 9, 2020, 3:25:43 AM3/9/20
to Prometheus Users
Hey, could you share how you managed to find a solution to this? I am stumbled upon a similar issue.
Reply all
Reply to author
Forward
0 new messages