groups:
  - name: homelab-core
    rules:
      - alert: ScrapeTargetDown
        expr: up == 0
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "Prometheus target down: {{ $labels.job }}"
          description: "Target {{ $labels.instance }} for job {{ $labels.job }} has been down for more than 5 minutes."

      - alert: PDMemoryPressureHigh
        expr: 100 * (1 - (node_memory_MemAvailable_bytes{job="pd-node"} / node_memory_MemTotal_bytes{job="pd-node"})) > 90
        for: 10m
        labels:
          severity: warning
        annotations:
          summary: "PD memory usage is high"
          description: "PlausibleDeniability memory usage has been above 90% for more than 10 minutes."

      - alert: PDFilesystemUsageHigh
        expr: 100 * (1 - (node_filesystem_avail_bytes{job="pd-node", mountpoint="/", fstype!~"tmpfs|ramfs|overlay|squashfs|nfs4"} / node_filesystem_size_bytes{job="pd-node", mountpoint="/", fstype!~"tmpfs|ramfs|overlay|squashfs|nfs4"})) > 85
        for: 15m
        labels:
          severity: warning
        annotations:
          summary: "PD root filesystem is filling up"
          description: "PlausibleDeniability root filesystem has been above 85% for more than 15 minutes."

      - alert: PDContainerRecentlyRestarted
        expr: changes(container_start_time_seconds{job="pd-cadvisor", name!=""}[30m]) > 0
        for: 5m
        labels:
          severity: info
        annotations:
          summary: "PD container restarted recently"
          description: "Container {{ $labels.name }} restarted within the last 30 minutes."

      - alert: PDRestoreVerificationFailed
        expr: pd_restore_verification_success == 0
        for: 15m
        labels:
          severity: warning
        annotations:
          summary: "PD restore verification failed"
          description: "The last scheduled restore verification on PlausibleDeniability failed."

      - alert: PDRestoreVerificationStale
        expr: time() - pd_restore_verification_last_success_timestamp_seconds > 8640000
        for: 1h
        labels:
          severity: warning
        annotations:
          summary: "PD restore verification is stale"
          description: "No successful PD restore verification has been recorded in the last 100 days."
