gpt4 book ai didi

prometheus - 设置 PromQL 值的格式

转载 作者:行者123 更新时间:2023-12-03 08:35:19 28 4
gpt4 key购买 nike

我使用此查询规则进行警报:

- 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%),我该怎么做?

enter image description here

感谢您阅读本文。

最佳答案

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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com