Grafana Loki LogQL bar gauge order by total
Asked Answered
L

3

10

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.

Lamothe answered 8/11, 2021 at 16:52 Comment(2)
ever found out?Elanorelapid
When I have an answer I will add it in this post.Lamothe
A
0

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

Ascospore answered 28/7, 2023 at 13:34 Comment(0)
O
0

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

Orthocephalic answered 4/12, 2023 at 14:15 Comment(0)
M
-2

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

Meandrous answered 4/2, 2022 at 20:18 Comment(2)
It is not working :(Lamothe
Unfortunately, this only works when the labels are the same value. But when you have different labels there, you can't sort them by the bar values.Suited

© 2022 - 2024 — McMap. All rights reserved.