如何在稳定/普罗米修斯图表中设置prometheus规则.yaml?

时间:2018-01-26 07:12:12

标签: charts configuration yaml rules prometheus

使用官方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

1 个答案:

答案 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

规则适用于记录规则,警报适用于警报规则。

  

https://prometheus.io/docs/practices/rules/