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
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue