I am trying to build Grafana dashboard representing the number of info logs in Loki (not in Prometheus). Basically, I would like to achieve this:
I searched around and it seems it is possible to build those with Prometheus metrics, using the logback_events
metrics from Prometheus.
Actually, the dashboard above is using Prometheus data, using the logback_events
not Loki data.
However my application is not sending any metrics, just logs to Loki. Therefore, I cannot rely on metrics of type logback_events
to build this dashboard.
Where a sample log looks like:
{
"name": "mycoolapp"
"pid": "1",
"level": "INFO",
"thread": "somethread",
"class": "SomeClass",
"traceId": "6170ea9877f59d050a13feaffc145d88"
"spanId": "6729eec142171c8f"
"message": "somecoolmessage"
}
Is there a way to get the number of info, error, warn, and debug logs from Loki? How to build a similar dashboard using Loki (not Prometheus) data?
With query like this, you can create graph for number of log entries per level.
sum by(level)(
count_over_time(
{<your_usual_stream_selector>}
| json
[$__interval]
)
)
If you need only number of messages with level INFO
you can add filter after | json
, like this: | json | level = "INFO"
.
Please notice, that here {<your_usual_stream_selector>}
is a placeholder for your actual stream selector. It depends on your setup and dashboard configuration. In the simplest case it might be something like {host="example.com"}
or {filename="log.json"}
.