resources.go 1.07 KB
Newer Older
Lei Li's avatar
Lei Li committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
}
Lei Li's avatar
Lei Li committed
61
62
63
64

func (r *Resources) Receive(msg *global.Message) error {
	return nil
}