{{- $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 "," $additionalGroupByLabels }}
{{- $grafanaHost := ternary (index (($Values.grafana).ingress).hosts 0) (($Values.external).grafana).host ($Values.grafana).enabled }}
condition: '{{ true }}'
name: node-exporter.rules
rules:
- condition: '{{ true }}'
  expr: |-
    count without (cpu, mode) (
      node_cpu_seconds_total{job="node-exporter",mode="idle"}
    )
  record: instance:node_num_cpu:sum
- condition: '{{ true }}'
  expr: |-
    1 - avg without (cpu) (
      sum without (mode) (rate(node_cpu_seconds_total{job="node-exporter", mode=~"idle|iowait|steal"}[5m]))
    )
  record: instance:node_cpu_utilisation:rate5m
- condition: '{{ true }}'
  expr: |-
    (
      node_load1{job="node-exporter"}
    /
      instance:node_num_cpu:sum{job="node-exporter"}
    )
  record: instance:node_load1_per_cpu:ratio
- condition: '{{ true }}'
  expr: |-
    1 - (
      (
        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"}
        )
      )
    /
      node_memory_MemTotal_bytes{job="node-exporter"}
    )
  record: instance:node_memory_utilisation:ratio
- condition: '{{ true }}'
  expr: rate(node_vmstat_pgmajfault{job="node-exporter"}[5m])
  record: instance:node_vmstat_pgmajfault:rate5m
- condition: '{{ true }}'
  expr: rate(node_disk_io_time_seconds_total{job="node-exporter", device=~"(/dev/)?(mmcblk.p.+|nvme.+|rbd.+|sd.+|vd.+|xvd.+|dm-.+|md.+|dasd.+)"}[5m])
  record: instance_device:node_disk_io_time_seconds:rate5m
- condition: '{{ true }}'
  expr: rate(node_disk_io_time_weighted_seconds_total{job="node-exporter", device=~"(/dev/)?(mmcblk.p.+|nvme.+|rbd.+|sd.+|vd.+|xvd.+|dm-.+|md.+|dasd.+)"}[5m])
  record: instance_device:node_disk_io_time_weighted_seconds:rate5m
- condition: '{{ true }}'
  expr: |-
    sum without (device) (
      rate(node_network_receive_bytes_total{job="node-exporter", device!="lo"}[5m])
    )
  record: instance:node_network_receive_bytes_excluding_lo:rate5m
- condition: '{{ true }}'
  expr: |-
    sum without (device) (
      rate(node_network_transmit_bytes_total{job="node-exporter", device!="lo"}[5m])
    )
  record: instance:node_network_transmit_bytes_excluding_lo:rate5m
- condition: '{{ true }}'
  expr: |-
    sum without (device) (
      rate(node_network_receive_drop_total{job="node-exporter", device!="lo"}[5m])
    )
  record: instance:node_network_receive_drop_excluding_lo:rate5m
- condition: '{{ true }}'
  expr: |-
    sum without (device) (
      rate(node_network_transmit_drop_total{job="node-exporter", device!="lo"}[5m])
    )
  record: instance:node_network_transmit_drop_excluding_lo:rate5m
