-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcumulus_collector.go
51 lines (38 loc) · 1.05 KB
/
cumulus_collector.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
package main
import (
"sync"
"gitlab.com/wobcom/cumulus-exporter/collector"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)
type cumulusCollector struct{}
func newCumulusCollector() *cumulusCollector {
return &cumulusCollector{}
}
func (*cumulusCollector) Describe(ch chan<- *prometheus.Desc) {
for _, collector := range enabledCollectors {
collector.Describe(ch)
}
}
func (*cumulusCollector) Collect(ch chan<- prometheus.Metric) {
waitGroup := &sync.WaitGroup{}
waitGroup.Add(len(enabledCollectors))
for _, collector := range enabledCollectors {
go runCollector(collector, waitGroup, ch)
}
waitGroup.Wait()
}
func runCollector(collector collector.Collector, waitGroup *sync.WaitGroup, ch chan<- prometheus.Metric) {
defer waitGroup.Done()
errorChan := make(chan error)
doneChan := make(chan struct{})
go collector.Collect(ch, errorChan, doneChan)
for {
select {
case err := <-errorChan:
log.Errorf("Error running collector %s: %v", collector.Name(), err)
case <-doneChan:
return
}
}
}