Grafana Loki LogQL bar gauge order by total

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.

Upvotes: 10

Views: 3834

Answers (3)

kuzdogan
kuzdogan

Reputation: 835

If you were doing the same thing as me, the problem was you had a reduced Total each in a different table.

Instead you need to reduce different tables (ie. labels) into a single table with a "Series to Rows" reducer and sort with the "Total" field

Transformation

Upvotes: 0

Adefe
Adefe

Reputation: 1

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:

SELECT
  count(user_id) as "Количество запросов",
  CONCAT("vk.com/id", user_id)  as "Пользователь"
FROM 
  strawberry.generated_data
WHERE 
  unix_date>$since 
GROUP BY 
  user_id 
ORDER BY
  count(user_id) DESC
LIMIT 20

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

Upvotes: 0

TXMikeD
TXMikeD

Reputation: 11

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

Upvotes: -2

Related Questions