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

Prometheus自定义告警规则未在UI显示,求排查操作问题

问题:Prometheus自定义告警规则无法在UI中显示

问题描述

我创建了告警规则文件file.yml,将其复制到Prometheus容器的根目录下,同时在values.yml文件中添加了该规则路径,但无法在Prometheus UI中看到这条规则。

相关配置信息

prometheus.yml配置片段

prometheus.yml:
rule_files:
  - /etc/config/recording_rules.yml
  - /etc/config/alerting_rules.yml
  - /custom_alerting_rules.yml
## Below two files are DEPRECATED will be removed from this default values file
  - /etc/config/rules
  - /etc/config/alerts

alerting:
  alertmanagers:
    - static_configs:
        - targets: ['alertmanager:9093'] # 这里我试过替换成Alertmanager服务的IP

告警规则文件内容

groups:
  - name: my-custom-alerts
    rules:
      - alert: HighPodCount
        expr: count(kube_pod_info{pod=~"consumer.*"}) > 2
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: High pod count
          description: The number of pods is above the threshold.

Alertmanager服务信息(k get svc输出)

prometheus-alertmanager               ClusterIP      10.10x.21x.x8    <none>        9093/TCP                       68m

错误点排查与解决方法

  • 规则文件路径与挂载问题:你把规则文件命名为file.yml,但配置里指定的路径是/custom_alerting_rules.yml,首先要确保容器内该路径下的文件就是你的规则文件,文件名完全匹配。另外如果是通过Helm部署的Prometheus,直接复制文件到容器会在Pod重启后丢失,正确做法是通过values.yml配置挂载ConfigMap或者持久化卷,确保规则文件能稳定映射到容器内的/custom_alerting_rules.yml路径。
  • 配置未重启生效:修改values.yml或容器内配置后,必须重启Prometheus Pod或者执行helm upgrade重新部署,否则Prometheus不会加载新的规则配置。
  • 规则文件语法错误:你提供的规则内容里出现了&quot;,这是HTML转义的双引号,YAML文件中需要使用普通双引号",否则Prometheus解析规则时会失败,导致规则无法加载。请将规则里的转义双引号替换为正常双引号。
  • Alertmanager目标配置修正:当前Alertmanager目标写的是alertmanager:9093,但实际服务名是prometheus-alertmanager,如果两者在同一命名空间,应改为prometheus-alertmanager:9093,这个问题不影响规则显示,但会导致告警无法推送到Alertmanager,建议一并修正。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 23:45:23