optimize nodata

master
710leo 5 years ago
parent 256dceb624
commit 2c285e63c1

@ -110,7 +110,7 @@ func Judge(stra *model.Stra, exps []model.Exp, historyData []*dataobj.RRDData, f
Hashid: getHashId(stra.Id, firstItem),
}
sendEventIfNeed(historyData, status, event, stra.RecoveryDur)
sendEventIfNeed(historyData, status, event, stra)
}
}()
@ -389,12 +389,12 @@ func GetReqs(stra *model.Stra, metric string, endpoints []string, now int64) ([]
return reqs, nil
}
func sendEventIfNeed(historyData []*dataobj.RRDData, status []bool, event *dataobj.Event, recoveryDur int) {
func sendEventIfNeed(historyData []*dataobj.RRDData, status []bool, event *dataobj.Event, stra *model.Stra) {
isTriggered := true
for _, s := range status {
isTriggered = isTriggered && s
}
now := time.Now().Unix()
lastEvent, exists := cache.LastEvents.Get(event.ID)
if isTriggered {
event.EventType = EVENT_ALERT
@ -404,9 +404,8 @@ func sendEventIfNeed(historyData []*dataobj.RRDData, status []bool, event *datao
return
}
if len(historyData) > 0 && historyData[len(historyData)-1].Timestamp <= lastEvent.Etime {
// 产生过报警的点,就不能再使用来判断了,否则容易出现一分钟报一次的情况
// 只需要拿最后一个historyData来做判断即可因为它的时间最老
if now-lastEvent.Etime < int64(stra.AlertDur) {
//距离上次告警的时间小于告警统计周期,不再进行告警判断
return
}
@ -416,7 +415,7 @@ func sendEventIfNeed(historyData []*dataobj.RRDData, status []bool, event *datao
// 如果LastEvent是Problem报OK否则啥都不做
if exists && lastEvent.EventType[0] == 'a' {
// 如果配置了留观时长则距离上一次故障时间要大于等于recoveryDur才产生恢复事件
if time.Now().Unix()-lastEvent.Etime < int64(recoveryDur) {
if now-lastEvent.Etime < int64(stra.RecoveryDur) {
return
}

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"math"
"math/rand"
"strings"
"time"
@ -192,24 +191,6 @@ func fetchData(start, end int64, consolFun, endpoint, counter string, step int)
return resp, err
}
// 没有获取到数据 做标记处理 math.NaN()
if len(resp.Values) < 1 {
ts := start - start%int64(60)
count := (end - start) / 60
if count > 730 {
count = 730
}
if count <= 0 {
return resp, nil
}
step := (end - start) / count
for i := 0; i < int(count); i++ {
resp.Values = append(resp.Values, &dataobj.RRDData{Timestamp: ts, Value: dataobj.JsonFloat(math.NaN())})
ts += step
}
}
resp.Start = start
resp.End = end

Loading…
Cancel
Save