'Prometheus query to return Top 5 results

I am running a diskspace used query in Prometheus and would like to return only the top 5 or 10 entries from the search result. Is there anyway I can achieve that?

Currently, the query I am trying is returning me 58 entries

(100 - 100 * (node_filesystem_avail{device!~"by-uuid",device!~"tmpfs",mountpoint="/"} / node_filesystem_size{device!~"by-uuid",device!~"tmpfs",mountpoint="/"})) > 70




Solution 1:[1]

Just add topk(5, ...) in your query:

topk(5, (100 - 100 * (node_filesystem_avail{device!~"by-uuid",device!~"tmpfs",mountpoint="/"} / node_filesystem_size{device!~"by-uuid",device!~"tmpfs",mountpoint="/"})) > 70)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marcelo Ávila de Oliveira