How to round off value in Alert values?

I need to learn how to round of values ( mostly percentage values) to 2/3 decimals.

The alert step goes like this :

A: nodememoryMemAvailablebytes / nodememoryMemTotalbytes * 100
B: Reduce → Mean → (input) A
C: Math : $B < 50

Now, this reports the value in my slack alert as : 38.15013949954521

I’d like to round it off either two decimals (2) or round off to next integer.

I think this can be done via humanize or ceil functions. But i’m unable to follow where to even put that ?

I"m using Grafana V9 via docker.

2 Likes

Any help is appreciated.

@melori.arellano, Could you please help on this if possible ?

Solved. For anyone searching this in the future, use this in your alert description section :

Only {{ printf "%.2f"  $values.B.Value }} % memory is left on node {{ $labels.instance }}.
10 Likes

thank you for this solution!!

If you have a moment, how did you find it?

It was bit tough to find it in docs, mostly experimentation.

Hello, are you aware of how to turn off rounding up in Alerting at the time of querying in expressions? The solution you shared seems to be of the end result during templating.
Thanks