grafanaprometheuspromql

Display table for series with label's occurrence count greater than N in Prometheus


In Prometheus, given below metric definition, how do I render a table for top 5 recurring devices part of the metric series?

top_5_noisy_devices:

    { "device" : "1234", "type" : "foo"}
    { "device" : "1234", "type" : "foo"}
    { "device" : "1234", "type" : "foo"}
    { "device" : "2345", "type" : "foo"}
    { "device" : "4231", "type" : "foo"}
    { "device" : "4354", "type" : "foo"}

I want to render a table in Grafana for the above labels to show that device 1234 is the noisy device in the selected time duration. I tried topk operator but it renders more than 3. ( I see 100's of rows in table instead of just 3) https://www.robustperception.io/graph-top-n-time-series-in-grafana claims to support topk in Grafana. But I fail to understand how to adapt it to a table.


Solution

  • I used below approach to display a table.

    topk(5,round(increase(top_5_noisy_devices{type="Foo"}[$interval])))

    enter image description here

    enter image description here

    And selecting any interval dropdown using the variables fetches the topk data for the specific period. enter image description here