operator添加自定义规则

查看prometheus资源

[root@test ~]# kubectl get prometheus -n kube-mon
NAME                                    AGE
prometheus-prometheus-oper-prometheus   17d

[root@test ~]#  kubectl get  prometheus prometheus-prometheus-oper-prometheus  -n kube-mon -o yaml > /tmp/test.yaml
[root@test ~]#  cat /tmp/test.yaml | grep -A 5  ruleSelector
        f:ruleSelector:
          .: {}
          f:matchLabels:
            .: {}
            f:app: {}
            f:release: {}
--
  ruleSelector:   ### 就是这里啦, 如果需要新添加规则,那么新建的Kind为PrometheusRule的资源的labels中必须包含 app: prometheus-operator和release: prometheus
    matchLabels:
      app: prometheus-operator
      release: prometheus
  securityContext:
    fsGroup: 2000

下面是一个例子

apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  labels:
    app: prometheus-operator
    release: prometheus
  name: customize-rules
  namespace: kube-mon
spec:
  groups:
  - name: customize-rules
    rules:
    - alert: 宿主机cpu一分钟负载
      annotations:
        description: "{{ $labels.instance }} use cpu too high"
        runbook_url: http://grafana-prod.smilemall.com/explore
        summary: cpu alert on minute
      expr: instance:node_Load1_per_cpu:ratio > instance:node_num_cpu:sum * 0.5
      for: 1m
      labels:
        serverity: warning
posted @ 2020-11-23 10:50  没脚的丛林鸟  阅读(255)  评论(0编辑  收藏  举报