An alert is a query with patience — the for duration, pending and firing states
An alerting rule is a query re-run at a fixed interval whose for duration holds the alert pending until the condition has stayed true continuously that long, trading a known extra delay for far fewer false pages.
We can compute honest numbers; now a machine must decide when one of them is bad enough, and long enough, to wake someone.
Scene 07
An alert is a query with patience
- Watch
- Try it
- Predict
- Capture
How does a number become a page without paging on every blip? A machine has to watch checkout's 5xx ratio for us. Watch the ticks march along the bottom: at every one of them the same query runs again and the answer is compared to the threshold. The strip underneath records what the alert decided after each evaluation. Two brief spikes and one real outage go past — see which of them actually rings a bell.
Highlighted lines are the ones running in the diagram right now.
def evaluate(rule): # every evaluation_intervalvalue = query(rule.expr)if value > rule.threshold:update_state(rule, now())else:clear(rule)def run_rules(rules):while True:for rule in rules:evaluate(rule)sleep(evaluation_interval) # 1m default
def update_state(rule, now):if rule.active is None:rule.active = Alert(started_at=now)held = now - rule.active.started_atif held >= rule.for_duration: # `for`rule.active.state = FIRINGpage(rule.active)else:rule.active.state = PENDINGdef clear(rule):del rule.active
def page(alert):if alert.state != FIRING:returnif alert.already_paged:returnalert.already_paged = Truesend_page(alert)def worst_case_ttd(rule):return (scrape_interval+ evaluation_interval+ rule.for_duration)
Where this sits in Metrics / Monitoring System
Scene 07 of 18, in the Wake a human act — Patient rules, one page, and a heartbeat for the monitor.. An alerting rule is a query re-run every interval; its waiting period holds the alert pending until the condition has stayed true that long, trading a known delay for far fewer false pages.
Up next. Now that rules decide something is wrong, the next question is who gets told, and how 500 firing alerts avoid becoming 500 pages.
All 18 scenes in Metrics / Monitoring System · Every curriculum