This commit is contained in:
uubulb 2025-01-19 21:17:11 +08:00
parent cf12f8df4d
commit 06cac05758
2 changed files with 4 additions and 5 deletions

View File

@ -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
}
}

View File

@ -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)) {