apiVersion: v1
kind: ConfigMap
metadata:
  name: k8s-pgmon-rules
  namespace: pgmon
data:
  k8s-pgmon.yaml: |-
    groups:
    - name: node.rules
      rules:
      - alert: NodeExporterDown
        expr: up{job="k8s-pgmon/kubernetes-node-exporter"} == 0
        for: 1m
        labels:
          severity: critical
        annotations:
          summary: "Node exporter down --------- {{ $labels.job }} ----------------"
          description: "has been down for more {{ $value }} than minutes."

      - alert: NodeMemoryUsage
        expr: node_memory_Active_bytes / node_memory_MemTotal_bytes * 100 > 85
        for: 2m
        labels:
          severity: warning
        annotations:
          summary: "{{$labels.instance}}: High Memory usage detected"
          description: "{{$labels.instance}}: Memory usage is above 85%, current value is: {{$value}}"

      - alert: NodeCPUUsage
        expr: 100 - (avg by (instance) (irate(node_cpu_seconds_total{job="k8s-pgmon/kubernetes-node-exporter",mode="idle"}[5m])) * 100) > 85
        for: 2m
        labels:
          severity: warning
        annotations:
          summary: "{{$labels.instance}}: High CPU usage detected"
          description: "{{$labels.instance}}: CPU usage is above 85% (current value is: {{ $value }}"

    - name: pod.rules
      rules:
      - alert: PodMemoryUsage
        expr: sum(container_memory_rss{image != ""}) by(pod_name, namespace) / sum(container_spec_memory_limit_bytes{image != ""}) by(pod_name, namespace) * 100 != +Inf > 85
        for: 2m
        labels:
          severity: warning
        annotations:
          summary: "{{$labels.pod_name}}:High Memory usage detected"
          description: "{{$labels.pod_name}}: Memory usage is above 85%, current value is: {{$value}}"

      - alert: PodCPUUsage
        expr: sum(rate(container_cpu_usage_seconds_total{image != ""}[5m])) by (pod_name, namespace) / (sum(container_spec_cpu_quota{image != ""} / 100000) by (pod_name, namespace)) * 100 != +Inf > 85
        for: 2m
        labels:
          severity: warning
        annotations:
          summary: "{{$labels.pod_name}}:High cpu usage detected"
          description: "{{$labels.pod_name}}: cpu usage is above 85%, current value is: {{$value}}"
