0

In a Kubernetes cluster, we're using Grafana and Prometeus for monitoring. We're trying to get memory usage per node and sort it alphabetically based on node name.

To do that I'm using the following PromQL query :

(1 -
  (node_memory_MemFree_bytes +
   node_memory_Cached_bytes +
   node_memory_Buffers_bytes) / node_memory_MemTotal_bytes
) * on(instance) group_left(nodename) node_uname_info

However, after adding the sort() function to it, it never sorts it based on nodename, but on instance.

How can I sort it alphabetically based on nodename? If it is at all possible...

  • 1
    [`sort`](https://prometheus.io/docs/prometheus/latest/querying/functions/#sort) is based on value, not labels. Why do you even need sorting if you're using Grafana? – markalex Apr 27 '23 at 16:49
  • The question has been asked before and the tl;dr is that it is not possible as this answer states: https://stackoverflow.com/a/65353296/6336357 However, the position of the prom maintainers seems to have softened a bit and you might get lucky in the future with the following PR https://github.com/prometheus/prometheus/pull/11299 Feel free to contribute there to move it forward. The community is usually very open and welcoming. – Rick Rackow Apr 27 '23 at 17:35

0 Answers0