2018-04-01 13:58:13 +01:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/coredns/coredns/core/dnsserver"
|
|
|
|
|
|
2019-07-03 09:04:47 +08:00
|
|
|
"github.com/caddyserver/caddy"
|
2018-04-01 13:58:13 +01:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
|
)
|
|
|
|
|
|
2019-05-05 13:31:55 -04:00
|
|
|
// MustRegister registers the prometheus Collectors when the metrics plugin is used.
|
2018-04-01 13:58:13 +01:00
|
|
|
func MustRegister(c *caddy.Controller, cs ...prometheus.Collector) {
|
|
|
|
|
m := dnsserver.GetConfig(c).Handler("prometheus")
|
|
|
|
|
if m == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
x, ok := m.(*Metrics)
|
|
|
|
|
if !ok {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
for _, c := range cs {
|
|
|
|
|
x.MustRegister(c)
|
|
|
|
|
}
|
|
|
|
|
}
|