-
Notifications
You must be signed in to change notification settings - Fork 17
/
modules.go
59 lines (49 loc) · 1.4 KB
/
modules.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 cagent
import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/cloudradar-monitoring/cagent/pkg/common"
"github.com/cloudradar-monitoring/cagent/pkg/monitoring"
"github.com/cloudradar-monitoring/cagent/pkg/monitoring/mysql"
"github.com/cloudradar-monitoring/cagent/pkg/monitoring/raid"
"github.com/cloudradar-monitoring/cagent/pkg/monitoring/storcli"
)
var modules []monitoring.Module
func (ca *Cagent) initModules() {
if len(modules) > 0 {
return
}
l := []func() monitoring.Module{
func() monitoring.Module {
return storcli.CreateModule(ca.Config.StorCLI.BinaryPath)
},
func() monitoring.Module {
return raid.CreateModule(ca.Config.SoftwareRAIDMonitoring)
},
func() monitoring.Module {
return mysql.CreateModule(&ca.Config.MysqlMonitoring)
},
}
for _, f := range l {
m := f()
if m.IsEnabled() {
modules = append(modules, m)
}
}
}
func (ca *Cagent) collectModulesMeasurements() ([]*monitoring.ModuleReport, error) {
var result []*monitoring.ModuleReport
var errs common.ErrorCollector
ca.initModules()
for _, m := range modules {
reports, err := m.Run()
if err != nil {
err = errors.Wrapf(err, "while executing module '%s'", m.GetDescription())
logrus.WithError(err).Debug()
errs.Add(err)
continue
}
result = append(result, reports...)
}
return result, errors.Wrap(errs.Combine(), "while collecting modules measurements")
}