Search code examples
loggingmonitoringgrafanagrafana-lokilogql

Grafana Loki total number of a specific log message


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.


Solution

  • 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