Skip to main content
APA
Sponsored byCAST AI — Kubernetes cost optimizationBetter Stack — Uptime monitoring and log managementVictoriaMetrics — Fast, open-source time series database and drop-in Prometheus replacement.

Nginx logoNginx Prometheus Alert Rules

4 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.

⚠️

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

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%)

  # 5% 4xx rate is a rough default. Client-error rates vary widely by application (bots, API misuse, rate limits, short-lived token expiry, scanners) — adjust based on your baseline.
- 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

  # 3s threshold is a rough default; acceptable latency varies by route and your SLO — adjust based on your baseline.
- 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 }}"
warning

4.1.4.Nginx internal metric errors

The nginx-lua-prometheus library failed to record one or more metrics (e.g. the shared dictionary used to store metrics is full or an LRU eviction occurred), which may mean other Nginx metrics are incomplete.

- alert: NginxInternalMetricErrors
  expr: increase(nginx_metric_errors_total[5m]) > 0
  for: 1m
  labels:
    severity: warning
  annotations:
    summary: Nginx internal metric errors (instance {{ $labels.instance }})
    description: "The nginx-lua-prometheus library failed to record one or more metrics (e.g. the shared dictionary used to store metrics is full or an LRU eviction occurred), which may mean other Nginx metrics are incomplete.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"