summaryrefslogtreecommitdiff
path: root/plugins/metrics/plugin.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/metrics/plugin.go')
-rw-r--r--plugins/metrics/plugin.go36
1 files changed, 15 insertions, 21 deletions
diff --git a/plugins/metrics/plugin.go b/plugins/metrics/plugin.go
index fefe92bd..651a2475 100644
--- a/plugins/metrics/plugin.go
+++ b/plugins/metrics/plugin.go
@@ -23,11 +23,6 @@ const (
maxHeaderSize = 1024 * 1024 * 100 // 104MB
)
-type statsProvider struct {
- collectors []prometheus.Collector
- name string
-}
-
// Plugin to manage application metrics using Prometheus.
type Plugin struct {
cfg *Config
@@ -74,16 +69,14 @@ func (m *Plugin) Init(cfg config.Configurer, log logger.Logger) error {
// Register invocation will be later in the Serve method
for k, v := range collectors {
- m.collectors.Store(k, statsProvider{
- collectors: []prometheus.Collector{v},
- name: k,
- })
+ m.collectors.Store(k, v)
}
return nil
}
// Register new prometheus collector.
-func (m *Plugin) Register(c prometheus.Collector) error {
+func (m *Plugin) Register(c
+) error {
return m.registry.Register(c)
}
@@ -92,13 +85,11 @@ func (m *Plugin) Serve() chan error {
errCh := make(chan error, 1)
m.collectors.Range(func(key, value interface{}) bool {
// key - name
- // value - statsProvider struct
- c := value.(statsProvider)
- for _, v := range c.collectors {
- if err := m.registry.Register(v); err != nil {
- errCh <- err
- return false
- }
+ // value - prometheus.Collector
+ c := value.(prometheus.Collector)
+ if err := m.registry.Register(c); err != nil {
+ errCh <- err
+ return false
}
return true
@@ -211,10 +202,13 @@ func (m *Plugin) Collects() []interface{} {
// Collector returns application specific collector by name or nil if collector not found.
func (m *Plugin) AddStatProvider(name endure.Named, stat StatProvider) error {
- m.collectors.Store(name.Name(), statsProvider{
- collectors: stat.MetricsCollector(),
- name: name.Name(),
- })
+ for _, c := range stat.MetricsCollector() {
+ err := m.registry.Register(c)
+ if err != nil {
+ return err
+ }
+ }
+
return nil
}