groups:
  - name: nodes
    rules:
      - alert: App server is down
        expr: up{instance="web:8000"} == 0
        for: 1m
        annotations:
          description: App server is not running
          summary: App server is down and not running

  - name: cpu
    rules:
      - alert: High CPU Usage
        expr: 100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80
        for: 5m
        annotations:
          description: CPU usage is above 80% for more than 5 minutes.
          summary: High CPU usage detected.

  - name: memory
    rules:
      - alert: High Memory Usage
        expr: (node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100 > 90
        for: 5m
        annotations:
          description: Memory usage is above 90% for more than 5 minutes.
          summary: High memory usage detected.

  - name: disk
    rules:
      - alert: High Disk Space Usage
        expr: (node_filesystem_size_bytes{fstype!~"tmpfs|fuse.lxcfs"} - node_filesystem_free_bytes{fstype!~"tmpfs|fuse.lxcfs"}) / node_filesystem_size_bytes{fstype!~"tmpfs|fuse.lxcfs"} * 100 > 90
        for: 5m
        annotations:
          description: Disk space usage is above 90% for more than 5 minutes.
          summary: High disk space usage detected.

  - name: latency
    rules:
      - alert: High Request Latency
        expr: histogram_quantile(0.99, rate(http_request_duration_seconds_bucket[5m])) > 1
        for: 1m
        annotations:
          description: Request latency is above 1 second for more than 1 minute.
          summary: High request latency detected.

  - name: errors
    rules:
      - alert: High Error Rate
        expr: rate(http_requests_total{status=~"5.."}[5m]) / rate(http_requests_total[5m]) > 0.05
        for: 1m
        annotations:
          description: Error rate is above 5% for more than 1 minute.
          summary: High error rate detected.