Value map for !=0

Hello.

I’m trying to create a simple visualization that displays either the word “Success” or “Failure”. I’m using value mappings in a stat panel. When the value is 0, it properly displays the text “Success”. For the 2nd mapping, I would like “not equal zero” to catch any other value and display text “Failure”. Instead, displays the numeric value.

I set:


And for value 0 I get:

But for any value other than 0, I get the original unmapped value:

I’m likely missing something obvious. Any/all help is appreciated.

Peace.

  • What Grafana version and what operating system are you using?
    Version 11.4.0
    Ubuntu 22.04

  • What are you trying to achieve?
    A a “stat” visualization with value-mapping where:
    Value 0 Success
    Value !=0 Failure

  • How are you trying to achieve it?
    I have tried value mappings of:
    Value !=0
    Regex [^0]+
    Regex *

  • What happened?
    It displays the number of the value, not the display text setting of “Failure”. My mapping for “Value = 0” does display the text “Success”.

  • What did you expect to happen?
    Display either the text “Success” or “Failure”

  • Can you copy/paste the configuration(s) that you are having problems with?
    See photos above

  • Did you follow any online instructions? If so, what is the URL?
    Configure value mappings | Grafana documentation

1 Like

try range value 1 to 99999999999999999999999999

does it also include negative values below 0?

I saw “range”, and that could work absent the real logic I’m hoping for. “From 1 to infinity” is not the same as “not equal zero”. What if the value ends up being nonsense? Or non-numeric garbage?

It is also possible that I’m an old BOFH, and should just let this go :slight_smile:

Au contraire mon amie! So you use Value map for !=0 and value = 0 but now you object with what if it is non numeric? :wink: Simon Travaglia objects!

Did you try Regex?

1 Like

I did try regex, yes. Strange, I’m getting different behavior than you are.

Exact same regex, but for me it displays the vale, un-mapped. I’m using Version 11.4.0.

please share your raw datasource, obfuscated if needed

The data is coming from Prometheus’ textfile collector. I have placed the following file:

root@mynode:/var/lib/node_exporter/textfile_collector# cat job_exit_status.prom
job_exit_status 127

Prometheus sees it as:

1 Like

so the value 127 is numeric so the regex is not happy. if the value is ‘127’ string it works. so maybe that [^0]+ works purely on string values?

I tried on numeric values (see Table view):

mapping

1 Like

If I add single or double quotes to the value in my .prom file, prometheus no longer picks up the metric:

cat job_exit_status.prom

job_exit_status '127'

I then get in Prometheus:

Also, fwiw, I am able to set an alert with the logic that I want:


That will fire on anything that is “not zero”.

For additional info. I have also set:

I have also toggled the “Unit” between Misc/Number and Misc/String. Either way, it still displays “127”.