Then I think that's a feature request for Grafana.  Prometheus is just the 
data source; the client (Grafana in this case) is responsible both for 
issuing the correct query and visualising the results.

On Wednesday, 5 October 2022 at 14:32:22 UTC+1 fiala...@gmail.com wrote:

> Thank you for tips but I'm still not sure, how to handle this.
>
> I'm using my query in grafana where I want to display table with highest 
> power usage in current calendar month. So I'm not able to calculate 
> constants like 10 (October), or timestamps and I dont want to change it 
> every month.
>
> On Wednesday, October 5, 2022 at 3:11:06 PM UTC+2 Brian Candler wrote:
>
>> Another option is to use the @ modifier 
>> <https://prometheus.io/docs/prometheus/latest/querying/basics/#modifier> 
>> to specify the exact execution time of the query, giving the end of the 
>> month as the timestamp.  This is now available by default in recent 
>> versions of prometheus (v.2.33.0+), but before that it was hidden behind a 
>> feature flag.
>>
>>     max_over_time(rack_max_power_watts{job="Max power on path 
>> /racks/max-power"}[4w] *@ 1667260800*)    # up to midnight on Nov 1st
>>
>> However, it's still up to you to calculate the execution time before 
>> running the query.  It won't work out "the current month" for you.  Also, a 
>> month isn't exactly 4 weeks; for October you'd want
>>
>>     max_over_time(rack_max_power_watts{job="Max power on path 
>> /racks/max-power"}*[31d]* @ 1667260800)
>>
>> On Wednesday, 5 October 2022 at 13:10:05 UTC+1 juliu...@promlabs.com 
>> wrote:
>>
>>> Hi,
>>>
>>> When you say "current month", I guess you care about the time window 
>>> starting exactly at the beginning of the calendar month, not an arbitrary 4 
>>> weeks ago?
>>>
>>> In that case, you would have to manually choose the time window just 
>>> large enough (relative to the overall query evaluation timestamp) to only 
>>> go back exactly to that time.
>>>
>>> There's also a complex construct you could write using a subquery to 
>>> select a rack power output only for those timestamps within the subquery 
>>> that fall into a given month, but I'm not sure you want to go that far, and 
>>> it introduces other potential issues, such as skipping over raw underlying 
>>> values in case you don't choose the subquery resolution high enough. It's 
>>> also more expensive.
>>>
>>> In any case, I'm thinking of something like:
>>>
>>> round(
>>>   max_over_time(
>>>     (
>>>
>>>         rack_max_power_watts{job="Max power on path /racks/max-power"}
>>>       and on()  # Filter rack power watt values down to only those from 
>>> October
>>>         month() == 10
>>>     )[5w:]
>>>   )
>>> )
>>>
>>> ...where 10 is the current month (October) and the 5w window is chosen 
>>> generously to always cover at least a full month going backward from now.
>>>
>>> Cheers,
>>> Julius
>>>
>>> On Wed, Oct 5, 2022 at 10:27 AM fiala...@gmail.com <fiala...@gmail.com> 
>>> wrote:
>>>
>>>> Hi,
>>>>
>>>> It is possible to get maximum value in current month?
>>>>
>>>> My query is:
>>>> round((max_over_time(rack_max_power_watts{job="Max power on path 
>>>> /racks/max-power"}[4w])
>>>>
>>>> Thank you.
>>>>
>>>> -- 
>>>> 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-use...@googlegroups.com.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/prometheus-users/11446946-70b1-4d49-a411-8f0cc8df735en%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/prometheus-users/11446946-70b1-4d49-a411-8f0cc8df735en%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>
>>>
>>> -- 
>>> Julius Volz
>>> PromLabs - promlabs.com
>>>
>>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/1b71b066-e140-441f-8b5e-0a672d0d82c5n%40googlegroups.com.

Reply via email to