coredns/plugin/template/metrics.go
Rene Treffer 0091e1c9dc Align plugin/template usage and syntax with other plugins (#1360)
* Align plugin/template usage and syntax with other plugins

* Use new fallthrough logic in plugin/template

* Use zone name normalization for plugin/template

* Test fallthrough parsing in plugin/template

* Rework scoping of match checks

Most matches are not plugin global but per template. The plugin does only a
very rough check while detailed checks are done per-template.

Per template checks include:
- Zones
- Class/Type
- Regex
- Fallthrough

* Remove trailing `.` from fully qualified domain names

* Register template metrics with zone/class/type instead of regex

* Remove trailing fqdn dot from multiple testcases
2018-01-09 21:30:58 +00:00

56 lines
1.5 KiB
Go

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"
)
// Metrics for template.
var (
TemplateMatchesCount = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace,
Subsystem: "template",
Name: "matches_total",
Help: "Counter of template regex matches.",
}, []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{"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{"zone", "class", "type", "section", "template"})
)
// OnStartupMetrics sets up the metrics on startup.
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
}
var metricsOnce sync.Once