diff options
author | 2017-12-27 15:48:14 +0000 | |
---|---|---|
committer | 2017-12-27 15:48:14 +0000 | |
commit | 90dd4bbd4570560a4b72ca8525c99dc8fc1db163 (patch) | |
tree | ab7029569d9e281a28c6ab203a556176f6586eea /plugin/dnssec/setup.go | |
parent | 5ac42ed5c29609ce710c2d9a8e145919f4124c00 (diff) | |
download | coredns-90dd4bbd4570560a4b72ca8525c99dc8fc1db163.tar.gz coredns-90dd4bbd4570560a4b72ca8525c99dc8fc1db163.tar.zst coredns-90dd4bbd4570560a4b72ca8525c99dc8fc1db163.zip |
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.
Diffstat (limited to 'plugin/dnssec/setup.go')
-rw-r--r-- | plugin/dnssec/setup.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/plugin/dnssec/setup.go b/plugin/dnssec/setup.go index 012ba5b3d..26cdbe2f1 100644 --- a/plugin/dnssec/setup.go +++ b/plugin/dnssec/setup.go @@ -7,6 +7,7 @@ import ( "github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/plugin" + "github.com/coredns/coredns/plugin/metrics" "github.com/coredns/coredns/plugin/pkg/cache" "github.com/mholt/caddy" @@ -30,6 +31,22 @@ func setup(c *caddy.Controller) error { return New(zones, keys, next, ca) }) + 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(cacheSize) + x.MustRegister(cacheCapacity) + x.MustRegister(cacheHits) + x.MustRegister(cacheMisses) + } + }) + return nil + }) + // Export the capacity for the metrics. This only happens once, because this is a re-load change only. cacheCapacity.WithLabelValues("signature").Set(float64(capacity)) |