Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gauge & Bar Gauge & Stat Panel should have option to sort each series #17245

Open
Wing924 opened this issue May 23, 2019 · 39 comments
Open

Gauge & Bar Gauge & Stat Panel should have option to sort each series #17245

Wing924 opened this issue May 23, 2019 · 39 comments
Labels
area/dataviz Anything that relates to Data Visualisation work but is not specific to one panel area/panel/bargauge area/panel/gauge area/transformations type/feature-request

Comments

@Wing924
Copy link

Wing924 commented May 23, 2019

What would you like to be added:
Bar Guage looks very nice! It would be nice if we can sort the bar by titles and values.

Why is this needed:
The problem is that after auto refresh, the order of bars are changed.

@torkelo
Copy link
Member

torkelo commented May 23, 2019

We do not want to add sorting to each visualization as this is something better done in your query. We are looking at adding a data transform layer between query results and visualization and sorting could possibly go there

@torkelo torkelo closed this as completed May 23, 2019
@Wing924
Copy link
Author

Wing924 commented May 23, 2019

@torkelo

is something better done in your query

Prometheus can only sort by value and it can't sort by label name.

@mblaschke
Copy link
Contributor

@torkelo
please add such an option, currently it's jumping around with each reload.

@torkelo
Copy link
Member

torkelo commented Aug 3, 2019

Sort should be done in the query

@hafkensite
Copy link

We do not want to add sorting to each visualization as this is something better done in your query. We are looking at adding a data transform layer between query results and visualization and sorting could possibly go there

I can see that more visualizations would benefit from this, when can we expect this transform layer to be implemented?

@torkelo
Copy link
Member

torkelo commented Dec 4, 2019

in next 3-5 months

@talbz
Copy link

talbz commented Feb 13, 2020

ETA? :)

@basroovers
Copy link

Only seems to happen for Prometheus datasource when you group in your query:

100 - min by (mountpoint,customer,environment,filesystem,job,role,volumelabel)(wmi_cluster_disk_partition_freespace) / min by (mountpoint,customer,environment,filesystem,job,role,volumelabel)(wmi_cluster_disk_partition_totalsize) * 100

A simpler query doesn't produce the re-ordering every page reload:

wmi_cluster_disk_partition_freespace

@eraac
Copy link
Contributor

eraac commented Jun 3, 2020

Some datasources don't support order (ex. stackdriver).

That will be nice to order bar depending of the value. My use case is to order by the oldest message in pubsub subscription

@mroe1234
Copy link

mroe1234 commented Jul 8, 2020

Another example of how sorting in the visualization is helpful. Here is my flux:
from(bucket: "ntopng/autogen")
|> range($range)
|> filter(fn: (r) => r._measurement == "host:traffic" and (r._field == "bytes_rcvd") and (r.ifid == "$ifid"))
|> difference(nonNegative: true)
|> sum()
|> group()
|> top(n:10)
|> duplicate(column: "host", as: "_field")
|> group(columns: ["_field"])
|> drop(columns: ["_measurement","ifid", "host"])

The visualization requires I group by a field in order to properly show the data, however that creates 10 tables, and the visualization seems to display them in alphabetic by, in my case, "_field" rather in descending value order.

@dunxiii
Copy link

dunxiii commented Jul 17, 2020

Sort should be done in the query

Yes but even when prometheus returns a correct sorted list bar gauge does not use that sorting. So something break the sort along the way.

@bradbeam
Copy link

@dunxiii try switching the instant toggle, that let the sorting show up correctly for me

@torkelo
Copy link
Member

torkelo commented Jul 24, 2020

This should be implemented as a sort transform using new transform feature

@kolminux
Copy link

kolminux commented Sep 1, 2020

Very useful feature, seems like a "sort transform" despite the datasource in use is the best approach.
Is there an estimated version to release it?

@Vamic
Copy link

Vamic commented Nov 29, 2020

I'm using multiple data sources and applying the merge transform to combine them.
A sort transform would be fantastic so the results can be displayed in order.

@carpeliam
Copy link

This should be implemented as a sort transform using new transform feature

@torkelo Right now Transform is unable to sort by value; are you saying that Transform should support sorting by value in the future? We were hoping that using sort or sort_desc in our PromQL would result in a sorted bar gauge in Grafana, which we can see if we toggle Instant as others have mentioned, but this use case doesn't work for us currently.

@torkelo
Copy link
Member

torkelo commented Dec 15, 2020

If sort in query Grafana will use that sort order, could be that if you are using a transform like join or merge that your sort order will be lost however.

But if you are not using any Transform the order is determined by the query

@carpeliam
Copy link

