refactor: 调整主机监控任务时间为整分钟执行 (#6379)

pull/6382/head
3 months ago committed by GitHub
parent feb6f4cbe0
commit 94e0c80d47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -201,16 +201,19 @@ func StartMonitor(removeBefore bool, interval string) error {
service := NewIMonitorService() service := NewIMonitorService()
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
monitorCancel = cancel monitorCancel = cancel
monitorID, err := global.Cron.AddJob(fmt.Sprintf("@every %sm", interval), service) now := time.Now()
if err != nil { nextMinute := now.Truncate(time.Minute).Add(time.Minute)
return err time.AfterFunc(time.Until(nextMinute), func() {
} monitorID, err := global.Cron.AddJob(fmt.Sprintf("@every %sm", interval), service)
if err != nil {
return
}
global.MonitorCronID = monitorID
})
service.Run() service.Run()
go service.saveIODataToDB(ctx, float64(intervalItem)) go service.saveIODataToDB(ctx, float64(intervalItem))
go service.saveNetDataToDB(ctx, float64(intervalItem)) go service.saveNetDataToDB(ctx, float64(intervalItem))
global.MonitorCronID = monitorID
return nil return nil
} }

Loading…
Cancel
Save