diff options
Diffstat (limited to 'plugin/cache/setup.go')
-rw-r--r-- | plugin/cache/setup.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/plugin/cache/setup.go b/plugin/cache/setup.go index d8ef9a8d7..d4d041ae8 100644 --- a/plugin/cache/setup.go +++ b/plugin/cache/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" @@ -29,6 +30,22 @@ func setup(c *caddy.Controller) error { return 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(Success).Set(float64(ca.pcap)) cacheCapacity.WithLabelValues(Denial).Set(float64(ca.ncap)) |