Format PromQL values

Hello,

i use this query rule for alert:

- alert: HostOutOfMemory

    expr: (1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) * 100 > 90

    for: 5m

    labels:

      severity: warning

    annotations:

      summary: "{{ $labels.name }} out of memory "

      description: "Host memory is {{ $value }}%"

But the value is float (default of PromQL), i want to format it (the picture below, can i change it to show only 90%), how can i do it ?

image

Thank you for reading this.

Take a look at this: https://prometheus.io/docs/prometheus/latest/configuration/template_reference/#numbers

humanizePercentage might be the best, but then you have to leave out the 100.

You can also use standard Go templating tools, like printf.

{{ printf "%.1f" $value }}% would print with one decimal place after the dot.

1 Like

thank you, have a nice day man