Topk values in LogQL

I need some help with Loki. I`ve got json logs like following

{"message": {"reason": "reason1"...}}
{"message": {"reason": "reason2"...}}

And I need to print top N reasons. How can I do this?

1 Answer

Try the following LogQL

topk(N, sum by (reason) (count_over_time({filename="xxxxx"} | json [1d])))
5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like