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

Sort series on X axis #13325

Open
bobrik opened this issue Sep 18, 2018 · 11 comments
Open

Sort series on X axis #13325

bobrik opened this issue Sep 18, 2018 · 11 comments

Comments

@bobrik
Copy link
Contributor

bobrik commented Sep 18, 2018

What Grafana version are you using?

5.2.3

What datasource are you using?

Prometheus

What did you do?

Set Graph X axis mode to "Series" to see CPU load distribution between cores.

What was the expected result?

Cores are sorted by their name: cpu00, cpu01, ..., cpu31

What happened instead?

Cores are randomly sorted on each refresh:

image

image

Query is:

(avg(sum(rate(node_cpu{instance="$instance", cpu=~"$cpu", mode=~"$mode"}[$rate])) without (mode)) without (instance), "cpu", "cpu0$1", "cpu", "cpu(.)")

If X axis is time, then the legend is sorted properly:

image

@torkelo
Copy link
Member

torkelo commented Sep 19, 2018

The order in which series are drawn is the same as the order returned by your Prometheus query, you need to sort your series in your query.

@torkelo torkelo closed this as completed Sep 19, 2018
@bobrik
Copy link
Contributor Author

bobrik commented Sep 19, 2018

That's a great idea, do you know a way to do it? From what I can tell, Prometheus doesn't support it:

@bobrik
Copy link
Contributor Author

bobrik commented Sep 19, 2018

Apparently sorting in Grafana works if Instant is unchecked, but it's quite wasteful in terms of compute power.

@bobrik
Copy link
Contributor Author

bobrik commented Sep 25, 2018

@torkelo can this be reopened?

@josephine-rueckert
Copy link

@torkelo sorting by anything other than the value is still not supported in PromQL and from what I read in the following issue, it doesn't seem like they want to add this as they think this is a presentation feature which should rather be available in Grafana.

I'd rather implement UI/presentation related features twice in graph consoles and grafana than cluttering PromQL and fighting an endless battle about what to add and what not "sort_by_label is already part of the language, there my alias() function makes sense as well".
prometheus/prometheus#1533

@mtanda
Copy link
Collaborator

mtanda commented Feb 7, 2020

I check the Prometheus implementation, it only sort series for range query.
https://github.com/prometheus/prometheus/blob/v2.15.2/promql/engine.go#L516

Prometheus need to support topk, it shouldn't sort for instant query.

@superawesome
Copy link

Bumping this for visibility. This would be very useful, as Prometheus has closed the PR linked above without merging it. It appears they believe Grafana should implement this sort of functionality.

@kesor
Copy link

kesor commented Oct 29, 2020

Sorting data of a time series in the Prometheus query sorts each time bucket returned from Prometheus. But when the X-Axis is set to "Series" with a "Total" aggregation function (part of Grafana) it is not really possible to sort this in the query like this.

Copy link
Contributor

This issue has been automatically marked as stale because it has not had activity in the last year. It will be closed in 30 days if no further activity occurs. Please feel free to leave a comment if you believe the issue is still relevant. Thank you for your contributions!

@github-actions github-actions bot added the stale Issue with no recent activity label Jan 19, 2024
@Roemer
Copy link

Roemer commented Jan 19, 2024

This is still relevant I suppose.

@bobrik
Copy link
Contributor Author

bobrik commented Jan 19, 2024

Prometheus gained support for label sorting for instant queries:

I also added natural sorting there:

I haven't tested it with Grafana, but it might just work these days.

@github-actions github-actions bot removed the stale Issue with no recent activity label Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants