Skip to main content
APA
Sponsored by CAST AI — Kubernetes cost optimization Better Stack — Uptime monitoring and log management
⚠️

Alert thresholds depend on the nature of your applications. Some queries may have arbitrary tolerance thresholds. Building an efficient monitoring platform takes time. 😉

Nginx Prometheus Alert Rules

3 Prometheus alerting rules for Nginx. Exported via knyar/nginx-lua-prometheus. These rules cover critical and warning conditions — copy and paste the YAML into your Prometheus configuration.

wget https://raw.githubusercontent.com/samber/awesome-prometheus-alerts/refs/heads/master/dist/rules/nginx/knyar-nginx-exporter.yml
critical

4.1.1. Nginx high HTTP 4xx error rate

Too many HTTP requests with status 4xx (> 5%)

- alert: NginxHighHTTP4xxErrorRate
  expr: sum(rate(nginx_http_requests_total{status=~"^4.."}[1m])) / sum(rate(nginx_http_requests_total[1m])) * 100 > 5 and sum(rate(nginx_http_requests_total[1m])) > 0
  for: 1m
  labels:
    severity: critical
  annotations:
    summary: Nginx high HTTP 4xx error rate (instance {{ $labels.instance }})
    description: "Too many HTTP requests with status 4xx (> 5%)\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
critical

4.1.2. Nginx high HTTP 5xx error rate

Too many HTTP requests with status 5xx (> 5%)

- alert: NginxHighHTTP5xxErrorRate
  expr: sum(rate(nginx_http_requests_total{status=~"^5.."}[1m])) / sum(rate(nginx_http_requests_total[1m])) * 100 > 5 and sum(rate(nginx_http_requests_total[1m])) > 0
  for: 1m
  labels:
    severity: critical
  annotations:
    summary: Nginx high HTTP 5xx error rate (instance {{ $labels.instance }})
    description: "Too many HTTP requests with status 5xx (> 5%)\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
warning

4.1.3. Nginx latency high

Nginx p99 latency is higher than 3 seconds

- alert: NginxLatencyHigh
  expr: histogram_quantile(0.99, sum(rate(nginx_http_request_duration_seconds_bucket[2m])) by (host, node, le)) > 3
  for: 2m
  labels:
    severity: warning
  annotations:
    summary: Nginx latency high (instance {{ $labels.instance }})
    description: "Nginx p99 latency is higher than 3 seconds\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"