Marco Pracucci

Rounding values in Prometheus alerts annotations

by Marco Pracucci Comments

If you’re a Prometheus experienced user you already know you can pipe GO default templating functions in ANNOTATIONS.

We’re used to write human readable alerting messages as annotations, that frequently contain the current $value of the monitored metric. Today I started rounding $value using printf to avoid displaying floating point numbers with a long tail of decimals.

For example, the expression $value | printf "%.2f" will round it to two decimals. Feel free to adjust it with any number of desired decimals (ie. "%.1f" for a single decimal). The following alert configuration snippet shows a nearly real use case.

  IF a_metric_to_alert_on > 12345
    severity="error", team="frontend"
    firing   = 'The current value of metric is {{ $value | printf "%.2f" }}.'

You may also be interested in ...

Upcoming conferences

I will join the following conferences. Reach me out on Twitter if you wanna meet:
Incontro DevOps 2020 Virtual 22 October 2020