forked from slashdoom/aruba_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collectors.go
75 lines (59 loc) · 2.05 KB
/
collectors.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"github.com/slashdoom/aruba_exporter/collector"
"github.com/slashdoom/aruba_exporter/config"
"github.com/slashdoom/aruba_exporter/connector"
"github.com/slashdoom/aruba_exporter/interfaces"
"github.com/slashdoom/aruba_exporter/system"
"github.com/slashdoom/aruba_exporter/wireless"
)
type collectors struct {
collectors map[string]collector.RPCCollector
devices map[string][]collector.RPCCollector
cfg *config.Config
}
func collectorsForDevices(devices []*connector.Device, cfg *config.Config) *collectors {
c := &collectors{
collectors: make(map[string]collector.RPCCollector),
devices: make(map[string][]collector.RPCCollector),
cfg: cfg,
}
for _, d := range devices {
c.initCollectorsForDevice(d)
}
return c
}
func (c *collectors) initCollectorsForDevice(device *connector.Device) {
f := c.cfg.FeaturesForDevice(device.Host)
c.devices[device.Host] = make([]collector.RPCCollector, 0)
c.addCollectorIfEnabledForDevice(device, "system", f.System, system.NewCollector)
c.addCollectorIfEnabledForDevice(device, "interfaces", f.Interfaces, interfaces.NewCollector)
c.addCollectorIfEnabledForDevice(device, "wireless", f.Wireless, wireless.NewCollector)
}
func (c *collectors) addCollectorIfEnabledForDevice(device *connector.Device, key string, enabled *bool, newCollector func() collector.RPCCollector) {
if !*enabled {
return
}
col, found := c.collectors[key]
if !found {
col = newCollector()
c.collectors[key] = col
}
c.devices[device.Host] = append(c.devices[device.Host], col)
}
func (c *collectors) allEnabledCollectors() []collector.RPCCollector {
collectors := make([]collector.RPCCollector, len(c.collectors))
i := 0
for _, collector := range c.collectors {
collectors[i] = collector
i++
}
return collectors
}
func (c *collectors) collectorsForDevice(device *connector.Device) []collector.RPCCollector {
cols, found := c.devices[device.Host]
if !found {
return []collector.RPCCollector{}
}
return cols
}