This got me confused for a few hours, i already found my answer but wanted to ask if this correct.
I have a metric that is always 1 in value, or null.
the metric has 2 labels, id and name.
So in grafana wanted to graph in a stat panel the label values when the metric is 1.
metric{id="$id"}
Legend: {{id}} - {{name}}
If the metric is null, i wanted to show “Not connected”, there is no way in grafana to use label values outside of the Legend for the query as far as i know, and the Value of the metric has to be hidden, so we are stuck with legends.
I made another query to do the inverse, basically, return null if query is 1, and return 0 if query is null.
After spending some time i come up with this, works but
(metric{id="$id"} default 0) == 0
Legend: "Not Connected"
My question is why can’t we check for nulls
, like (nil if (metric{id="$id"} == 1)) default 0
, or (0 if (metric{id="$id"} == nil) default nil
seems more descriptive to me, don’t know id there is another way to do it out of curiosity.
4
(metric{id="$id"} default 0) == 0
Legend: "Not Connected"
Returns 0 only if query is null. else returns null if the metric returns 1.