diff --git a/README.md b/README.md index 1ff2bcb..7bbd64e 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@
LOGO designed by 熊大 .

-    +   

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

diff --git a/cmd/dashboard/main.go b/cmd/dashboard/main.go index 9343c73..722a0bc 100644 --- a/cmd/dashboard/main.go +++ b/cmd/dashboard/main.go @@ -17,11 +17,7 @@ import ( "github.com/naiba/nezha/service/dao" ) -var serviceSentinelDispatchBus chan model.Monitor - func init() { - serviceSentinelDispatchBus = make(chan model.Monitor) - shanghai, err := time.LoadLocation("Asia/Shanghai") if err != nil { panic(err) @@ -59,7 +55,6 @@ func initSystem() { dao.DB.AutoMigrate(model.Server{}, model.User{}, model.Notification{}, model.AlertRule{}, model.Monitor{}, model.MonitorHistory{}, model.Cron{}, model.Transfer{}) - dao.NewServiceSentinel(serviceSentinelDispatchBus) loadServers() //加载服务器列表 loadCrons() //加载计划任务 @@ -178,8 +173,10 @@ func loadCrons() { func main() { cleanMonitorHistory() go rpc.ServeRPC(dao.Conf.GRPCPort) + serviceSentinelDispatchBus := make(chan model.Monitor) go rpc.DispatchTask(serviceSentinelDispatchBus) go dao.AlertSentinelStart() + dao.NewServiceSentinel(serviceSentinelDispatchBus) srv := controller.ServeWeb(dao.Conf.HTTPPort) graceful.Graceful(func() error { return srv.ListenAndServe() diff --git a/cmd/dashboard/rpc/rpc.go b/cmd/dashboard/rpc/rpc.go index 02604d1..7a435cc 100644 --- a/cmd/dashboard/rpc/rpc.go +++ b/cmd/dashboard/rpc/rpc.go @@ -28,10 +28,10 @@ func DispatchTask(serviceSentinelDispatchBus <-chan model.Monitor) { workedServerIndex := 0 for task := range serviceSentinelDispatchBus { round := 0 - prevIndex := workedServerIndex + endIndex := workedServerIndex dao.SortedServerLock.RLock() - // 如果已经轮了一整圈没有合适机器去请求,跳出循环 - for round == 0 && prevIndex != workedServerIndex { + // 如果已经轮了一整圈又轮到自己,没有合适机器去请求,跳出循环 + for round < 1 || workedServerIndex < endIndex { // 如果到了圈尾,再回到圈头,圈数加一,游标重置 if workedServerIndex == len(dao.SortedServerList) { workedServerIndex = 0 diff --git a/service/dao/dao.go b/service/dao/dao.go index 3c03303..f7f720f 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.33" // !!记得修改 README 中的 badge 版本!! +var Version = "v0.9.34" // !!记得修改 README 中的 badge 版本!! var ( Conf *model.Config diff --git a/service/dao/servicesentinel.go b/service/dao/servicesentinel.go index 7ae4281..e255ab8 100644 --- a/service/dao/servicesentinel.go +++ b/service/dao/servicesentinel.go @@ -154,12 +154,8 @@ func (ss *ServiceSentinel) loadMonitorHistory() { panic(err) } ss.monitors[monitors[i].ID] = monitors[i] - if len(ss.serviceCurrentStatusData[monitors[i].ID]) == 0 { - ss.serviceCurrentStatusData[monitors[i].ID] = make([]model.MonitorHistory, _CurrentStatusSize) - } - if ss.serviceStatusToday[monitors[i].ID] == nil { - ss.serviceStatusToday[monitors[i].ID] = &_TodayStatsOfMonitor{} - } + ss.serviceCurrentStatusData[monitors[i].ID] = make([]model.MonitorHistory, _CurrentStatusSize) + ss.serviceStatusToday[monitors[i].ID] = &_TodayStatsOfMonitor{} } year, month, day := time.Now().Date() @@ -216,6 +212,10 @@ func (ss *ServiceSentinel) OnMonitorUpdate(m model.Monitor) error { Up: &[30]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Down: &[30]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, } + ss.serviceResponseDataStoreLock.Lock() + defer ss.serviceResponseDataStoreLock.Unlock() + ss.serviceCurrentStatusData[m.ID] = make([]model.MonitorHistory, _CurrentStatusSize) + ss.serviceStatusToday[m.ID] = &_TodayStatsOfMonitor{} } // 更新这个任务 ss.monitors[m.ID] = &m