mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
feat(cron): add automatic alert detector for anomaly monitoring
Implement AlertDetector background task that runs every minute to detect and create alerts for various anomalies: - Rate limit detection: monitors masters hitting rate limits - Error spike detection: flags keys with >= 10% error rate - Quota exceeded: warns when key quota usage >= 90% - Provider down: alerts when API keys have >= 50% failure rate Includes fingerprint-based deduplication with 5-minute cooldown to prevent duplicate alerts for the same issue.
This commit is contained in:
@@ -207,6 +207,13 @@ func main() {
|
||||
defer cancelToken()
|
||||
go tokenRefresher.Start(tokenCtx)
|
||||
|
||||
// Alert Detector
|
||||
alertDetectorConfig := cron.DefaultAlertDetectorConfig()
|
||||
alertDetector := cron.NewAlertDetector(db, logDB, rdb, service.NewStatsService(rdb), alertDetectorConfig, logger)
|
||||
alertDetectorCtx, cancelAlertDetector := context.WithCancel(context.Background())
|
||||
defer cancelAlertDetector()
|
||||
go alertDetector.Start(alertDetectorCtx)
|
||||
|
||||
adminService, err := service.NewAdminService()
|
||||
if err != nil {
|
||||
fatal(logger, "failed to create admin service", "err", err)
|
||||
|
||||
Reference in New Issue
Block a user