I am using Grafana and Loki to analyze logs from my application, and have used the Bar Gauge in a few places already.

This is my query:

sum(count_over_time({namespace=~"$namespace", job=~"$namespace-logs"} |= "KPIExecuted" [$__interval])) by (namespace)

And I get:

enter image description here

I was wondering whether I can sort the results based on the metric result? Or if there is an alternative I could use to achieve a similar outcome?

Thanks.

2

Best Answer


I had a bit different problem, but I think it might be helpful for somebody searching how to sort bars in bar chart.I have a table with queries from users and I wanted to find the most active users.Right solution:

SELECTcount(user_id) as "Количество запросов",CONCAT("vk.com/id", user_id) as "Пользователь"FROM strawberry.generated_dataWHERE unix_date>$since GROUP BY user_id ORDER BYcount(user_id) DESCLIMIT 20

My problem was that i was selecting time and bars so mixed

You can use a Sort Transform to do this.

Next to the Query Tab is a Transform Tab. Click that and choose Sort By. You will most likely sort by Value #A

Documentation is here https://grafana.com/docs/grafana/latest/panels/transformations/types-options/#sort-by