我在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?
只要您能够通过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?
这只是一个例子,你当然可以把通配符设置得更大,以覆盖更多你想要提醒的卷。