You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Prometheus Alertmanager告警描述添加指标标签?

解决Prometheus告警中无法获取指标标签的问题

你的需求是在告警消息中展示触发告警的指标标签(如connection),但当前告警配置无法正确获取这些标签。以下是具体的解决方法:

问题分析

你当前的告警表达式直接对比两个带不同le标签的job_duration_bucket序列:

expr: job_duration_bucket{queue="high",le="20"} > job_duration_bucket{queue="high",le="15"}

Prometheus默认会匹配两个序列的所有标签,但这两个序列的le标签值不同(20 vs 15),导致无法正确关联对应队列的指标,最终丢失了connection等关键标签。

修正后的告警规则

修改表达式,使用ignoring(le)忽略le标签的差异,让Prometheus基于resource_server、queue、connection这些标签匹配序列:

groups:
- name: alert.rules
  rules:
  - alert: JobDurationExceedance
    expr: job_duration_bucket{queue="high",le="20"} > ignoring(le) job_duration_bucket{queue="high",le="15"}
    for: 1s
    labels:
      severity: critical
    annotations:
      summary: {{ $labels.resource_server }} high prio job duration exceed limit
      description: "On the {{ $labels.resource_server }} {{ $labels.queue }} prio {{ $labels.connection }} queue currently jobs exist, which take more than 15 minutes from being queued to completion."

关键说明

  • ignoring(le):指定比较时忽略le标签,确保其他标签(resource_server、queue、connection)完全匹配的序列能被正确关联计算。
  • 修正描述语法:将原注释中的jobs exists改为jobs exist,needing more than 15 minutes or more改为take more than 15 minutes,避免语法错误和冗余表述。

调整后,告警消息就能正确输出你期望的格式:On the rs1 high prio database queue currently jobs exist...

内容的提问来源于stack exchange,提问作者Stefan Meindl

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 08:05:18