From 438a8c393cb453dd6367aad0700a990f1a220ba4 Mon Sep 17 00:00:00 2001 From: naiba Date: Mon, 19 Jul 2021 17:38:18 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20=E6=8F=90=E5=8D=87=E5=81=A5?= =?UTF-8?q?=E5=A3=AE=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- service/dao/dao.go | 2 +- service/dao/servicesentinel.go | 15 +++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0cab302..a21be19 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@


-    +   

:trollface: 哪吒监控 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。

diff --git a/service/dao/dao.go b/service/dao/dao.go index 6a399e0..a47e711 100644 --- a/service/dao/dao.go +++ b/service/dao/dao.go @@ -13,7 +13,7 @@ import ( pb "github.com/naiba/nezha/proto" ) -var Version = "v0.9.8" // !!记得修改 README 中的 badge 版本!! +var Version = "v0.9.9" // !!记得修改 README 中的 badge 版本!! var ( Conf *model.Config diff --git a/service/dao/servicesentinel.go b/service/dao/servicesentinel.go index 5bfbc0c..9554966 100644 --- a/service/dao/servicesentinel.go +++ b/service/dao/servicesentinel.go @@ -132,6 +132,7 @@ func (ss *ServiceSentinel) Monitors() []model.Monitor { func (ss *ServiceSentinel) OnMonitorUpdate() { var monitors []model.Monitor DB.Find(&monitors) + ss.monitorsLock.Lock() defer ss.monitorsLock.Unlock() ss.monitors = make(map[uint64]model.Monitor) @@ -145,14 +146,11 @@ func (ss *ServiceSentinel) OnMonitorUpdate() { } } - ss.monthlyStatusLock.Lock() - defer ss.monthlyStatusLock.Unlock() year, month, day := time.Now().Date() today := time.Date(year, month, day, 0, 0, 0, 0, time.Local) - // 加载历史记录 - var mhs []model.MonitorHistory - DB.Where("created_at >= ? AND created_at < ?", today.AddDate(0, 0, -29), today).Find(&mhs) + ss.monthlyStatusLock.Lock() + defer ss.monthlyStatusLock.Unlock() for i := 0; i < len(monitors); i++ { ServiceSentinelShared.monthlyStatus[monitors[i].ID] = &model.ServiceItemResponse{ Monitor: monitors[i], @@ -162,8 +160,13 @@ func (ss *ServiceSentinel) OnMonitorUpdate() { } } - // 整合数据 + // 加载历史记录 + var mhs []model.MonitorHistory + DB.Where("created_at >= ? AND created_at < ?", today.AddDate(0, 0, -29), today).Find(&mhs) for i := 0; i < len(mhs); i++ { + if ServiceSentinelShared.monthlyStatus[mhs[i].MonitorID] == nil { + continue + } dayIndex := 28 - (int(today.Sub(mhs[i].CreatedAt).Hours()) / 24) if mhs[i].Successful { ServiceSentinelShared.monthlyStatus[mhs[i].MonitorID].TotalUp++