【问题标题】:Auto-generate alert rules in Prometheus in Kubernetes?在 Kubernetes 的 Prometheus 中自动生成警报规则?
【发布时间】:2021-04-23 20:09:56
【问题描述】:

我在 Kubernetes 中使用 Prometheus Community Helm Chart 设置了一个 Prometheus 实例。每当持久卷已满 70% 时,我都会通过 Slack 收到警报。为了实现这一点,我在舵图的值文件中添加了一些代码(下面是一个示例)。 整个事情运行良好,但目前,我需要为每个新的持久卷添加一个新警报。

是否有更快的方法来自动生成这些规则(或使用变量定义它们)?我的值文件的相关部分可以在下面看到。

additionalPrometheusRulesMap:
    rule-name:
     groups:
     - name: storage
       rules:
        - alert: grafanaStorageAt70%
          expr: ( sum(kubelet_volume_stats_capacity_bytes{job="kubelet", namespace="kube-logging", persistentvolumeclaim="prom-grafana"}) 
                - sum(kubelet_volume_stats_available_bytes{job="kubelet", namespace="kube-logging", persistentvolumeclaim="prom-grafana"})) 
                / sum(kubelet_volume_stats_capacity_bytes{job="kubelet", namespace="kube-logging", persistentvolumeclaim="prom-grafana"}) > 0.7
          for: 15m
          labels:
            severity: warning
          annotations:
            summary: The Storage of Grafana is 70% full. Maybe increase the storage size?
        
        - alert: lokiStorageAt70%
          expr: ( sum(kubelet_volume_stats_capacity_bytes{job="kubelet", namespace="kube-logging", persistentvolumeclaim="storage-loki-0"}) 
                - sum(kubelet_volume_stats_available_bytes{job="kubelet", namespace="kube-logging", persistentvolumeclaim="storage-loki-0"})) 
                / sum(kubelet_volume_stats_capacity_bytes{job="kubelet", namespace="kube-logging", persistentvolumeclaim="storage-loki-0"})> 0.7
          for: 15m
          labels:
            severity: warning
          annotations:
            summary: The Storage of Loki is 70% full. Maybe increase the storage size?

【问题讨论】:

    标签: kubernetes alert prometheus kubernetes-helm


    【解决方案1】:

    只要您能够通过 PromQL 通配符表示要提醒的交易量的范围,您就可以为所有相关交易量制定一条规则。

    Prometheus 实际上非常聪明地对具有匹配值标签的值进行算术运算,即使您使用通配符也是如此。

    例如,覆盖所有 loki 持久卷实例(即不仅仅是 -0)的规则如下所示:

    additionalPrometheusRulesMap:
        rule-name:
         groups:
         - name: storage
           rules:
            - alert: lokiStorageAt70%
              expr: ( sum(kubelet_volume_stats_capacity_bytes{job="kubelet", namespace="kube-logging", persistentvolumeclaim=~"storage-loki-.+"}) 
                    - sum(kubelet_volume_stats_available_bytes{job="kubelet", namespace="kube-logging", persistentvolumeclaim=~"storage-loki-.+"})) 
                    / sum(kubelet_volume_stats_capacity_bytes{job="kubelet", namespace="kube-logging", persistentvolumeclaim=~"storage-loki-.+"})> 0.7
              for: 15m
              labels:
                severity: warning
              annotations:
                summary: The Storage of Loki is 70% full. Maybe increase the storage size?
    
    

    这只是一个示例,您当然可以使通配符更加狂野,以涵盖更多您想要提醒的卷。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-23
      • 2020-03-03
      • 2021-01-01
      相关资源
      最近更新 更多