package resources import ( "agent/cmd/agent/global" "errors" "linkfog.com/public/lib/l" "time" ) var ( detectInterval = 30 * time.Second // 周期检测间隔 detectCPURateRange = 30 * time.Second // 计算cpu稳定占比的区间 ) type Resources struct { isRunning bool watch *Watch } func New() *Resources { r := &Resources{} r.watch = NewWatch(WatchConfig{ DetectInterval: detectInterval, DetectCPURateRange: detectCPURateRange, }) return r } func (r *Resources) Name() string { return global.ResourceModuleName } func (r *Resources) Start() error { if r.IsRunning() { return nil } l.Info("init resources module") if r.watch == nil { return errors.New("resources watch is nil") } l.Info("start resources watch") go r.watch.StartWatch() r.isRunning = true l.Info("init resources module success") return nil } func (r *Resources) Stop() { if r.IsRunning() { r.isRunning = false r.watch.Stop() } } func (r *Resources) IsRunning() bool { return r.isRunning } func (r *Resources) Receive(msg *global.Message) error { return nil }