Operating Prometheus
Reloads, upgrades, CI checks, and meta-monitoring
The monitoring system has to be more reliable than the systems it watches. That means treating its config as code, changing it safely, and monitoring it, from somewhere else.
Config as code
Everything in this module lives in git: prometheus.yml, rules, rule
tests, Alertmanager config, Grafana provisioning, and dashboards. Every
change goes through review and a CI pipeline:
docker run --rm -v "$PWD/prometheus/config:/cfg" --entrypoint promtool prom/prometheus:v3.15.0 \
check config /cfg/prometheus.yml
docker run --rm -v "$PWD/prometheus/config:/cfg" --entrypoint promtool prom/prometheus:v3.15.0 \
test rules /cfg/tests/alerts.test.yml
docker run --rm -v "$PWD/prometheus/config:/cfg" --entrypoint amtool prom/alertmanager:v0.34.1 \
check-config /cfg/alertmanager.yml
# optional: lint rules for style and common mistakes
pint lint prometheus/config/rules/pint (from Cloudflare) is worth adding: it checks rules against a
live Prometheus, catching things like alerts that select metrics that
don't exist, missing runbook_url annotations, and expressions that
will be too expensive.
promtool check config validates syntax and structure, not
meaning. A rule selecting http_request_total (missing the s) is
perfectly valid and will never fire. Unit tests and pint's live
checks catch that class of mistake; syntax checks don't.
Reloading safely
Prometheus and Alertmanager reload their config without restarting (keeping all in-memory data):
curl -X POST localhost:9090/-/reload # needs --web.enable-lifecycle
curl -X POST localhost:9093/-/reload
docker kill -s HUP prometheus # same thing via signalIf the new config is invalid, the reload is rejected and the old config keeps running. That's safe, but silent. So alert on it:
- alert: PrometheusConfigReloadFailed
expr: prometheus_config_last_reload_successful == 0
for: 5m
labels: { severity: warning }
- alert: AlertmanagerConfigReloadFailed
expr: alertmanager_config_last_reload_successful == 0
for: 5m
labels: { severity: warning }Upgrades
- Read the release notes, especially across major versions.
Prometheus 3 changed defaults (UTF-8 metric names, the range-selector
boundary,
holt_wintersrenamed) that can change query results. - Pin image versions. This stack uses
v3.15.0, neverlatest.latestmeans an unplanned upgrade every time a container is recreated. - Upgrade one HA replica first, compare its data and rule results with the other for a day, then upgrade the second.
- TSDB format changes are rare and documented; downgrades across them may not be possible, which is another reason to stage the rollout.
Meta-monitoring
Who watches the watcher? The Stack Health dashboard watches Prometheus from inside Prometheus. That catches slow rule evaluation and growing cardinality, but it can't catch Prometheus being down. Three layers cover the gaps:
- Self-metrics, scraped by the same server (this stack): config reloads, rule failures, notification failures, TSDB health, memory.
- A second Prometheus scraping the first. In an HA pair, each replica can scrape the other.
- An external dead man's switch: the
Watchdogalert routed to a service outside your infrastructure (Healthchecks.io, PagerDuty's heartbeat, Opsgenie heartbeat, Grafana OnCall) that pages when the heartbeat stops. This is the only layer that detects "the whole alerting pipeline is gone."
The alerts that should exist about the stack itself:
up{job=~"prometheus|alertmanager"} == 0
prometheus_config_last_reload_successful == 0
increase(prometheus_rule_evaluation_failures_total[5m]) > 0
increase(prometheus_rule_group_iterations_missed_total[10m]) > 0
rate(prometheus_notifications_errors_total[5m]) > 0
prometheus_notifications_queue_length / prometheus_notifications_queue_capacity > 0.5
rate(alertmanager_notifications_failed_total[5m]) > 0
increase(prometheus_tsdb_compactions_failed_total[3h]) > 0
process_resident_memory_bytes{job="prometheus"} / <container limit> > 0.8
predict_linear(node_filesystem_avail_bytes{mountpoint="/prometheus"}[6h], 24*3600) < 0The kube-prometheus and prometheus-mixin projects ship a
well-tuned version of this whole set. Use them as a reference.
Runbooks
Every alert should have a runbook_url annotation that answers, in
order:
- What does this alert mean? In plain words.
- What's the impact? Who is affected, how badly.
- How do I check? The first three queries or dashboard links to look at.
- How do I mitigate? Restart, roll back, scale, fail over.
- Who to escalate to.
Store runbooks next to the rules in git, and link to the rendered page. An alert without a runbook pages someone who then has to reverse-engineer the PromQL at 3 a.m.
Lab
- Add the two
ConfigReloadFailedalerts toalerts.yml. Then breakprometheus.yml(an invalid YAML indent), call/-/reload, and confirm Prometheus keeps running with the old config and the metric drops to 0. Fix it and reload again. - Write a CI script
prometheus/check.shthat runs the three checks above and exits non-zero on any failure. - Add a
runbook_urlannotation toErrorBudgetBurnFastpointing at a newprometheus/runbooks/error-budget-burn.mdwith the five sections above.