@torkelo is that assuming that "Instant" is toggled to be on, or should that be true regardless of whether or not the query is regarded as "instant"? Here's a screenshot of a bar graph in Grafana 7.1.5 with no transformations applied, using the sort_desc function; only if I make this an instant query will the results be sorted.
image

@torkelo
Copy link
Member

torkelo commented Dec 15, 2020

The prometheus sort functions only work on instant vectors, there is no series sorting

@torkelo torkelo changed the title Bar Gauge should have option to sort each series Gauge & Bar Gauge & Stat Panel should have option to sort each series Jan 5, 2021
@dpnbp
Copy link

dpnbp commented May 19, 2021

I'd like for the bar gauge specifically to have a sort by property.

The "Sort By" transformation doesn't work on data that is in multiple data frames and the bar gauge panel doesn't display data that is in a single data frame so right now I can't get both of these features to work together to get a sorted bar gauge visualization.

(The table panel in conjunction with the reduce/series-to-rows transformation is a work around but it doesn't have the same dynamic display capabilities that the bar gauge panel has).

@maththedude
Copy link

maththedude commented Jun 22, 2021

@torkelo

We do not want to add sorting to each visualization as this is something better done in your query.

I am currently displaying the output of an expression. It is table data, not timeseries. If there is a way to get that output sorted by value, I am not aware of it.

@kong62
Copy link

kong62 commented Jun 29, 2021

image
can not disable full legend name

@torkelo
Copy link
Member

torkelo commented Jun 29, 2021

you can use the Sort by transform to sort data

@spxie85
Copy link

spxie85 commented Aug 16, 2021

There isn't an option to Sort by Value using Transform tab, and Grafana does not appear to obey the query's ORDER BY rules.

@gabzim
Copy link

gabzim commented Sep 6, 2021

image

if something like this would help (I know it's not as nice/smooth as a bar gauge) I got this to work by using a table, then using an override to make the field with the value into a cell display mode: gradient gauge (you can also do LCD gauge)

Here's one a little more similar to your example:

image

@albrechtflo-hg
Copy link

To make clear what multiple people already have said, of course has such a sorting to be done in the Panel. Please note that the panel does perform a calculation (it even is labelled "Calculate") when it e.g. takes the "last" value of each series. So, if you want to order by that calculated value, this is the correct place to do it.

@justinTM
Copy link
Contributor

justinTM commented Oct 5, 2021

figured it out. using sort() function in query fails silently unless you override Instant toggle to true.

jelly added a commit to jelly/cockpituous that referenced this issue Feb 11, 2022
The panel is a bar gauge which lists the slowest tests overall as
filtering is currently not possible. For filtering per project to work
we need to introduce a new metric which has a label for every project we
have. As label_values(top_failures_pct, project) is not the same as
label_values(top_slowest_tests, project).

The second issue is that a bar gauge can't be sorted correctly this is a
Grafana limitation. grafana/grafana#17245
jelly added a commit to jelly/cockpituous that referenced this issue Feb 11, 2022
The panel is a bar gauge which lists the slowest tests overall as
filtering is currently not possible. For filtering per project to work
we need to introduce a new metric which has a label for every project we
have. As label_values(top_failures_pct, project) is not the same as
label_values(top_slowest_tests, project).

The second issue is that a bar gauge can't be sorted correctly this is a
Grafana limitation. grafana/grafana#17245
martinpitt pushed a commit to cockpit-project/cockpituous that referenced this issue Feb 11, 2022
The panel is a bar gauge which lists the slowest tests overall as
filtering is currently not possible. For filtering per project to work
we need to introduce a new metric which has a label for every project we
have. As label_values(top_failures_pct, project) is not the same as
label_values(top_slowest_tests, project).

The second issue is that a bar gauge can't be sorted correctly this is a
Grafana limitation. grafana/grafana#17245
@jgagnon44
Copy link

jgagnon44 commented Jun 15, 2023

I tried sorting the result in the PromQL and it does sort as needed there ... but that sorting is ignored once displayed in the bar gauge in Grafana.
The "sort by" transformation does not allow for the value to be selected, which is what I need to sort by.
Why has this not been thought of?

@torkelo
Copy link
Member

torkelo commented Jun 15, 2023

@jgagnon44 strange, the Bar gauge panel does no sorting, so should display the data in the same order it's coming from the query

@supilee supilee added the area/dataviz Anything that relates to Data Visualisation work but is not specific to one panel label Jun 17, 2023
@BigOneDroum
Copy link

Ok I find a solution :

1 - Make a Table
2 - In the "transform" select the fields you want to display an use the "Sort by" on the value you want to sort.
3 - Overrinde the feild you had sort and "Cell options =>Cell type" select Gauge

I use grafana 10

@govindrai
Copy link

Something doesn't add up. if I use sort_desc on my query and promql returns results sorted by value, why would the guage go out of it's way to display results differently?

@HighPriest
Copy link

Here is my solution.
The most important settings are for the query: "Table" & "Instant".
For the panel: Value Options->All Values & Value Options->Fields: the metric you are interested in.

Then we can sort by the metric.
Panel code:

{
  "datasource": {
    "type": "prometheus",
    "uid": "cae1b9fc-5054-4994-bdcc-299ae73ca914"
  },
  "fieldConfig": {
    "defaults": {
      "mappings": [],
      "thresholds": {
        "mode": "percentage",
        "steps": [
          {
            "color": "red",
            "value": null
          },
          {
            "color": "#EAB839",
            "value": 90
          },
          {
            "color": "green",
            "value": 100
          }
        ]
      },
      "color": {
        "mode": "thresholds"
      },
      "decimals": 0,
      "links": [
        {
          "targetBlank": true,
          "title": "http://${__data.fields.instance}",
          "url": "http://${__data.fields.instance}"
        }
      ],
      "max": 172800000,
      "min": 0,
      "unit": "ms"
    },
    "overrides": []
  },
  "gridPos": {
    "h": 8,
    "w": 3,
    "x": 16,
    "y": 6
  },
  "id": 14,
  "options": {
    "reduceOptions": {
      "values": true,
      "calcs": [
        "lastNotNull"
      ],
      "fields": "/^Value$/"
    },
    "orientation": "horizontal",
    "displayMode": "gradient",
    "valueMode": "color",
    "showUnfilled": true,
    "minVizWidth": 0,
    "minVizHeight": 10
  },
  "pluginVersion": "10.1.1",
  "targets": [
    {
      "datasource": {
        "type": "prometheus",
        "uid": "cae1b9fc-5054-4994-bdcc-299ae73ca914"
      },
      "editorMode": "code",
      "exemplar": false,
      "expr": "sysUpTime{job=\"SNMP\"}",
      "format": "table",
      "instant": true,
      "interval": "",
      "legendFormat": "__auto",
      "range": false,
      "refId": "A"
    }
  ],
  "title": "Switch_Uptime",
  "transformations": [
    {
      "id": "sortBy",
      "options": {
        "fields": {},
        "sort": [
          {
            "field": "Value"
          }
        ]
      }
    }
  ],
  "type": "bargauge"
}

@sd-matt-b
Copy link

sd-matt-b commented Nov 2, 2023

Something doesn't add up. if I use sort_desc on my query and promql returns results sorted by value, why would the guage go out of it's way to display results differently?

If you tried a sort_desc query in the Prometheus UI, it will force the query to use instant vectors. To prove this, paste that query into the Grafana panel and turn the "instant" toggle on. Refresh and you should see your results are sorted. These results should 1:1 match the results in the Prometheus UI even if you're not explicitly using instant vectors in the Prometheus UI. Toggling the "instant" toggle off in your panel, and then refreshing, would probably show more accurate values based on how your query was written verbatim.

I'm frustrated that there's no functionality built into Grafana to help me sort the results of a non-instant vector query with Prometheus! It's right there, it feels so close to what I want -- but the information I really need is obscured when using instant vectors!

@kuzdogan
Copy link

kuzdogan commented Dec 4, 2023

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

image

@geira
Copy link

geira commented Apr 19, 2024

In Time Series panels, users can sort interactively by name, mean, max and whatever other columns are present. It would be natural to expect similar functionality for bar graphs/gauges as well, instead of only one fixed sort order. For day-to-day operations it would e.g. be convenient to sort by max disk usage percentage, but when trying to find a specific server you might want to change to alphabetical sorting by server name.

@AK00077
Copy link

AK00077 commented Jun 12, 2024

Here's a really easy way to do this in the Bar gauge visualization. Under Query settings, click on Functions + Filter > TOP. To include all values, click precisely on top of number '5' in the new function once it's added, then change it to something that exceeds all possible values, like 100. Done!

grafana-sort-1

grafana-sort-2

@shufps
Copy link

shufps commented Aug 8, 2024

after trying to sort via transforms I figured out that it just works by adding sort_desc(...) to my prometheus query 🥳

Not sure why SortBy Transform didn't give me any option to sort by value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dataviz Anything that relates to Data Visualisation work but is not specific to one panel area/panel/bargauge area/panel/gauge area/transformations type/feature-request
Projects
None yet
Development

No branches or pull requests