From 06cac05758ca043f3b559ecd0da4322d949ae2b3 Mon Sep 17 00:00:00 2001 From: uubulb Date: Sun, 19 Jan 2025 21:17:11 +0800 Subject: [PATCH] changes --- model/alertrule.go | 6 +++--- service/singleton/alertsentinel.go | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/model/alertrule.go b/model/alertrule.go index cc1b55b..9b4fca0 100644 --- a/model/alertrule.go +++ b/model/alertrule.go @@ -103,14 +103,14 @@ func (r *AlertRule) Check(points [][]bool) (maxDuration int, passed bool) { continue } total, fail := 0, 0 - for _, point := range points[len(points)-duration:] { + for timeTick := len(points) - duration; timeTick < len(points); timeTick++ { total++ - if !point[ruleId] { + if !points[timeTick][ruleId] { fail++ } } // 当70%以上的采样点未通过规则判断时 才认为当前检查未通过 - if fail*100/total*100 <= 70 { + if fail*100/total <= 70 { hasPassedRule = true } } diff --git a/service/singleton/alertsentinel.go b/service/singleton/alertsentinel.go index ce92868..9d94d36 100644 --- a/service/singleton/alertsentinel.go +++ b/service/singleton/alertsentinel.go @@ -77,8 +77,7 @@ func AlertSentinelStart() { lastPrint := time.Now() var checkCount uint64 ticker := time.Tick(3 * time.Second) // 3秒钟检查一次 - for { - startedAt := <-ticker + for startedAt := range ticker { checkStatus() checkCount++ if lastPrint.Before(startedAt.Add(-1 * time.Hour)) {