|
|
@ -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
|
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
|
|
|
nextMinute := now.Truncate(time.Minute).Add(time.Minute)
|
|
|
|
|
|
|
|
time.AfterFunc(time.Until(nextMinute), func() {
|
|
|
|
monitorID, err := global.Cron.AddJob(fmt.Sprintf("@every %sm", interval), service)
|
|
|
|
monitorID, err := global.Cron.AddJob(fmt.Sprintf("@every %sm", interval), service)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|