Prometheus Alerting Rule Not Firing Fix
In this tutorial, you'll learn about Prometheus Alerting Rule Not Firing Fix. We cover key concepts, practical examples, and best practices.
Your Prometheus alerting rule is green when it should be red — the alert never fires, shows PENDING but never FIRING, or fires but does not reach Alertmanager. The PromQL expression is wrong, the for duration is too long, or Alertmanager routing drops the alert.
The Problem
groups:
- name: alerts
rules:
- alert: HighCPUUsage
expr: cpu_usage_percent > 80
for: 30m
labels:
severity: critical
The alert never fires because cpu_usage_percent does not exist as a metric — the expression evaluates to no data, so the alert rule is always inactive.
Step-by-Step Fix
1. Verify the PromQL expression returns data
// Test the expression in Prometheus UI
cpu_usage_percent > 80
// Should return one or more time series with values
// If empty, check the actual metric name
cpu_usage_percent // Does this metric exist?
avg by (instance) (rate(cpu_seconds_total[5m])) * 100 // Alternative
2. Adjust the for duration
groups:
- name: alerts
rules:
- alert: HighCPUUsage
# Shorter for: duration for faster alerting
expr: avg by (instance) (rate(cpu_seconds_total[5m])) * 100 > 80
for: 2m # Alert after 2 minutes above threshold
labels:
severity: warning
annotations:
summary: "CPU usage above 80% on {{ $labels.instance }}"
3. Handle absent metrics
groups:
- name: alerts
rules:
- alert: InstanceDown
# Alert when up == 0 OR when up metric is absent
expr: up == 0 or absent(up)
for: 1m
labels:
severity: critical
4. Configure Alertmanager routing
# alertmanager.yml
route:
receiver: team-ops
routes:
- match:
severity: critical
receiver: team-ops-pager
- match:
severity: warning
receiver: team-ops-slack
receivers:
- name: team-ops-pager
pagerduty_configs:
- routing_key: YOUR_PAGERDUTY_KEY
- name: team-ops-slack
slack_configs:
- api_url: https://hooks.slack.com/services/...
channel: '#alerts'
5. Monitor alert rule health
// Check how many alerts are firing
count(ALERTS{alertstate="firing"}) by (severity)
// Check rule evaluation errors
prometheus_rule_evaluation_failures_total
// Check alert delivery to Alertmanager
rate(prometheus_notifications_sent_total[5m])
Expected output:
Rule evaluation: SUCCESS
Alert: HighCPUUsage → FIRING (instance=web-1, value=85.3)
Notifications sent to Alertmanager: 1
Prevention Tips
- Test PromQL expressions in Prometheus UI before writing alert rules
- Use
for:to prevent flapping alerts (2-5m for production alerts) - Add meaningful annotations for alert context
- Verify Alertmanager routing with
amtoolor the Alertmanager UI - Monitor alert rule evaluation with
<a href="/devops/prometheus-grafana/">Prometheus</a>_rule_evaluation_duration_seconds
Common Mistakes with alerting rule
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
- Misunderstanding that
Stringis[Char]with poor performance for large text operations - Using
foldlinstead offoldl'causing stack overflow on large lists
These mistakes appear frequently in real-world PROMETHEUS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro