Topk Values in Logql

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

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.

Elena Rostova
Author

Elena Rostova

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.