
{{- $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: kube-prometheus-node-recording.rules
rules:
- expr: {{ printf "sum(rate(node_cpu_seconds_total{mode!=\"idle\",mode!=\"iowait\",mode!=\"steal\"}[3m])) by(instance,%s)" $groupLabels }}
  condition: true
  record: instance:node_cpu:rate:sum
- expr: {{ printf "sum(rate(node_network_receive_bytes_total[3m])) by(instance,%s)" $groupLabels }}
  condition: true
  record: instance:node_network_receive_bytes:rate:sum
- expr: {{ printf "sum(rate(node_network_transmit_bytes_total[3m])) by(instance,%s)" $groupLabels }}
  condition: true
  record: instance:node_network_transmit_bytes:rate:sum
- expr: {{ printf "sum(rate(node_cpu_seconds_total{mode!=\"idle\",mode!=\"iowait\",mode!=\"steal\"}[5m])) without(cpu,mode) / on(instance,%s) group_left() count(sum(node_cpu_seconds_total) by(instance,cpu,%s)) by(instance,%s)" $groupLabels $groupLabels $groupLabels }}
  condition: true
  record: instance:node_cpu:ratio
- expr: {{ printf "sum(rate(node_cpu_seconds_total{mode!=\"idle\",mode!=\"iowait\",mode!=\"steal\"}[5m])) by(%s)" $groupLabels }}
  condition: true
  record: cluster:node_cpu:sum_rate5m
- expr: {{ printf "cluster:node_cpu:sum_rate5m / count(sum(node_cpu_seconds_total) by(instance,cpu,%s)) by(%s)" $groupLabels $groupLabels }}
  condition: true
  record: cluster:node_cpu:ratio
condition: true
