【问题标题】:Match using metric name instead of metric labels使用指标名称而不是指标标签进行匹配
【发布时间】:2021-05-07 10:26:38
【问题描述】:

我的一个出口商打印了一个没有标签的指标:

$ curl -s http://localhost:9999/metrics | grep service_up | grep -v "#"
service_up 1

创建 AlertManager 接收器时,我通常使用 match 的度量标签之一(例如,job: 'nodeexporter-textcollector')。

例如,对于这种情况,AlertManager 配置如下所示:

route:
  receiver: 'default'
  routes:
  - receiver: 'custom'
    match:
      severity: 'critical'
      job: 'nodeexporter-textcollector'

但是,对于上述指标 (service_up),是否可以匹配指标名称?

谢谢。

【问题讨论】:

    标签: prometheus prometheus-alertmanager


    【解决方案1】:

    您已为此指标定义了警报规则,对吗?类似于以下示例:

    - alert: ServiceIsDown
      expr: service_up == 0
    

    现在,要路由此警报,您只需使用警报名称:

    route:
      receiver: 'default'
      routes:
      - receiver: 'custom'
        match:
          alertname: 'ServiceIsDown'
    

    【讨论】:

      【解决方案2】:

      您需要创建一个自定义命名警报并在其上放置正确的标签。例如 severity 就像在这个例子中一样。

      # alerts/example-redis.yml
      groups:
      
      - name: ExampleRedisGroup
        rules:
        - alert: ExampleRedisDown
          expr: redis_up{} == 0
          for: 2m
          labels:
            severity: critical
          annotations:
            summary: "Redis instance down"
            description: "Whatever"
      

      另外,注意expr 字段,alermanager 会这样理解它需要触发警报。只需检查您的alertmanager 分发中的alerts 文件夹,有很多示例。

      关于创建警报的官方文档:https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/

      更多自定义提醒示例:https://awesome-prometheus-alerts.grep.to/alertmanager

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-08-14
        • 2010-11-26
        • 2019-04-27
        • 2018-08-05
        • 1970-01-01
        • 2018-07-11
        • 2017-05-22
        • 2019-09-09
        相关资源
        最近更新 更多