🎓 A1Learner
🔍
0 of 50 lessons completed

Prometheus: Fire an Alert for Real

A fired alert is the whole alerting pipeline proved in one run: a real failure, a pending alert, a firing alert, and a notification that arrives. This lesson breaks ShopSentry on purpose and watches every step.

Stop the shop

This command stops the ShopSentry process on its port.

fuser -k 18104/tcp

Watch the alert state

This call lists every active alert and its state.

curl -s http://127.0.0.1:19104/api/v1/alerts

The listener that receives the notification

The small Python listener prints every POST it gets.

python3 webhook_listener.py

Example

curl -s http://127.0.0.1:19124/api/v2/alerts | jq '.[0].labels'

Key points

  • Stop the ShopSentry process, so Prometheus cannot scrape it at all.
  • The up series for ShopSentry drops to 0 at the next scrape.
  • The ShopSentryDown alert turns pending as soon as up is 0.
  • The alert turns firing only after the for time of 5 minutes has passed.
  • Alertmanager waits group_wait, then posts the alert to the webhook receiver.
  • The webhook listener prints the real notification, with the alert name and labels.
  • Restart ShopSentry after the test, and the alert resolves on its own.

In this example, the alert went pending at 23:53:04 UTC and firing at 23:58:04 UTC, five minutes later, exactly as the for clause requires. Alertmanager then posted a real notification to the webhook receiver, with status firing and notification_reason first notification. Restarting ShopSentry made up return to 1 and the alert resolve.

Note

The /break switch leaves /metrics answering, so up stays 1.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

Why does the alert stay pending for five minutes before firing?