Prometheus and Grafana: Capstone: ShopSentry, Fully Monitored
The capstone pulls the whole course together into one monitored service. ShopSentry gets recording rules, a finished dashboard, tested alerts, and a real receiver.
Check the rules file
Three recording rules and two alerting rules live in one file. Promtool counts them for you.
promtool check rules shopsentry-rules.ymlTest the alerts before they ship
The test file feeds fake samples to the rules and pins the expected alert at each time.
promtool test rules shopsentry-rules-test.ymlWatch a recording rule work
The request rate series appears once Prometheus evaluates the rule. The value is real traffic.
curl -s "http://127.0.0.1:19105/api/v1/query?query=job%3Ashopsentry%3Arequest_rate_5m"Example
curl -s "http://127.0.0.1:18105/break?mode=down" && sleep 105 && curl -s "http://127.0.0.1:19105/api/v1/alerts" | python3 -c "import json,sys; print([(a['labels']['alertname'],a['state']) for a in json.load(sys.stdin)['data']['alerts']])"Key points
- The service is instrumented already, with counters, a histogram, and the shopsentry_up gauge.
- Recording rules precompute the request rate, the error rate, and the p95 latency.
- The dashboard shows the four golden signals: traffic, latency, errors, and saturation.
- Dashboard variables let one dashboard serve every job and route.
- The dashboard JSON is committed as code, so it can be reviewed and restored.
- Prometheus alerting rules are tested with promtool before they ship.
- Alertmanager routes the alerts to a real webhook receiver that logs every notification.
- A Grafana alert rule watches the same service from the Grafana side.
- Breaking the service fires the whole pipeline, from the rule to the receiver.
In this example, breaking ShopSentry fires the whole pipeline. The down switch makes the shop answer 503, the Prometheus rules go pending and then firing after their one minute wait, Alertmanager shows both alerts active, and the webhook receiver logs the firing notification for ShopSentryDown. Healing the shop afterwards sends a resolved notification for it. The dashboard, the rules, and the receiver are all real files and real processes, not pictures of them.
Note
The capstone runs on the lab ports in this lesson, and your ports will differ.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
In the capstone, what proves the alert pipeline works end to end?