forked from rancher/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
host_info.go
45 lines (40 loc) · 1.21 KB
/
host_info.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
package hostInfo
import (
"github.com/Sirupsen/logrus"
"github.com/pkg/errors"
"github.com/rancher/agent/model"
"github.com/rancher/agent/utilities/constants"
)
type Collector interface {
GetData() (map[string]interface{}, error)
KeyName() string
GetLabels(string) (map[string]string, error)
}
func CollectData(collectors []Collector) map[string]interface{} {
data := map[string]interface{}{}
for _, collector := range collectors {
collectedData, err := collector.GetData()
if err != nil {
logrus.Warnf("Failed to collect data from collector %v error msg: %v", collector.KeyName(), err.Error())
}
data[collector.KeyName()] = collectedData
}
return data
}
func HostLabels(prefix string, collectors []Collector) (map[string]string, error) {
labels := map[string]string{}
for _, collector := range collectors {
lmap, err := collector.GetLabels(prefix)
if err != nil {
return map[string]string{}, errors.Wrap(err, constants.HostLabelsError+"failed to collect labels from collectors")
}
for key, value := range lmap {
labels[key] = value
}
}
return labels, nil
}
func GetDefaultDisk(infoData model.InfoData) (string, error) {
collector := IopsCollector{}
return collector.getDefaultDisk()
}