我使用这个查询规则来发出警报:
- 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 }}%"但是这个值是浮动(PromQL的缺省值),我想格式化它(下面的图片,我可以更改它只显示90%),我怎么做呢?

谢谢你读这篇文章。
发布于 2020-09-21 12:21:51
Prometheus模板语言是基于Go模板系统的。有许多文档中的示例。
在您的具体情况下,您可以使用:
description: Host memory is {{ $value | printf "%.2f%" }}.普罗米修斯中也有一些可以引起人们兴趣的内置函数,比如humanizePercentage。
- alert: HostOutOfMemory
expr: (1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) > 0.9
...
annotations:
description: Host memory is {{ $value | humanizePercentage }}https://stackoverflow.com/questions/63987446
复制相似问题