optimize nodata
This commit is contained in:
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),
|
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
|
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
|
isTriggered := true
|
||||||
for _, s := range status {
|
for _, s := range status {
|
||||||
isTriggered = isTriggered && s
|
isTriggered = isTriggered && s
|
||||||
}
|
}
|
||||||
|
now := time.Now().Unix()
|
||||||
lastEvent, exists := cache.LastEvents.Get(event.ID)
|
lastEvent, exists := cache.LastEvents.Get(event.ID)
|
||||||
if isTriggered {
|
if isTriggered {
|
||||||
event.EventType = EVENT_ALERT
|
event.EventType = EVENT_ALERT
|
||||||
|
@ -404,9 +404,8 @@ func sendEventIfNeed(historyData []*dataobj.RRDData, status []bool, event *datao
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(historyData) > 0 && historyData[len(historyData)-1].Timestamp <= lastEvent.Etime {
|
if now-lastEvent.Etime < int64(stra.AlertDur) {
|
||||||
// 产生过报警的点,就不能再使用来判断了,否则容易出现一分钟报一次的情况
|
//距离上次告警的时间小于告警统计周期,不再进行告警判断
|
||||||
// 只需要拿最后一个historyData来做判断即可,因为它的时间最老
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,7 +415,7 @@ func sendEventIfNeed(historyData []*dataobj.RRDData, status []bool, event *datao
|
||||||
// 如果LastEvent是Problem,报OK,否则啥都不做
|
// 如果LastEvent是Problem,报OK,否则啥都不做
|
||||||
if exists && lastEvent.EventType[0] == 'a' {
|
if exists && lastEvent.EventType[0] == 'a' {
|
||||||
// 如果配置了留观时长,则距离上一次故障时间要大于等于recoveryDur,才产生恢复事件
|
// 如果配置了留观时长,则距离上一次故障时间要大于等于recoveryDur,才产生恢复事件
|
||||||
if time.Now().Unix()-lastEvent.Etime < int64(recoveryDur) {
|
if now-lastEvent.Etime < int64(stra.RecoveryDur) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"math"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -192,24 +191,6 @@ func fetchData(start, end int64, consolFun, endpoint, counter string, step int)
|
||||||
return resp, err
|
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.Start = start
|
||||||
resp.End = end
|
resp.End = end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue