prometheus - 设置 PromQL 值的格式

标签 prometheus slack promql

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

- 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/

相关文章:

docker - 如何更改Prometheus监控的cadvisor和node-exporter中的端口号

docker - cAdvisor prometheus 集成将 container_cpu_load_average_10s 返回为 0

go - 如何在 Prometheus (k8s) 中动态定义指标

python - 如何在 Python 请求中为 Slack API 的事件请求发送 http 200

c# - Web 套接字在一段时间后停止响应

prometheus - 如何在 Prometheus 查询中对标签进行分组?

kubernetes - 如何获取在 prometheus 中运行的 Pod 数量

node.js - 使用nodejs制作Slack机器人,Slack事件不起作用

monitoring - 获取Prometheus中两个自定义时间戳之间的增量

prometheus - 使用 PromQL 计算可用性