Files
shelly-exporter/collector/group.go
T
lostakj 9db7aa2560
Build Docker image on push / docker (push) Successful in 22s
Initila commit
2026-08-18 00:46:59 +02:00

32 lines
862 B
Go

package collector
import (
"sync"
"github.com/prometheus/client_golang/prometheus"
)
// Group registers multiple device collectors as one Prometheus collector.
// Collecting devices concurrently prevents one slow device from delaying all others.
type Group []prometheus.Collector
// Describe forwards descriptors from every registered device collector.
func (group Group) Describe(channel chan<- *prometheus.Desc) {
for _, deviceCollector := range group {
deviceCollector.Describe(channel)
}
}
// Collect scrapes all configured devices concurrently.
func (group Group) Collect(channel chan<- prometheus.Metric) {
var waitGroup sync.WaitGroup
waitGroup.Add(len(group))
for _, deviceCollector := range group {
go func(current prometheus.Collector) {
defer waitGroup.Done()
current.Collect(channel)
}(deviceCollector)
}
waitGroup.Wait()
}