Grafana Loki total number of a specific log message
Asked Answered
C

1

21

I am using Grafana Loki and I need to calculate the total number of a certain log message for a specific time interval. For example, I need the total number of log message "some-text" in the period from 12:00:00 to 14:00:00. I just found the following way to count the occurrences of the last minute, something this: count_over_time({container="some-containter"} |= "some-text")[1m], but i did not found any way to query a specific interval.

I would be very happy if this is possible and someone could help.

Cletus answered 13/6, 2022 at 18:25 Comment(1)
Side note: counting logs with the given text on the given [start..end] interval is easy to do in LogsQL: _time:[start, end] "some-text" | count()Encrust
I
37

If you're using Grafana Explore to query your logs you can do an instant query and use the time range and global variables.

So you can select the time range as seen in the screenshot below and your query would become count_over_time({container="some-container"} |= "some-text"[$__range])

You can check my example in the Grafana Playground. enter image description here

Inapposite answered 22/6, 2022 at 9:27 Comment(2)
example appears to have no data nowTawnatawney
If there was no data, how can we default the count to zero for the purpose of adding conditions for alert firing?Hopeless

© 2022 - 2024 — McMap. All rights reserved.