Templating last value of metric into alert message

Hello Everyone!

I have a following query in my alert:

100 -
(
  avg(node_memory_MemAvailable_bytes{job="node-exporter", instance="211.111.11.111:9111"}) /
  avg(node_memory_MemTotal_bytes{job="node-exporter", instance="211.111.11.111:9111"})
* 100
)

And my query in alert and condition looks like this(look at image):

I want to have a following alert text: Instance 211.111.11.111:9111 has 60 point of Memory Usage when Threshold is 50. Investigate the problem
So I want to template instance ip and last value of Memory Usage right now,
I have tried to use {{ $values.B }} and it resulted in .
Only success I had when using {{ $value }} and as output I got this information:

Instance 211.111.11.111:9111 has [ var='B0' metric='100 -
(
 avg(node_memory_MemAvailable_bytes{job="node-exporter", instance="211.111.11.111:9111"}) /
 avg(node_memory_MemTotal_bytes{job="node-exporter", instance="211.111.11.111:9111"})
* 100
)
' labels={} value=41.96771814524034 ] % of Memory Usage. Investigate the problem

And out of this I need to get value=41.96771814524034

Any help is appreciated. Thanks!

Hi @coderuslan,
Try this:

{{ $values.B.Value }}

If you want to print only 1 decimal:

{{ printf "%.1f" $values.B.Value }}

Additionally, check links below:

Best regards,
ldrascic

Hi @ldrascic ldrascic I have tried using
{{ $values.B.Value }}
But it has resulted in < no values > message being show, thank you for additional links I will also look into them.

Kind Regards

I guess it makes difference if you are using Reduce (like in my example) or Classic condition (your example). Try solution that was proposed in next answer:

{{ $values.B0.Value }}

Also, the printf "%.1f" part does not work with classic condition :frowning: .

Hi! If it helps the documentation for this can be found here Templating labels and annotations | Grafana documentation, including for Classic Conditions