-
Notifications
You must be signed in to change notification settings - Fork 17
/
vm.go
34 lines (29 loc) · 904 Bytes
/
vm.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
package cagent
import (
"github.com/sirupsen/logrus"
"github.com/cloudradar-monitoring/cagent/pkg/common"
"github.com/cloudradar-monitoring/cagent/pkg/monitoring/vmstat"
"github.com/cloudradar-monitoring/cagent/pkg/monitoring/vmstat/types"
)
func (ca *Cagent) getVMStatMeasurements(f func(string, common.MeasurementsMap, error)) {
ca.vmstatLazyInit.Do(func() {
if err := vmstat.Init(); err != nil {
logrus.Error("vmstat: cannot instantiate virtual machines API: ", err.Error())
return
}
for _, name := range ca.Config.VirtualMachinesStat {
vm, err := vmstat.Acquire(name)
if err != nil {
if err != types.ErrNotAvailable {
logrus.Warnf("vmstat: Error while acquiring vm provider \"%s\": %s", name, err.Error())
}
} else {
ca.vmWatchers[name] = vm
}
}
})
for name, p := range ca.vmWatchers {
res, err := p.GetMeasurements()
f(name, res, err)
}
}