diff options
Diffstat (limited to 'plugin/proxy')
-rw-r--r-- | plugin/proxy/metrics.go | 11 | ||||
-rw-r--r-- | plugin/proxy/setup.go | 15 |
2 files changed, 15 insertions, 11 deletions
diff --git a/plugin/proxy/metrics.go b/plugin/proxy/metrics.go index 96be50893..e0dd3fe98 100644 --- a/plugin/proxy/metrics.go +++ b/plugin/proxy/metrics.go @@ -25,15 +25,6 @@ var ( }, []string{"proto", "proxy_proto", "family", "to"}) ) -// OnStartupMetrics sets up the metrics on startup. This is done for all proxy protocols. -func OnStartupMetrics() error { - metricsOnce.Do(func() { - prometheus.MustRegister(RequestCount) - prometheus.MustRegister(RequestDuration) - }) - return nil -} - // familyToString returns the string form of either 1, or 2. Returns // empty string is not a known family func familyToString(f int) string { @@ -46,4 +37,4 @@ func familyToString(f int) string { return "" } -var metricsOnce sync.Once +var once sync.Once diff --git a/plugin/proxy/setup.go b/plugin/proxy/setup.go index bbe65c35d..eff7c63f4 100644 --- a/plugin/proxy/setup.go +++ b/plugin/proxy/setup.go @@ -3,6 +3,7 @@ package proxy import ( "github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/plugin" + "github.com/coredns/coredns/plugin/metrics" "github.com/mholt/caddy" ) @@ -28,7 +29,19 @@ func setup(c *caddy.Controller) error { return P }) - 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(RequestCount) + x.MustRegister(RequestDuration) + } + }) + return nil + }) for i := range upstreams { u := upstreams[i] |