diff --git a/model/alertrule.go b/model/alertrule.go index 2653b1c..821a24a 100644 --- a/model/alertrule.go +++ b/model/alertrule.go @@ -75,17 +75,15 @@ func (r *AlertRule) Snapshot(cycleTransferStats *CycleTransferStats, server *Ser func (r *AlertRule) Check(points [][]bool) (maxDuration int, passed bool) { failCount := 0 // 检查未通过的个数 - for i, rule := range r.Rules { + for ruleId, rule := range r.Rules { if rule.IsTransferDurationRule() { // 循环区间流量报警 if maxDuration < 1 { maxDuration = 1 } - for j := len(points) - 1; j >= 0; j-- { - if !points[j][i] { - failCount++ - break - } + if len(points) > 0 && !points[len(points)-1][ruleId] { + failCount++ + break } } else { // 常规报警 @@ -96,11 +94,10 @@ func (r *AlertRule) Check(points [][]bool) (maxDuration int, passed bool) { if len(points) < duration { continue } - total, fail := 0.0, 0.0 - for j := len(points) - duration; j < len(points); j++ { + for timeTick := len(points) - duration; timeTick < len(points); timeTick++ { total++ - if !points[j][i] { + if !points[timeTick][ruleId] { fail++ } } diff --git a/service/singleton/alertsentinel.go b/service/singleton/alertsentinel.go index 891f487..125d810 100644 --- a/service/singleton/alertsentinel.go +++ b/service/singleton/alertsentinel.go @@ -26,7 +26,7 @@ type NotificationHistory struct { var ( AlertsLock sync.RWMutex Alerts []*model.AlertRule - alertsStore map[uint64]map[uint64][][]bool // [alert_id][server_id] -> 对应报警规则的检查结果 + alertsStore map[uint64]map[uint64][][]bool // [alert_id][server_id] -> [timeTick][ruleId] 时间点对应的rule的检查结果 alertsPrevState map[uint64]map[uint64]uint8 // [alert_id][server_id] -> 对应报警规则的上一次报警状态 AlertsCycleTransferStatsStore map[uint64]*model.CycleTransferStats // [alert_id] -> 对应报警规则的周期流量统计 ) diff --git a/service/singleton/frontend-templates.yaml b/service/singleton/frontend-templates.yaml index 838dcd5..2cbf718 100644 --- a/service/singleton/frontend-templates.yaml +++ b/service/singleton/frontend-templates.yaml @@ -2,14 +2,14 @@ name: "OfficialAdmin" repository: "https://github.com/nezhahq/admin-frontend" author: "nezhahq" - version: "v1.4.3" + version: "v1.4.4" isadmin: true isofficial: true - path: "user-dist" name: "Official" repository: "https://github.com/hamster1963/nezha-dash-v1" author: "hamster1963" - version: "v1.9.3" + version: "v1.10.3" isofficial: true - path: "nazhua-dist" name: "Nazhua"