In 2024 I built a monitoring project on two GCP VMs: Prometheus, Node Exporter, the Blackbox Exporter and Alertmanager, with eight alert rules. I tested the important ones the honest way. I stopped the website and the email arrived. I stopped the server and the email arrived. I called it done.
The other five rules, for memory, disk and CPU, I never triggered. Reviewing the project this year, I found that none of the five could ever have fired. Not on a full disk, not on a machine out of memory, not at 100% CPU. And nothing in Prometheus said so: the config loaded, the rules evaluated every 15 seconds, and the alerts page showed them all green.
This post covers why that happens, how to prove it with promtool in a few seconds, and what I check now so an alert that can’t fire doesn’t look the same as one that hasn’t.
Eight rules, two of them tested #
Here are the rules from alert_rules.yml, and what I knew about each in 2024:
| Alert | What it watches | Tested in 2024 | Could it fire? |
|---|---|---|---|
InstanceDown |
up == 0 |
Yes | Yes |
WebsiteDown |
probe_success == 0 |
Yes | Yes |
ServiceUnavailable |
up{job="node_exporter"} == 0 |
Not separately | Yes |
HostOutOfMemory |
node_memory_MemAvailable |
No | No |
HighMemoryUsage |
node_memory_Active |
No | No |
HostOutOfDiskSpace |
node_filesystem_avail |
No | No |
FileSystemFull |
node_filesystem_avail |
No | No |
HostHighCpuLoad |
node_cpu |
No | No |
The pattern is hard to miss once it’s in a table: every rule I tested worked, and every rule I didn’t test was broken.
Here is the memory rule exactly as it ran:
- alert: HostOutOfMemory
expr: node_memory_MemAvailable / node_memory_MemTotal * 100 < 25 # Expression to detect low memory
for: 5m
labels:
severity: warningIt reads correctly. The threshold is sensible. And on a current Node Exporter, node_memory_MemAvailable doesn’t exist.
What changed in 2018 #
Node Exporter 0.16.0, released in 2018, renamed its metrics to follow Prometheus’s naming rule that a name ends with its base unit. Memory and filesystem gauges gained _bytes, and the CPU counter gained _seconds_total:
| Before 0.16.0 | From 0.16.0 |
|---|---|
node_memory_MemAvailable |
node_memory_MemAvailable_bytes |
node_memory_MemTotal |
node_memory_MemTotal_bytes |
node_memory_Active |
node_memory_Active_bytes |
node_filesystem_avail |
node_filesystem_avail_bytes |
node_filesystem_size |
node_filesystem_size_bytes |
node_cpu |
node_cpu_seconds_total |
My install script pulled Node Exporter 1.8.2, six years after the rename, and I wrote the rules from examples that predated it. Rule examples outlive the versions they were written for, and nothing about an old example tells you it’s old.
To check against the real thing, I ran the same Node Exporter 1.8.2 on my laptop and counted the series under each name:
# node_exporter 1.8.2: old vs current metric names
node_memory_MemAvailable old name: 0 series current name: 1 series
node_memory_MemTotal old name: 0 series current name: 1 series
node_memory_Active old name: 0 series current name: 1 series
node_filesystem_avail old name: 0 series current name: 11 series
node_filesystem_size old name: 0 series current name: 11 series
node_cpu old name: 0 series current name: 64 seriesWhy Prometheus says nothing #
A PromQL selector that matches no series isn’t an error. It returns an empty result, and an alert rule with an empty result has nothing to fire on. As far as Prometheus is concerned, node_memory_MemAvailable / node_memory_MemTotal * 100 < 25 is a perfectly good question whose answer, every 15 seconds, is “no hosts match”.
That’s a deliberate design, not a bug. The same property is what lets one rule cover a whole fleet: hosts that are fine produce no result, and only the sick ones appear. Prometheus can’t tell “no host is low on memory” from “no host reports this metric”, because in PromQL both are the same empty set.
The tools that check your rules before Prometheus loads them work at the same level. promtool check rules validates the YAML and parses the PromQL. It has no idea which metrics exist, so the 2024 file passes cleanly:
$ promtool check rules rules-2024.yml
Checking rules-2024.yml
SUCCESS: 8 rules found
exit=0A rule can be valid, loaded and evaluated, and still be dead.
The CPU rule was wrong three times #
The CPU rule deserves its own section, because renaming the metric wouldn’t have saved it:
- alert: HostHighCpuLoad
expr: (sum by (instance) (irate(node_cpu{job="node_exporter_metrics",mode="idle"}[5m]))) > 80 # Expression to detect high CPU load
for: 5m- The old metric name.
node_cpuis nownode_cpu_seconds_total. - The wrong job label. The scrape config names the job
node_exporter. The rule asks fornode_exporter_metrics, which no target has ever had. Even with the right metric name, the selector matches nothing. - The wrong quantity, in the wrong units. It measures idle time, so in spirit it alerts on a quiet machine. But the real problem is scale.
node_cpu_seconds_totalcounts seconds, so its rate per core is a fraction between 0 and 1: a fully idle core spends 1 second per second idle. Summed across cores, the result can’t exceed the number of cores. The rule compares that to 80. On my 2-vCPUe2-mediumVM the expression’s maximum was 2.
When I reviewed the project earlier this year, I wrote that the CPU rule “would have fired when the CPU was quiet”. That was wrong too. Fixing only the name and the job label shows it can’t fire either way:
$ promtool test rules tests-cpu-renamed-only.yml
FAILED:
name: busy host (95% busy),
alertname: HostHighCpuLoad, time: 15m,
exp:[
0:
Labels:{alertname="HostHighCpuLoad", instance="app:9100", severity="warning"}
Annotations:{summary="Host high CPU load (instance app:9100)"}
],
got:[]
name: idle host (100% idle),
alertname: HostHighCpuLoad, time: 15m,
exp:[
0:
Labels:{alertname="HostHighCpuLoad", instance="app:9100", severity="warning"}
Annotations:{summary="Host high CPU load (instance app:9100)"}
],
got:[]
exit=1Both cases fail: the busy host (95% busy) and the idle host (100% idle). The rule is dead in both directions.
The working rule takes the average idle fraction per instance and turns it into a busy percentage:
- alert: HostHighCpuLoad
expr: 100 - (avg by (instance) (rate(node_cpu_seconds_total{job="node_exporter", mode="idle"}[5m])) * 100) > 80
for: 5mProving it with promtool #
promtool test rules is the missing piece. It feeds made-up series into your rules on a simulated clock and checks which alerts fire. No Prometheus server, no VM, no waiting for a disk to fill.
I described a struggling 2-core host using Node Exporter’s current metric names: 7.5% memory available, 95% of memory active, 5% disk free and 95% CPU busy. Then I asserted that every resource alert fires after 15 minutes. An excerpt:
rule_files:
- rules-2024.yml
evaluation_interval: 1m
tests:
- interval: 1m
input_series:
- series: node_memory_MemTotal_bytes{instance="app:9100", job="node_exporter"}
values: "4000000000x20"
- series: node_memory_MemAvailable_bytes{instance="app:9100", job="node_exporter"}
values: "300000000x20" # 7.5% available
- series: node_cpu_seconds_total{instance="app:9100", job="node_exporter", cpu="0", mode="idle"}
values: "0+3x20" # 3 s idle per 60 s: 95% busy
alert_rule_test:
- eval_time: 15m
alertname: HostOutOfMemory
exp_alerts:
- exp_labels: { severity: warning, instance: "app:9100", job: node_exporter }Against the 2024 rules, every resource alert comes back empty:
$ promtool test rules tests-2024.yml
FAILED:
alertname: HostOutOfMemory, time: 15m,
exp:[
0:
Labels:{alertname="HostOutOfMemory", instance="app:9100", job="node_exporter", severity="warning"}
Annotations:{summary="Host out of memory (instance app:9100)"}
],
got:[]
# ...the same empty result for:
# HighMemoryUsage
# HostOutOfDiskSpace
# FileSystemFull
# HostHighCpuLoad
exit=1The same test against the fixed rules, which differ only in metric names and the CPU expression:
$ promtool test rules tests-fixed.yml
SUCCESS
exit=0The whole reproduction is five small files, now in the project’s tests/ folder, and the 2024 rules there are left unchanged so the failing test keeps failing.
How I guard against it now #
- A unit test for every alert, in CI. One
promtool test rulescase per alert, with a series that should make it fire. It’s the cheapest possible proof, and it fails the build when an exporter upgrade renames something. - Check selectors against a live server. Cloudflare’s
pintlints rules against a running Prometheus and reports selectors that match no series. That catches the name and the job-label mistakes in the same pass. - Alert on missing data, deliberately.
absent(node_memory_MemAvailable_bytes{job="node_exporter"})fires when the metric a rule depends on disappears. Absence is the failure that ordinary rules can’t see, so it needs a rule of its own. - Trigger every alert on purpose, once. Tests prove the logic; a real
fallocateorstress-ngrun proves the whole chain to the inbox. In Project Aether this became a rule: an alert doesn’t count until it has been seen firing. - Watch the watcher. A dead man’s switch, an alert that always fires and is relayed to an outside service, tells you when the alerting path itself has died. That’s how I run it today, described in Observability Off the Cluster.
What I learned #
- An alert that has never fired looks exactly like one that can’t. Green on the alerts page means “no result”, not “checked and healthy”.
- Empty results are not errors in PromQL, and that’s by design. The consequence is that a typo, a renamed metric or a wrong label fails silently.
- Syntax checks aren’t tests.
promtool check rulespassed every broken rule.promtool test rulescaught every one. - The bugs were exactly where my testing stopped. The alerts I broke things to test worked. The ones I assumed worked didn’t.
This came out of reviewing Real-Time Monitoring and Alerting with Prometheus; the original build is in the 2024 write-up.