42 lines
957 B
Go
42 lines
957 B
Go
package registry
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.faercol.me/monitoring/sys-exporter/collector"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
var R CollectorRegistry
|
|
|
|
type CollectorRegistry struct {
|
|
promRegistry *prometheus.Registry
|
|
collectors map[string]collector.Collector
|
|
}
|
|
|
|
func (r *CollectorRegistry) RegisterCollector(name string, c collector.Collector) error {
|
|
r.collectors[name] = c
|
|
return r.promRegistry.Register(c.PromCollector())
|
|
}
|
|
|
|
func (r *CollectorRegistry) MustRegisterCollector(name string, c collector.Collector) {
|
|
r.collectors[name] = c
|
|
r.promRegistry.MustRegister(c.PromCollector())
|
|
}
|
|
|
|
func (r *CollectorRegistry) PromRegistry() *prometheus.Registry {
|
|
return r.promRegistry
|
|
}
|
|
|
|
func (r *CollectorRegistry) Run(ctx context.Context) {
|
|
for _, c := range r.collectors {
|
|
go c.Run(ctx)
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
R = CollectorRegistry{
|
|
promRegistry: prometheus.NewRegistry(),
|
|
collectors: make(map[string]collector.Collector),
|
|
}
|
|
}
|