Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format PromQL values

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 ?

enter image description here

Thank you for reading this.

like image 386
Ngọc Bình Avatar asked Dec 07 '25 10:12

Ngọc Bình


1 Answers

Prometheus templating language is based on the Go templating system. There are many examples in the documentation.

In your specific case you would use:

 description: Host memory is {{ $value | printf "%.2f%" }}.

There are also some builtin functions in Prometheus that can be of interest like humanizePercentage:

- alert: HostOutOfMemory
  expr: (1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) > 0.9
  ...
  annotations:
    description: Host memory is {{ $value | humanizePercentage }}
like image 92
Michael Doubez Avatar answered Dec 09 '25 23:12

Michael Doubez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!