
{{- $Values := (.helm).Values | default .Values }}
{{- $runbookUrl := ($Values.defaultRules).runbookUrl | default "https://runbooks.prometheus-operator.dev/runbooks" }}
{{- $clusterLabel := ($Values.global).clusterLabel | default "cluster" }}
{{- $additionalGroupByLabels := append $Values.defaultRules.additionalGroupByLabels $clusterLabel }}
{{- $groupLabels := join "," (uniq $additionalGroupByLabels) }}
{{- $grafanaAddr := include "vm-k8s-stack.grafana.addr" . }}
name: node.rules
rules:
- expr: {{ printf "topk(1, max(label_replace(kube_pod_info{job=\"kube-state-metrics\",node!=\"\"}, \"pod\", \"$1\", \"pod\", \"(.*)\")) by(%s,node,namespace,pod)) by(%s,namespace,pod)" $groupLabels $groupLabels }}
  condition: true
  record: 'node_namespace_pod:kube_pod_info:'
- expr: {{ printf "count(node_cpu_seconds_total{mode=\"idle\",job=\"%s\"} * on(%s,namespace,pod) group_left(node) topk(1, node_namespace_pod:kube_pod_info:) by(%s,namespace,pod)) by(%s,node)" (include "vm-k8s-stack.nodeExporter.name" .) $groupLabels $groupLabels $groupLabels }}
  condition: true
  record: node:node_num_cpu:sum
- expr: {{ printf "sum(node_memory_MemAvailable_bytes{job=\"%s\"} or (((node_memory_Buffers_bytes{job=\"%s\"} + node_memory_Cached_bytes{job=\"%s\"}) + node_memory_MemFree_bytes{job=\"%s\"}) + node_memory_Slab_bytes{job=\"%s\"})) by(%s)" (include "vm-k8s-stack.nodeExporter.name" .) (include "vm-k8s-stack.nodeExporter.name" .) (include "vm-k8s-stack.nodeExporter.name" .) (include "vm-k8s-stack.nodeExporter.name" .) (include "vm-k8s-stack.nodeExporter.name" .) $groupLabels }}
  condition: true
  record: :node_memory_MemAvailable_bytes:sum
- expr: {{ printf "avg(sum(rate(node_cpu_seconds_total{mode!=\"idle\",mode!=\"iowait\",mode!=\"steal\",job=\"%s\"}[5m])) without(mode)) by(%s,node)" (include "vm-k8s-stack.nodeExporter.name" .) $groupLabels }}
  condition: true
  record: node:node_cpu_utilization:ratio_rate5m
- expr: {{ printf "avg(node:node_cpu_utilization:ratio_rate5m) by(%s)" $groupLabels }}
  condition: true
  record: cluster:node_cpu:ratio_rate5m
condition: true
