PromQL query to sort by numbers

613 views
Skip to first unread message

Tom005

unread,
Nov 30, 2020, 6:52:28 AM11/30/20
to Prometheus Users
I have a metric that I'd like to sort by numbers.
Currently it is sorted like this:
0, 1, 11, 12, 13... 2, 20,21... etc.
I'd like it to go like this:
0, 1, 2, 3, 3...10, 11, 12... etc.

Is that possible?
Thanks 

Stuart Clark

unread,
Nov 30, 2020, 7:27:25 AM11/30/20
to Tom005, Prometheus Users
How do you mean you have a metric sorted like that?

Do you mean that you have a metric with the given values for a
particular time period?

Or are you referring to the value of one of the metric's labels?

Tom005

unread,
Nov 30, 2020, 8:06:58 AM11/30/20
to Prometheus Users
Sorry, yeah I actually meant the metric labels, I'd like to sort from the metric label in that order.

Stuart Clark

unread,
Nov 30, 2020, 8:29:59 AM11/30/20
to Tom005, Prometheus Users
On 30/11/2020 13:06, Tom005 wrote:
> Sorry, yeah I actually meant the metric labels, I'd like to sort from
> the metric label in that order.
>
How data is displayed is up to whatever system is doing the API query.
For example Grafana has various sort options.

Tom005

unread,
Nov 30, 2020, 8:31:54 AM11/30/20
to Prometheus Users
Right, I am using grafana to display. Is there a way to do that do you know? 
Appreciate that it might be going slightly off topic away from Prometheus. 

Stuart Clark

unread,
Nov 30, 2020, 8:38:12 AM11/30/20
to Tom005, Prometheus Users
On 30/11/2020 13:31, Tom005 wrote:
> Right, I am using grafana to display. Is there a way to do that do you
> know?
> Appreciate that it might be going slightly off topic away from
> Prometheus.
>
Exactly how you do it will depend on the visualisation you are using and
the version. For example for a table you can use the transform options
to convert labels into fields and decide what to show, click on the
field to sort. You can also set the default sorting.

Tom005

unread,
Nov 30, 2020, 8:44:35 AM11/30/20
to Prometheus Users
Ok yeah, I can see that and I can do that. 
I'm actually using the graph visualisation though, which I need. Is there a way to sort from that? 

Stuart Clark

unread,
Nov 30, 2020, 9:02:44 AM11/30/20
to Tom005, Prometheus Users
On 30/11/2020 13:44, Tom005 wrote:
> Ok yeah, I can see that and I can do that.
> I'm actually using the graph visualisation though, which I need. Is
> there a way to sort from that?
>
I'm not an expert, so you might be better asking the Grafana people, but
google does mention how to do it via the JSON, but I'm sure there is a
way in the UI:

https://github.com/grafana/grafana/issues/2640#issuecomment-606012950

Julien Pivotto

unread,
Nov 30, 2020, 9:13:07 AM11/30/20
to Stuart Clark, Tom005, Prometheus Users
That kind of sort is on the roadmap but it will still take a few time
before we have it.
> --
> You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/f4451964-3c3d-af4b-f406-4bb58597f516%40Jahingo.com.

--
Julien Pivotto
@roidelapluie

Tom005

unread,
Nov 30, 2020, 9:22:41 AM11/30/20
to Prometheus Users
Ok thanks guys. It's a bit annoying I will say. 
My use case is that I'm monitoring CPU cores, and it goes 0, 1, 10, 11 which is just annoying as I said. 
Look forward to the release. 

Reply all
Reply to author
Forward
0 new messages