Skip to content

Prometheus Rule Evaluation Error Fix

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about Prometheus Rule Evaluation Error Fix. We cover key concepts, practical examples, and best practices.

Prometheus logs Error reading rules or Error evaluating rule — the rule file has a syntax error, references a missing metric, or uses an invalid PromQL expression.

The Problem

# WRONG — missing metric name in the rule
groups:
  - name: example
    rules:
      - alert: HighCPUUsage
        expr: avg(rate(cpu_seconds[5m])) > 0.8
Error evaluating rule "HighCPUUsage": found no matching metrics

The metric cpu_seconds doesn't exist. The correct metric name is node_cpu_seconds_total. Prometheus evaluates the expression, finds no data, and logs an error for every evaluation cycle.

Step-by-Step Fix

1. Validate rule syntax

# Check Prometheus config
promtool check rules /etc/prometheus/rules/*.yml

# Check config including rules
promtool check config /etc/prometheus/prometheus.yml

2. Fix the PromQL expression

groups:
  - name: node_alerts
    rules:
      - alert: HighCPUUsage
        expr: avg(rate(node_cpu_seconds_total{mode="user"}[5m])) > 0.8
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "High CPU usage on {{ $labels.instance }}"

3. Handle missing metrics with absent()

rules:
  - alert: InstanceDown
    expr: up == 0
    for: 1m
    annotations:
      summary: "Instance {{ $labels.instance }} is down"

  - alert: NoMetrics
    expr: absent(up)
    for: 5m
    annotations:
      summary: "No metrics received at all"

4. Use recording rules for complex expressions

groups:
  - name: node_recording
    rules:
      - record: node:cpu:rate5m
        expr: rate(node_cpu_seconds_total[5m])

  - name: node_alerts
    rules:
      - alert: HighCPUUsage
        expr: avg(node:cpu:rate5m{mode="user"}) > 0.8
        for: 5m

5. Catch evaluation errors in the API

curl http://localhost:9090/api/v1/rules

Expected output from promtool check rules:

Checking rules/node-rules.yml
  SUCCESS: 5 rules found

Prevention Tips

  • Run promtool check rules in CI before deploying rule changes
  • Use recording rules for complex PromQL to simplify alert rules
  • Test expressions in the Prometheus UI's Graph tab before writing rules
  • Validate metric names with curl http://<a href="/devops/prometheus-grafana/">prometheus</a>:9090/api/v1/label/__name__/values
  • Add absent() alerts to detect missing metrics

Common Mistakes with rule evaluation

  1. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  2. Using return to exit a function early instead of wrapping a pure value in the monad
  3. Mixing let bindings with <- bindings in do notation, producing type errors

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

### What causes "found no matching metrics" in rule evaluation?

The PromQL expression references a metric that doesn't exist in Prometheus. Either the metric name is wrong, the metric hasn't been scraped yet, or the time range is too short. Verify the metric name with curl http://<a href="/devops/prometheus-grafana/">prometheus</a>:9090/api/v1/label/__name__/values.

How do I debug a recording rule that produces no output?

Check if the source metrics exist in Prometheus. Evaluate the raw expression in the Prometheus UI Graph tab. Verify the recording rule is in a loaded group (check /api/v1/rules). Recording rules fire at scrape_interval, not immediately.

What's the best practice for organizing rule files?

Separate into alerts/ and recording/ directories. Group by domain (node, app, infra). Use promtool for validation. Keep rule files small (10-20 rules per file). Use for: 5m to reduce false positives from transient spikes.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro