-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.go
59 lines (50 loc) · 1.4 KB
/
controller.go
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
package main
import (
"github.com/milonoir/schwer/resource"
)
// Controller controls resource loads and monitors.
type Controller struct {
cpuLoad resource.Load
memLoad resource.Load
cpuMonitor resource.Monitor
memMonitor resource.Monitor
}
// NewController returns a new Controller.
func NewController(cpuLoad, memLoad resource.Load, cpuMonitor, memMonitor resource.Monitor) *Controller {
return &Controller{
cpuLoad: cpuLoad,
memLoad: memLoad,
cpuMonitor: cpuMonitor,
memMonitor: memMonitor,
}
}
// Start starts up resource monitors and loads.
func (c *Controller) Start() {
c.cpuMonitor.Start()
c.memMonitor.Start()
c.cpuLoad.Start()
c.memLoad.Start()
}
// Stop stops resource loads and monitors.
func (c *Controller) Stop() {
c.cpuLoad.Stop()
c.memLoad.Stop()
c.cpuMonitor.Stop()
c.memMonitor.Stop()
}
// UpdateCPULoad sends an update to the CPU load.
func (c *Controller) UpdateCPULoad(pct int64) {
c.cpuLoad.Update(pct)
}
// UpdateMemLoad sends an update to the memory load.
func (c *Controller) UpdateMemLoad(size int64) {
c.memLoad.Update(size)
}
// CPUUtilisationLevels returns the latest CPU utilisation levels from the CPU load monitor.
func (c *Controller) CPUUtilisationLevels() interface{} {
return c.cpuMonitor.Usage()
}
// MemStats returns the latest memory stats from the memory load monitor.
func (c *Controller) MemStats() interface{} {
return c.memMonitor.Usage()
}