2018-05-01 23:45:06 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/coredns/coredns/core/dnsserver"
|
|
|
|
|
2020-09-09 18:09:42 +00:00
|
|
|
"github.com/caddyserver/caddy"
|
2018-05-01 23:45:06 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
2020-09-09 18:09:42 +00:00
|
|
|
// MustRegister registers the prometheus Collectors when the metrics plugin is used.
|
2018-05-01 23:45:06 +00: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)
|
|
|
|
}
|
|
|
|
}
|