mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 10:43:17 -04:00
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:
@@ -38,17 +38,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(RcodeCount)
|
||||
x.MustRegister(RequestDuration)
|
||||
x.MustRegister(HealthcheckFailureCount)
|
||||
x.MustRegister(SocketGauge)
|
||||
}
|
||||
metrics.MustRegister(c, RequestCount, RcodeCount, RequestDuration, HealthcheckFailureCount, SocketGauge)
|
||||
})
|
||||
return f.OnStartup()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user