mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 02:33:14 -04:00
metrics: correctly register all metrics (#1335)
After initial startup, see if prometheus is loaded and if so, register our metrics with it. Stop doing the init() func and just use the sync.Once so we don't double registrer our metrics.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/coredns/coredns/core/dnsserver"
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/plugin/metrics"
|
||||
|
||||
"github.com/mholt/caddy"
|
||||
"github.com/miekg/dns"
|
||||
@@ -24,7 +25,18 @@ func setup(c *caddy.Controller) error {
|
||||
return plugin.Error("autopath", err)
|
||||
}
|
||||
|
||||
c.OnStartup(OnStartupMetrics)
|
||||
c.OnStartup(func() error {
|
||||
once.Do(func() {
|
||||
m := dnsserver.GetConfig(c).Handler("prometheus")
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
if x, ok := m.(*metrics.Metrics); ok {
|
||||
x.MustRegister(AutoPathCount)
|
||||
}
|
||||
})
|
||||
return nil
|
||||
})
|
||||
|
||||
// Do this in OnStartup, so all plugin has been initialized.
|
||||
c.OnStartup(func() error {
|
||||
|
||||
Reference in New Issue
Block a user