prometheusgrafanagrafana-variable

ignore N/A or None


I am using Grafana and Prometheus. How do we exclude N/A or None from the list of values of a variable? The data will be something like

N/A
ABC-100
XYZ-200
123ABC
None
456-DGZ

I need just need to display all values other than N/A and None i.e. display only

ABC-100
XYZ-200
123ABC

I looked at Regexp & Grafana: exclusions and string cut I tried ^(?!N\/A).* enter image description here It did not work.


Solution

  • This situation can be approached from two directions:

    1. Remove undesired labels on Prometheus' side.
      Depending on situation, this might be implemented in a couple ways. In the simplest case, where you extract values of label my_label from metric my_metric, you can use query
    my_metric{my_label!="N/A", my_label!="None"}
    

    Demo of similar query here.

    1. Remove undesired labels on Grafana's side.
      As you mentioned yourself for this regex with negative lookaround should be used.
      Expression /^(?!None$|N\/A$).+/ will filter out values None and N/A leaving all others as is. enter image description here