mirror of
https://github.com/nezhahq/nezha.git
synced 2025-03-12 00:38:13 -04:00
fix service (#1015)
This commit is contained in:
parent
4844b1d8a3
commit
831ddf1136
@ -97,7 +97,7 @@ func (r *AlertRule) Check(points [][]bool) (int, bool) {
|
|||||||
if hasPassedRule = boundCheck(len(points), duration, hasPassedRule); hasPassedRule {
|
if hasPassedRule = boundCheck(len(points), duration, hasPassedRule); hasPassedRule {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for timeTick := len(points); timeTick >= len(points)-duration; timeTick-- {
|
for timeTick := len(points); timeTick > len(points)-duration; timeTick-- {
|
||||||
fail++
|
fail++
|
||||||
if points[timeTick][ruleIndex] {
|
if points[timeTick][ruleIndex] {
|
||||||
hasPassedRule = true
|
hasPassedRule = true
|
||||||
|
@ -120,7 +120,7 @@ func NewServiceSentinel(serviceSentinelDispatchBus chan<- *model.Service, sc *Se
|
|||||||
|
|
||||||
var mhs []model.ServiceHistory
|
var mhs []model.ServiceHistory
|
||||||
// 加载当日记录
|
// 加载当日记录
|
||||||
DB.Where("created_at >= ?", today).Find(&mhs)
|
DB.Where("created_at >= ? AND server_id = 0", today).Find(&mhs)
|
||||||
totalDelay := make(map[uint64]float32)
|
totalDelay := make(map[uint64]float32)
|
||||||
totalDelayCount := make(map[uint64]float32)
|
totalDelayCount := make(map[uint64]float32)
|
||||||
for _, mh := range mhs {
|
for _, mh := range mhs {
|
||||||
@ -233,7 +233,7 @@ func (ss *ServiceSentinel) loadServiceHistory() error {
|
|||||||
|
|
||||||
// 加载服务监控历史记录
|
// 加载服务监控历史记录
|
||||||
var mhs []model.ServiceHistory
|
var mhs []model.ServiceHistory
|
||||||
DB.Where("created_at > ? AND created_at < ?", today.AddDate(0, 0, -29), today).Find(&mhs)
|
DB.Where("created_at > ? AND created_at < ? AND server_id = 0", today.AddDate(0, 0, -29), today).Find(&mhs)
|
||||||
var delayCount = make(map[int]int)
|
var delayCount = make(map[int]int)
|
||||||
for _, mh := range mhs {
|
for _, mh := range mhs {
|
||||||
dayIndex := 28 - (int(today.Sub(mh.CreatedAt).Hours()) / 24)
|
dayIndex := 28 - (int(today.Sub(mh.CreatedAt).Hours()) / 24)
|
||||||
@ -412,6 +412,7 @@ func (ss *ServiceSentinel) worker() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
css = nil
|
css = nil
|
||||||
|
|
||||||
mh := r.Data
|
mh := r.Data
|
||||||
if mh.Type == model.TaskTypeTCPPing || mh.Type == model.TaskTypeICMPPing {
|
if mh.Type == model.TaskTypeTCPPing || mh.Type == model.TaskTypeICMPPing {
|
||||||
serviceTcpMap, ok := ss.serviceResponsePing[mh.GetId()]
|
serviceTcpMap, ok := ss.serviceResponsePing[mh.GetId()]
|
||||||
@ -426,7 +427,6 @@ func (ss *ServiceSentinel) worker() {
|
|||||||
ts.count++
|
ts.count++
|
||||||
ts.ping = (ts.ping*float32(ts.count-1) + mh.Delay) / float32(ts.count)
|
ts.ping = (ts.ping*float32(ts.count-1) + mh.Delay) / float32(ts.count)
|
||||||
if ts.count == Conf.AvgPingCount {
|
if ts.count == Conf.AvgPingCount {
|
||||||
ts.count = 0
|
|
||||||
if err := DB.Create(&model.ServiceHistory{
|
if err := DB.Create(&model.ServiceHistory{
|
||||||
ServiceID: mh.GetId(),
|
ServiceID: mh.GetId(),
|
||||||
AvgDelay: ts.ping,
|
AvgDelay: ts.ping,
|
||||||
@ -435,10 +435,12 @@ func (ss *ServiceSentinel) worker() {
|
|||||||
}).Error; err != nil {
|
}).Error; err != nil {
|
||||||
log.Printf("NEZHA>> Failed to save service monitor metrics: %v", err)
|
log.Printf("NEZHA>> Failed to save service monitor metrics: %v", err)
|
||||||
}
|
}
|
||||||
|
ts.count = 0
|
||||||
ts.ping = mh.Delay
|
ts.ping = mh.Delay
|
||||||
}
|
}
|
||||||
serviceTcpMap[r.Reporter] = ts
|
serviceTcpMap[r.Reporter] = ts
|
||||||
}
|
}
|
||||||
|
|
||||||
ss.serviceResponseDataStoreLock.Lock()
|
ss.serviceResponseDataStoreLock.Lock()
|
||||||
// 写入当天状态
|
// 写入当天状态
|
||||||
if mh.Successful {
|
if mh.Successful {
|
||||||
|
Loading…
Reference in New Issue
Block a user