Prometheus 警报管理器不打印 {{ $labels.instance }} 值

发布于 2025-01-13 10:54:50 字数 1010 浏览 3 评论 0原文

我们有多个 AWS 账户,并且网络访问是在两个 AWS 账户之间配置的,并且服务发现正在与节点导出器配合使用。我有 Prometheus 配置,其中为 docker 容器配置了一些规则,现在我添加了与现有规则类似的规则之一,以检查是否错误地在另一个 AWS 账户中启动了同一个容器,下面是规则。对于现有规则, {{ $labels.instance }} 正在警报电子邮件中打印,但不适用于我新编写的新规则

Scrape 标签配置:

  - job_name: 'aws-conatiners'
    scheme: http
    ec2_sd_configs:
         - region: {{region}}
           port: 8181
    relabel_configs:
           - source_labels: [__meta_ec2_tag_Name]
             target_label: instance

我创建的用于检查是否有多个容器正在运行的新规则:

# Alert to check if more than one instance is running for backendapi service
  - alert: multiple_instances_are_running
    expr: sum(container_last_seen{name=~"backendapi"}) > 1
    for: 5m
    labels:
      severity: critical
    annotations:
      summary: "More than one Instance (instance {{ $labels.instance }}) is running"
      description: "More than one Instance (instance {{ $labels.instance }}) is running for 5 minutes."

有人可以检查并帮助我获取警报电子邮件中打印的实例名称吗

We have multiple AWS accounts and network access is configured between two AWS accounts and service discovery is working with node-exporter. I have Prometheus configuration with some of the rules configured for the docker containers and now I have added one of the rules similar to the existing one to check if by mistakenly same container is launched in another AWS account and below is the rule. for exiting rules, {{ $labels.instance }} is printing in Alerts email, but not for the new rule which I have written newly

Scrape config for labels:

  - job_name: 'aws-conatiners'
    scheme: http
    ec2_sd_configs:
         - region: {{region}}
           port: 8181
    relabel_configs:
           - source_labels: [__meta_ec2_tag_Name]
             target_label: instance

The new rule which I have created to check if more than one container is running:

# Alert to check if more than one instance is running for backendapi service
  - alert: multiple_instances_are_running
    expr: sum(container_last_seen{name=~"backendapi"}) > 1
    for: 5m
    labels:
      severity: critical
    annotations:
      summary: "More than one Instance (instance {{ $labels.instance }}) is running"
      description: "More than one Instance (instance {{ $labels.instance }}) is running for 5 minutes."

Can someone please check and help me to get the instance name printed in alert emails

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文