aboutsummaryrefslogtreecommitdiff
path: root/plugin/template/metrics.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/template/metrics.go')
-rw-r--r--plugin/template/metrics.go29
1 files changed, 21 insertions, 8 deletions
diff --git a/plugin/template/metrics.go b/plugin/template/metrics.go
index f602548f4..a963b3a31 100644
--- a/plugin/template/metrics.go
+++ b/plugin/template/metrics.go
@@ -3,7 +3,10 @@ package template
import (
"sync"
+ "github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
+ "github.com/coredns/coredns/plugin/metrics"
+ "github.com/mholt/caddy"
"github.com/prometheus/client_golang/prometheus"
)
@@ -15,28 +18,38 @@ var (
Subsystem: "template",
Name: "matches_total",
Help: "Counter of template regex matches.",
- }, []string{"regex"})
+ }, []string{"zone", "class", "type"})
TemplateFailureCount = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace,
Subsystem: "template",
Name: "template_failures_total",
Help: "Counter of go template failures.",
- }, []string{"regex", "section", "template"})
+ }, []string{"zone", "class", "type", "section", "template"})
TemplateRRFailureCount = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace,
Subsystem: "template",
Name: "rr_failures_total",
Help: "Counter of mis-templated RRs.",
- }, []string{"regex", "section", "template"})
+ }, []string{"zone", "class", "type", "section", "template"})
)
// OnStartupMetrics sets up the metrics on startup.
-func OnStartupMetrics() error {
- metricsOnce.Do(func() {
- prometheus.MustRegister(TemplateMatchesCount)
- prometheus.MustRegister(TemplateFailureCount)
- prometheus.MustRegister(TemplateRRFailureCount)
+func setupMetrics(c *caddy.Controller) error {
+ c.OnStartup(func() error {
+ metricsOnce.Do(func() {
+ m := dnsserver.GetConfig(c).Handler("prometheus")
+ if m == nil {
+ return
+ }
+ if x, ok := m.(*metrics.Metrics); ok {
+ x.MustRegister(TemplateMatchesCount)
+ x.MustRegister(TemplateFailureCount)
+ x.MustRegister(TemplateRRFailureCount)
+ }
+ })
+ return nil
})
+
return nil
}