# CPU Usage Alert
      - alert: HighCPUUsage
        expr: 100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[1m])) * 100) > 80
        for: 2m
        labels:
          severity: warning
        annotations:
          summary: "High CPU Usage on {{ $labels.instance }}"
          description: "CPU usage is above 80% for the past 2 minutes."

      # Memory Usage Alert
      - alert: HighMemoryUsage
        expr: node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes < 0.2
        for: 2m
        labels:
          severity: warning
        annotations:
          summary: "High Memory Usage on {{ $labels.instance }}"
          description: "Available memory is less than 20%."

      # PostgreSQL Service Status
      - alert: PostgresServiceDown
        expr: pg_up == 0
        for: 1m
        labels:
          severity: critical
        annotations:
          summary: "PostgreSQL Service is Down on {{ $labels.instance }}"
          description: "PostgreSQL service is not responding."

      # Active Connections Alert
      - alert: HighActiveConnections
        expr: pg_stat_activity_count{state="active"} > 100
        for: 2m
        labels:
          severity: warning
        annotations:
          summary: "High Active Connections on {{ $labels.instance }}"
          description: "Active connections are more than 100 for 2 minutes."

      # Disk Usage Alert
      - alert: HighDiskUsage
        expr: (node_filesystem_avail_bytes{fstype!~"tmpfs|overlay"} / node_filesystem_size_bytes{fstype!~"tmpfs|overlay"}) < 0.1
        for: 2m
        labels:
          severity: critical
        annotations:
          summary: "High Disk Usage on {{ $labels.instance }}"
          description: "Available disk space is less than 10%."

      # Replication Lag Alert
      - alert: HighReplicationLag
        expr: pg_stat_replication_lag > 100000
        for: 2m
        labels:
          severity: critical
        annotations:
          summary: "High Replication Lag on {{ $labels.instance }}"
          description: "Replication lag is more than 100,000 bytes."

      # Replication Status Alert
      - alert: ReplicationNotStreaming
        expr: pg_stat_replication_state != "streaming"
        for: 1m
        labels:
          severity: warning
        annotations:
          summary: "Replication Not Streaming on {{ $labels.instance }}"
          description: "Replication state is not streaming.
