🎓 A1Learner
🔍
0 of 50 lessons completed

Prometheus: Alerting Rules

An alerting rule is a PromQL expression that Prometheus checks again and again, plus a name and a message for when it stays true. The first rule in this course fires when ShopSentry is down.

The first rule: ShopSentry down

This rule fires when ShopSentry stops answering for five minutes.

- alert: ShopSentryDown
  expr: up{job="shopsentry"} == 0
  for: 5m
  labels:
    severity: critical

Annotations: the human message

The summary is the one line a person reads first.

annotations:
  summary: "ShopSentry is down"
  description: "ShopSentry has been down for more than 5 minutes."

Check the rule file

promtool checks the rule file before Prometheus loads it.

promtool check rules rules/shopsentry.yml

Example

promtool check rules rules/shopsentry.yml

Key points

  • An alerting rule has an expression, a name, labels, and annotations.
  • The expression uses up, the series that is 1 when a target answers and 0 when it does not.
  • The for clause says how long the expression must stay true before the alert fires.
  • The for clause is the flapping guard: a one-second blip never becomes a page.
  • An alert starts as pending while the for time runs, then becomes firing.
  • Labels on a rule, like severity, decide where the alert is routed later.
  • Annotations hold the human text: a short summary and a longer description.

In this example, promtool checks the real rule file on the lab machine and finds both ShopSentry rules valid. Prometheus then loads the rules, and the ShopSentryDown rule sits inactive while the shop answers. The for clause of five minutes is the flapping guard shown in this lesson.

Note

An alerting rule watches a symptom, not a cause. Down is the symptom; the cause comes later.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

What does the for clause do in an alerting rule?