使用官方Prometheus
图表stable/prometheus
。
自定义其values.yaml
文件以设置alertmanager.yml
文件和serverFiles
区域。
rules: {}
:
https://github.com/kubernetes/charts/blob/master/stable/prometheus/values.yaml#L598
它是{}
。如何在official format处写出真实的警报规则?
例如,我尝试过:
serverFiles:
alerts: {}
rules:
# Alert for any instance that is unreachable for >5 minutes.
- alert: InstanceDown
expr: up == 0
for: 5m
labels:
severity: page
annotations:
summary: "Instance {{ $labels.instance }} down"
description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes."
然后跑$ helm install my_prometheus
。然后pod遇到了这个错误:
PersistentVolumeClaim is not bound: "sweet-terrier-prometheus-server"
Back-off restarting failed container
Error syncing pod
答案 0 :(得分:8)
serverFiles:
alerts:
groups:
- name: NodeAlerts
rules:
- alert: NodeCPUUsage
expr: (100 - (avg(irate(node_cpu{mode="idle"}[5m])) BY (instance) * 100)) > 75
for: 2m
labels:
severity: alert
annotations:
description: '{{$labels.instance}}: CPU usage is above 75% (current value is:
{{ $value }})'
summary: '{{$labels.instance}}: High CPU usage detect
规则适用于记录规则,警报适用于警报规则。