I need to set up an grafana alert that counts the logs from 00:00 to the current time. Unfortunately, I can’t use now/d
in the Grafana alert time range. Could anyone assist me with the Loki LogQL query to achieve this?
This is not possible. The query can be only configured with a relative interval, for example now-10m
(you can change that but it must be relative). Then during the evaluation of the rule the relative interval is transformed into absolute, where now
is the tick time.
For now, it’s not possible to control the time when rule is evaluated.
1 Like
Hi @yuriy.tseretyan Thanks for your reply . Is there any possibility to set time range 00:00 to current time in loki query .
No, it is not possible
1 Like
Thanks for your reply.
I think it’s possible. Of course it is not straightforward and you can use now/log time (.ts) formatted to day only and select only logs, which have logday=today.
Idea (not copy&paste solution) - fix any functional/syntax issues:
count(
rate(
{<selector>}
| label_format today=`{{ date "2006-01-02" now }}`
| label_format logday=`{{ date "2006-01-02" .ts }}`
| label_format match=`{{ eq .today .logday }}`
| match = `true` [$__auto]
)
)