【问题标题】:Prometheus alert manager template changesPrometheus 警报管理器模板更改
【发布时间】:2019-05-08 12:25:22
【问题描述】:

我有一个使用模板运行的 prometheus 警报管理器,我收到的电子邮件主题如下

[FIRING:6] 异常的网络吞吐量输出(thanos group_b aws_us_b instance_191 基础设施监控-prometheus-node 警告)

警报名称后的所有值都是标签。 这是模板主题代码

{{ define "__subject" }}[{{ .Status | toUpper }} {{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}]  {{ .GroupLabels.SortedPairs.Values | join " " }}  {{ if gt (len .CommonLabels) (len .GroupLabels) }} ({{ with .CommonLabels.Remove .GroupLabels.Names }}   {{ .Values | join " " }}   {{ end }}) {{ end }}{{ end }}

我想修改它只是为了获得关注

[FIRING:6] 异常的网络吞吐量输出(group_b instance_191) 只有组名和实例名

我怎样才能做到这一点?

【问题讨论】:

    标签: go prometheus


    【解决方案1】:

    你可以用这样的东西替换你的模板:

    {{ define "__subject" }}[{{ .Status | toUpper }} {{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .GroupLabels.alertname }} ({{ .GroupLabels.group }} {{ .GroupLabels.instance }})
    

    不确定如果 group 或 instance 标签并非在所有警报中通用(例如,如果您的警报跨多个组和/或实例触发)会发生什么。也许你只会得到一个空字符串,也许是null。根据某些brief testing in the Go playground 的说法,您似乎可能会得到<no value>。如果你不想这样,你可以玩Go template's {{if }} action。

    类似

    {{ if .GroupLabels.group }}{{ .GroupLabels.group }}{{ end }}
    

    【讨论】:

    • 这些标签在所有警报中都很常见。完美运行
    猜你喜欢
    • 2021-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-15
    • 1970-01-01
    • 1970-01-01
    • 2020-02-28
    • 1970-01-01
    相关资源
    最近更新 更多