我使用此查询规则进行警报:
- 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 }}%"
但是该值是float(PromQL的默认值),我想对其进行格式化(如下图,我可以将其更改为仅显示90%),我该怎么做?
感谢您阅读本文。
最佳答案
Prometheus 模板语言基于 Go templating system 。有很多examples in the documentation .
根据您的具体情况,您将使用:
description: Host memory is {{ $value | printf "%.2f%" }}.
Prometheus 中还有一些可能令人感兴趣的内置函数,例如 humanizePercentage
:
- alert: HostOutOfMemory
expr: (1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) > 0.9
...
annotations:
description: Host memory is {{ $value | humanizePercentage }}
关于prometheus - 设置 PromQL 值的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63987446/