Alert Thresholds

I have been trying to figure this out for a while and I have gotten to this point. My query is working fine and my expressions are showing the correct data:

In my labels I have the following:

{{if gt $values.C.Value 90 }}Critical{{else}}Warning{{end}}

I have also tried:

{{ $v := $values.C.Value }}{{ if gt $v 90 }}Critical{{ else }}Warning{{ end }}

I also have this matching in my notifications policy:

No matter which way I go I get the following in the subject of my email:

[FIRING:2] Memory Internals ({{if gt $values.C.Value 90 }}Critical{{else}}Warning{{end}})

And my priority label shows the following:

{{if gt $values.C.Value 90 }}Critical{{else}}Warning{{end}}

How do I get this to display right?

I know it’s got to be something simple I’m missing

Hi! This is an issue that other people have run into and is not in our docs at this time.

The issue is that $values contains floating point numbers, and Go’s text/template does not do type coercion. That means that comparing the value to an integer returns an error. It’s very frustrating.

You should change your template to compare to a float64 too, then it should work:

{{if gt $values.C.Value 90.0 }}Critical{{else}}Warning{{end}}
1 Like

Okay so I am putting it here and here?

Aha! I figured it out! Your line didn’t work the first time. I was pulling my hair out and then I thought it might be spacing. So I did the following:

{{ if gt $values.C.Value 90.0 }}Critical{{ else }}Warning{{ end }}

The spacing between brackets caused an error as well. Added spacing and BAM!


Thank you!

I’ve created a pull request to update on docs for this Docs: Update docs on comparisions with $values by grobinson-grafana · Pull Request #74156 · grafana/grafana · GitHub.

1 Like