# Node health alert rules for Expanso

groups:
  - name: expanso_node_health
    interval: 30s
    rules:
      # Alert when an edge node stops reporting metrics
      - alert: EdgeNodeDisconnected
        expr: |
          (time() - timestamp(
            expanso_process_cpu_utilization_ratio{service_name="expanso-edge"}
          )) > 120
        for: 2m
        labels:
          severity: critical
          component: edge
        annotations:
          summary: "Edge node {{ $labels.node_hostname }} disconnected"
          description: "Edge node {{ $labels.node_hostname }} ({{ $labels.node_id }}) has not reported metrics for {{ $value }} seconds"

      # Alert when orchestrator goes down
      - alert: OrchestratorDown
        expr: |
          absent(
            expanso_process_cpu_utilization_ratio{service_name="expanso-orchestrator"}
          )
        for: 1m
        labels:
          severity: critical
          component: orchestrator
        annotations:
          summary: "Orchestrator is down"
          description: "The Expanso orchestrator is not reporting any metrics"

      # Alert on high CPU usage
      - alert: HighCPUUsage
        expr: |
          expanso_process_cpu_utilization_ratio > 0.85
        for: 5m
        labels:
          severity: warning
          component: performance
        annotations:
          summary: "High CPU usage on {{ $labels.service_name }}"
          description: "{{ $labels.service_name }} on {{ $labels.node_hostname }} has CPU utilization at {{ $value | humanizePercentage }}"

      # Alert on high memory usage
      - alert: HighMemoryUsage
        expr: |
          expanso_process_memory_usage_bytes > 1024 * 1024 * 1024
        for: 5m
        labels:
          severity: warning
          component: performance
        annotations:
          summary: "High memory usage on {{ $labels.service_name }}"
          description: "{{ $labels.service_name }} is using {{ $value | humanize }}B of memory"
