plugin/metrics: add MustRegister function (#1648)

This registers the Collectors iff the metrics plugin has been loaded.
Safes a bunch of code in each and every plugin's setup code.
This commit is contained in:
Miek Gieben
2018-04-01 13:58:13 +01:00
committed by GitHub
parent 4df416ca1d
commit 2338120f5b
9 changed files with 34 additions and 72 deletions

View File

@@ -30,16 +30,7 @@ func setup(c *caddy.Controller) error {
})
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)
}
})
once.Do(func() { metrics.MustRegister(c, RequestCount, RequestDuration) })
return nil
})