apiVersion: operator.victoriametrics.com/v1beta1
kind: VMRule
metadata:
  name: alerts-node.rules
spec:
  groups:
  - name: node.rules
    params: {}
    rules:
    - annotations: {}
      expr: |-
        topk by (namespace,pod,cluster) (1,
          max by (node,namespace,pod,cluster) (
            label_replace(kube_pod_info{job="kube-state-metrics",node!=""}, "pod", "$1", "pod", "(.*)")
        ))
      labels: {}
      record: 'node_namespace_pod:kube_pod_info:'
    - annotations: {}
      expr: |-
        count by (node,cluster) (
          node_cpu_seconds_total{mode="idle",job="node-exporter"}
          * on (namespace,pod,cluster) group_left(node)
          topk by (namespace,pod,cluster) (1, node_namespace_pod:kube_pod_info:)
        )
      labels: {}
      record: node:node_num_cpu:sum
    - annotations: {}
      expr: |-
        sum(
          node_memory_MemAvailable_bytes{job="node-exporter"} or
          (
            node_memory_Buffers_bytes{job="node-exporter"} +
            node_memory_Cached_bytes{job="node-exporter"} +
            node_memory_MemFree_bytes{job="node-exporter"} +
            node_memory_Slab_bytes{job="node-exporter"}
          )
        ) by (cluster)
      labels: {}
      record: :node_memory_MemAvailable_bytes:sum
    - annotations: {}
      expr: |-
        avg by (node,cluster) (
          sum without (mode) (
            rate(node_cpu_seconds_total{mode!="idle",mode!="iowait",mode!="steal",job="node-exporter"}[5m])
          )
        )
      labels: {}
      record: node:node_cpu_utilization:ratio_rate5m
    - annotations: {}
      expr: |-
        avg by (cluster) (
          node:node_cpu_utilization:ratio_rate5m
        )
      labels: {}
      record: cluster:node_cpu:ratio_rate5m
