← Jonghyun Beik

Alert service for GPU scan workers

VBody · 2026.03–10 · FastAPI, Redis Streams, Prometheus, Discord

워커 다운: gpu-worker-03-gpu0
Worker IDgpu-worker-03-gpu0
GPUNVIDIA GeForce RTX 5070 Ti
Statusidle
Last Heartbeat2026-04-23T11:49:42.945365Z
VBody Monitor | CRITICAL · 26. 4. 23. 오후 8:51
워커 복구: gpu-worker-03-gpu0
Worker IDgpu-worker-03-gpu0
GPUNVIDIA GeForce RTX 5070 Ti
Statusidle
VBody Monitor | INFO · 26. 4. 23. 오후 8:53
A real pair from the production channel, 2026-04-23 (status icons omitted; no customer data in either). Last heartbeat 20:49:42 KST, down alert 20:51, recovery alert 20:53. The titles now read "처리 서버 응답 없음" and "처리 서버 정상 복구", plain Korean for the support staff who act on them.

The outage that started it

Kiosks upload scans, 3–5 GPU workers analyze them, and reports go to clinics. In March 2026 a GPU worker stopped and nobody noticed for days; it came back only after a physical reboot. Detection and alert code existed but nothing ran it, and errors lived only in console logs. The team is small, and the people who handle site support are not developers.

Why a separate service

Checks inside the API
Stops exactly when the API crashes or redeploys, the moment monitoring matters most.
Sentry + Grafana
Cannot take operational actions (DLQ retry), $26–75/month, one more tool to watch.
Separate monitoring service (chosen)
One more service to run (~$5/month) and no automatic DB/HTTP instrumentation. Moved out of the API into its own repo in 2026.04.

Delivering each alert once

One firing and one recovery alert per incident
Repeated alerts during an outage get muted. Firing state is a Redis key (SET NX, 24 h TTL), so a restart does not re-send; recovery needs 2 healthy checks in a row.
Redis Stream over Pub/Sub
Pub/Sub drops messages when nobody listens, so failures during a monitor redeploy would be lost. A stream keeps them until consumed.
A pending claim, then a sent mark
Marking before sending loses an alert when the send fails; marking after duplicates it on redelivery. The pending claim expires after 5 minutes, so after a crash mid-send the alert goes out again, possibly twice.
Text for the people who act on it
Center, scan, server, retry count, failed stage and a hint; the title links to the job's timeline.
API + GPU workerserrors Redis Streamkept until read Monitoring servicedetect loop · 11 rulespending → sent Discordfire · recover Heartbeat keys, Postgreslatest values, job state read each loop · hourly reconcile
Errors go to a Redis Stream; the monitor reads it, marks pending then sent, and posts to Discord. Heartbeats and job state are read each loop and reconciled hourly.

What 2.1 minutes measures

For each worker_down alert, the time until the next recovery alert for the same worker, from monitor.alert_history: 21 pairs between 2026-08-07 and 09-30, median 2.1 min, longest 27.3 min; every down alert had a matching recovery. The loop runs every 60 s and recovery needs two healthy checks in a row, so about 2 minutes is the floor: most downs were brief and over by the next check. The number shows that every incident was opened and closed by an alert. How fast a down was noticed was not measured separately.

Failed scans, 2026.07–10: 43 of 47 final failures alerted automatically (job-failed alerts in alert_history joined to scans whose final status is failed). Of the 4 misses, 1 was grouped away by the 60 s per-error-group limit across different scans and 3 never finished uploading, so they were outside alert scope; the limit position and reconcile criteria are being changed. No single transaction spans Redis, the database and Discord, so this does not claim zero loss.

Who did what

Mine: the detection loop, alert engine and rules, stream delivery, the reconcile job, the job-detail data API, moving the monitor into its own repo. By git blame on origin/main (2026-11-17), 89% of the current lines under app/ and tests/ are mine; 22 of my 42 commits were co-authored with Claude Code. Not mine: retry ×3 and the DLQ, which existed before I joined, and the job-detail screen, built by a teammate.