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:
parent
5ac42ed5c2
commit
90dd4bbd45
8 changed files with 76 additions and 45 deletions
17
plugin/cache/setup.go
vendored
17
plugin/cache/setup.go
vendored
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue