apiVersion: operator.victoriametrics.com/v1beta1
kind: VMRule
metadata:
  name: alerts-node
  namespace: cozy-monitoring
spec:
  groups:
  - name: coreos.node
    rules:
    - record: node:node_cpu:rate:sum
      expr: sum(rate(node_cpu{mode!="idle",mode!="iowait"}[3m]))
        BY (node)
    - record: node:node_filesystem_usage:sum
      expr: sum((node_filesystem_size{mountpoint="/"} - node_filesystem_free{mountpoint="/"}))
        BY (node)
    - record: node:node_network_receive_bytes:rate:sum
      expr: sum(rate(node_network_receive_bytes[3m])) BY (node)
    - record: node:node_network_transmit_bytes:rate:sum
      expr: sum(rate(node_network_transmit_bytes[3m])) BY (node)
    - record: node:node_cpu:ratio
      expr: sum(rate(node_cpu{mode!="idle",mode!="iowait"}[5m])) WITHOUT (cpu, mode) / ON(node)
        GROUP_LEFT() count(sum(node_cpu) BY (node, cpu)) BY (node)
    - record: cluster:node_cpu:sum_rate5m
      expr: sum(rate(node_cpu{mode!="idle",mode!="iowait"}[5m]))
    - record: cluster:node_cpu:ratio
      expr: cluster:node_cpu:rate5m / count(sum(node_cpu) BY (node, cpu))
    - alert: NodeExporterDown
      expr: absent(up{job="node-exporter"} == 1)
      for: 10m
      labels:
        severity_level: "3"
      annotations:
        plk_protocol_version: "1"
        description: Prometheus could not scrape a node-exporter for more than 10m,
          or node-exporters have disappeared from discovery
        summary: Prometheus could not scrape a node-exporter
