grafanagrafana-loki

Grafana Dashboard with Loki to display a single number


Hi I have a Grafana Dashboard that I want to use to display the failed logs sent to Loki. The logs look something like this enter image description here

I have edited the query to show the sum of the number of error logs given on the interval and I have made a query like below

sum by (endpoint) (count_over_time({application="api-monitor"} |~ "status.*fail" [$__interval]))

enter image description here

I get a whole timeline even for the ones outside of the set intervals, when what I want is a single number that shows the total number of errors.

It would be deeply appreciated if you could tell me what is wrong and how I could fix my query to get the desired result.

Thank you in advance


Solution

  • To get a single number showing the total errors within a specific time range, rather than a timeline, you can tweak your query a bit. Instead of using intervals, try to specify a fixed time range, like the last hour, day or week.

    Here’s what I mean:

    sum(count_over_time({application="api-monitor"} |~ "status.*fail" [1h]))
    

    Here for instance, [1h] is the time range, so it counts all errors over the past hour.