forked from rancher/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu.go
47 lines (41 loc) · 1.02 KB
/
cpu.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
package hostInfo
import (
"fmt"
"github.com/pkg/errors"
"github.com/rancher/agent/utilities/constants"
"os"
)
type CPUCollector struct {
}
func (c CPUCollector) GetData() (map[string]interface{}, error) {
data := map[string]interface{}{}
cInfo, err := c.getCPUInfo()
if err != nil {
return data, errors.Wrap(err, constants.CPUGetDataError+"failed to get cpu info")
}
percent, err := c.getCPUPercentage()
if err != nil {
return data, errors.Wrap(err, constants.CPUGetDataError+"failed to get cpu percentage")
}
for key, value := range percent {
data[key] = value
}
for key, value := range cInfo {
data[key] = value
}
for key, value := range c.getCPULoadAverage() {
data[key] = value
}
return data, nil
}
func (c CPUCollector) KeyName() string {
return "cpuInfo"
}
func (c CPUCollector) GetLabels(prefix string) (map[string]string, error) {
if _, err := os.Stat("/dev/kvm"); err == nil {
return map[string]string{
fmt.Sprintf("%s.%s", prefix, "kvm"): "true",
}, nil
}
return map[string]string{}, nil
}