using promauto package to ensure all created metrics are properly registered (#4025)

Signed-off-by: zounengren <zounengren@cmss.chinamobile.com>
This commit is contained in:
Zou Nengren 2020-07-25 23:06:28 +08:00 committed by GitHub
parent 05751bdb59
commit 4166dcc2fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 71 additions and 163 deletions

View file

@ -28,6 +28,7 @@ env:
- TEST_TYPE=core - TEST_TYPE=core
- TEST_TYPE=plugin - TEST_TYPE=plugin
- TEST_TYPE=fmt - TEST_TYPE=fmt
- TEST_TYPE=metrics
# - TEST_TYPE=fuzzit FUZZIT_TYPE=local-regression # - TEST_TYPE=fuzzit FUZZIT_TYPE=local-regression
# - TEST_TYPE=fuzzit FUZZIT_TYPE=fuzzing # - TEST_TYPE=fuzzit FUZZIT_TYPE=fuzzing

View file

@ -31,6 +31,12 @@ endif
ifeq ($(TEST_TYPE),fmt) ifeq ($(TEST_TYPE),fmt)
( echo "fmt"; gofmt -w -s . | grep ".*\.go"; if [ "$$?" = "0" ]; then exit 1; fi ) ( echo "fmt"; gofmt -w -s . | grep ".*\.go"; if [ "$$?" = "0" ]; then exit 1; fi )
endif endif
ifeq ($(TEST_TYPE),metrics)
( echo "metrics"; go get github.com/fatih/faillint)
( faillint -paths "github.com/prometheus/client_golang/prometheus.{NewCounter,NewCounterVec,NewCounterVec,\
NewGauge,NewGaugeVec,NewGaugeFunc,NewHistorgram,NewHistogramVec,NewSummary,NewSummaryVec}=github.com/prometheus/client_golang/prometheus/promauto.{NewCounter,\
NewCounterVec,NewCounterVec,NewGauge,NewGaugeVec,NewGaugeFunc,NewHistorgram,NewHistogramVec,NewSummary,NewSummaryVec}" ./...)
endif
ifeq ($(TEST_TYPE),plugin) ifeq ($(TEST_TYPE),plugin)
( cd plugin; go test -race ./... ) ( cd plugin; go test -race ./... )
endif endif

3
go.mod
View file

@ -14,6 +14,7 @@ require (
github.com/cenkalti/backoff/v4 v4.0.2 github.com/cenkalti/backoff/v4 v4.0.2
github.com/dnstap/golang-dnstap v0.2.0 github.com/dnstap/golang-dnstap v0.2.0
github.com/farsightsec/golang-framestream v0.0.0-20190425193708-fa4b164d59b8 github.com/farsightsec/golang-framestream v0.0.0-20190425193708-fa4b164d59b8
github.com/fatih/faillint v1.5.0 // indirect
github.com/golang/protobuf v1.4.2 github.com/golang/protobuf v1.4.2
github.com/gophercloud/gophercloud v0.9.0 // indirect github.com/gophercloud/gophercloud v0.9.0 // indirect
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645
@ -30,7 +31,7 @@ require (
github.com/prometheus/client_golang v1.7.1 github.com/prometheus/client_golang v1.7.1
github.com/prometheus/client_model v0.2.0 github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.10.0 github.com/prometheus/common v0.10.0
github.com/prometheus/prometheus v2.5.0+incompatible github.com/prometheus/prometheus v2.5.0+incompatible // indirect
go.etcd.io/etcd v0.5.0-alpha.5.0.20200306183522-221f0cc107cb go.etcd.io/etcd v0.5.0-alpha.5.0.20200306183522-221f0cc107cb
go.uber.org/zap v1.14.1 // indirect go.uber.org/zap v1.14.1 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9

5
go.sum
View file

@ -22,6 +22,8 @@ cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiy
cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos=
cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk=
contrib.go.opencensus.io/exporter/ocagent v0.4.12/go.mod h1:450APlNTSR6FrvC3CTRqYosuDstRB9un7SOx2k/9ckA= contrib.go.opencensus.io/exporter/ocagent v0.4.12/go.mod h1:450APlNTSR6FrvC3CTRqYosuDstRB9un7SOx2k/9ckA=
dmitri.shuralyov.com/go/generated v0.0.0-20170818220700-b1254a446363 h1:o4lAkfETerCnr1kF9/qwkwjICnU+YLHNDCM8h2xj7as=
dmitri.shuralyov.com/go/generated v0.0.0-20170818220700-b1254a446363/go.mod h1:WG7q7swWsS2f9PYpt5DoEP/EBYWx8We5UoRltn9vJl8=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/Azure/azure-sdk-for-go v32.4.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/azure-sdk-for-go v32.4.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/azure-sdk-for-go v40.6.0+incompatible h1:ULjp/a/UsBfnZcl45jjywhcBKex/k/A1cG9s9NapLFw= github.com/Azure/azure-sdk-for-go v40.6.0+incompatible h1:ULjp/a/UsBfnZcl45jjywhcBKex/k/A1cG9s9NapLFw=
@ -158,6 +160,8 @@ github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSY
github.com/farsightsec/golang-framestream v0.0.0-20190425193708-fa4b164d59b8 h1:/iPdQppoAsTfML+yqFSq2EBChiEMnRkh5WvhFgtWwcU= github.com/farsightsec/golang-framestream v0.0.0-20190425193708-fa4b164d59b8 h1:/iPdQppoAsTfML+yqFSq2EBChiEMnRkh5WvhFgtWwcU=
github.com/farsightsec/golang-framestream v0.0.0-20190425193708-fa4b164d59b8/go.mod h1:eNde4IQyEiA5br02AouhEHCu3p3UzrCdFR4LuQHklMI= github.com/farsightsec/golang-framestream v0.0.0-20190425193708-fa4b164d59b8/go.mod h1:eNde4IQyEiA5br02AouhEHCu3p3UzrCdFR4LuQHklMI=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/faillint v1.5.0 h1:fUolG+EsD6zdRW4rapzrM0tSf7VdpxWG3GLCPafUOcE=
github.com/fatih/faillint v1.5.0/go.mod h1:e+3n7K3aI9fnZS4aNCggnoB+uBF4hwjqqR7BmA35PCE=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
@ -667,6 +671,7 @@ golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapK
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200207224406-61798d64f025/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4 h1:kDtqNkeBrZb8B+atrj50B5XLHpzXXqcCdZPP/ApQ5NY= golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4 h1:kDtqNkeBrZb8B+atrj50B5XLHpzXXqcCdZPP/ApQ5NY=

View file

@ -4,18 +4,19 @@ import (
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
) )
var ( var (
// RequestBlockCount is the number of DNS requests being blocked. // RequestBlockCount is the number of DNS requests being blocked.
RequestBlockCount = prometheus.NewCounterVec(prometheus.CounterOpts{ RequestBlockCount = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: pluginName, Subsystem: pluginName,
Name: "blocked_requests_total", Name: "blocked_requests_total",
Help: "Counter of DNS requests being blocked.", Help: "Counter of DNS requests being blocked.",
}, []string{"server", "zone"}) }, []string{"server", "zone"})
// RequestAllowCount is the number of DNS requests being Allowed. // RequestAllowCount is the number of DNS requests being Allowed.
RequestAllowCount = prometheus.NewCounterVec(prometheus.CounterOpts{ RequestAllowCount = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: pluginName, Subsystem: pluginName,
Name: "allowed_requests_total", Name: "allowed_requests_total",

View file

@ -6,7 +6,6 @@ import (
"github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
"github.com/caddyserver/caddy" "github.com/caddyserver/caddy"
"github.com/infobloxopen/go-trees/iptree" "github.com/infobloxopen/go-trees/iptree"
@ -37,11 +36,6 @@ func setup(c *caddy.Controller) error {
return a return a
}) })
// Register all metrics.
c.OnStartup(func() error {
metrics.MustRegister(c, RequestBlockCount, RequestAllowCount)
return nil
})
return nil return nil
} }

View file

@ -4,11 +4,12 @@ import (
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
) )
var ( var (
// autoPathCount is counter of successfully autopath-ed queries. // autoPathCount is counter of successfully autopath-ed queries.
autoPathCount = prometheus.NewCounterVec(prometheus.CounterOpts{ autoPathCount = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "autopath", Subsystem: "autopath",
Name: "success_total", Name: "success_total",

View file

@ -5,7 +5,6 @@ import (
"github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
"github.com/caddyserver/caddy" "github.com/caddyserver/caddy"
"github.com/miekg/dns" "github.com/miekg/dns"
@ -19,11 +18,6 @@ func setup(c *caddy.Controller) error {
return plugin.Error("autopath", err) return plugin.Error("autopath", err)
} }
c.OnStartup(func() error {
metrics.MustRegister(c, autoPathCount)
return nil
})
// Do this in OnStartup, so all plugin has been initialized. // Do this in OnStartup, so all plugin has been initialized.
c.OnStartup(func() error { c.OnStartup(func() error {
m := dnsserver.GetConfig(c).Handler(mw) m := dnsserver.GetConfig(c).Handler(mw)

View file

@ -4,46 +4,47 @@ import (
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
) )
var ( var (
// cacheSize is total elements in the cache by cache type. // cacheSize is total elements in the cache by cache type.
cacheSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{ cacheSize = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "cache", Subsystem: "cache",
Name: "entries", Name: "entries",
Help: "The number of elements in the cache.", Help: "The number of elements in the cache.",
}, []string{"server", "type"}) }, []string{"server", "type"})
// cacheHits is counter of cache hits by cache type. // cacheHits is counter of cache hits by cache type.
cacheHits = prometheus.NewCounterVec(prometheus.CounterOpts{ cacheHits = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "cache", Subsystem: "cache",
Name: "hits_total", Name: "hits_total",
Help: "The count of cache hits.", Help: "The count of cache hits.",
}, []string{"server", "type"}) }, []string{"server", "type"})
// cacheMisses is the counter of cache misses. // cacheMisses is the counter of cache misses.
cacheMisses = prometheus.NewCounterVec(prometheus.CounterOpts{ cacheMisses = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "cache", Subsystem: "cache",
Name: "misses_total", Name: "misses_total",
Help: "The count of cache misses.", Help: "The count of cache misses.",
}, []string{"server"}) }, []string{"server"})
// cachePrefetches is the number of time the cache has prefetched a cached item. // cachePrefetches is the number of time the cache has prefetched a cached item.
cachePrefetches = prometheus.NewCounterVec(prometheus.CounterOpts{ cachePrefetches = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "cache", Subsystem: "cache",
Name: "prefetch_total", Name: "prefetch_total",
Help: "The number of times the cache has prefetched a cached item.", Help: "The number of times the cache has prefetched a cached item.",
}, []string{"server"}) }, []string{"server"})
// cacheDrops is the number responses that are not cached, because the reply is malformed. // cacheDrops is the number responses that are not cached, because the reply is malformed.
cacheDrops = prometheus.NewCounterVec(prometheus.CounterOpts{ cacheDrops = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "cache", Subsystem: "cache",
Name: "drops_total", Name: "drops_total",
Help: "The number responses that are not cached, because the reply is malformed.", Help: "The number responses that are not cached, because the reply is malformed.",
}, []string{"server"}) }, []string{"server"})
// servedStale is the number of requests served from stale cache entries. // servedStale is the number of requests served from stale cache entries.
servedStale = prometheus.NewCounterVec(prometheus.CounterOpts{ servedStale = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "cache", Subsystem: "cache",
Name: "served_stale_total", Name: "served_stale_total",

View file

@ -8,7 +8,6 @@ import (
"github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
"github.com/coredns/coredns/plugin/pkg/cache" "github.com/coredns/coredns/plugin/pkg/cache"
clog "github.com/coredns/coredns/plugin/pkg/log" clog "github.com/coredns/coredns/plugin/pkg/log"
@ -29,13 +28,6 @@ func setup(c *caddy.Controller) error {
return ca return ca
}) })
c.OnStartup(func() error {
metrics.MustRegister(c,
cacheSize, cacheHits, cacheMisses,
cachePrefetches, cacheDrops, servedStale)
return nil
})
return nil return nil
} }

View file

@ -4,11 +4,12 @@ import (
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
) )
var ( var (
// RequestsTranslatedCount is the number of DNS requests translated by dns64. // RequestsTranslatedCount is the number of DNS requests translated by dns64.
RequestsTranslatedCount = prometheus.NewCounterVec(prometheus.CounterOpts{ RequestsTranslatedCount = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: pluginName, Subsystem: pluginName,
Name: "requests_translated_total", Name: "requests_translated_total",

View file

@ -5,7 +5,6 @@ import (
"github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
clog "github.com/coredns/coredns/plugin/pkg/log" clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/upstream" "github.com/coredns/coredns/plugin/pkg/upstream"
@ -29,12 +28,6 @@ func setup(c *caddy.Controller) error {
return dns64 return dns64
}) })
// Register all metrics.
c.OnStartup(func() error {
metrics.MustRegister(c, RequestsTranslatedCount)
return nil
})
return nil return nil
} }

View file

@ -4,25 +4,26 @@ import (
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
) )
var ( var (
// cacheSize is the number of elements in the dnssec cache. // cacheSize is the number of elements in the dnssec cache.
cacheSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{ cacheSize = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "dnssec", Subsystem: "dnssec",
Name: "cache_entries", Name: "cache_entries",
Help: "The number of elements in the dnssec cache.", Help: "The number of elements in the dnssec cache.",
}, []string{"server", "type"}) }, []string{"server", "type"})
// cacheHits is the count of cache hits. // cacheHits is the count of cache hits.
cacheHits = prometheus.NewCounterVec(prometheus.CounterOpts{ cacheHits = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "dnssec", Subsystem: "dnssec",
Name: "cache_hits_total", Name: "cache_hits_total",
Help: "The count of cache hits.", Help: "The count of cache hits.",
}, []string{"server"}) }, []string{"server"})
// cacheMisses is the count of cache misses. // cacheMisses is the count of cache misses.
cacheMisses = prometheus.NewCounterVec(prometheus.CounterOpts{ cacheMisses = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "dnssec", Subsystem: "dnssec",
Name: "cache_misses_total", Name: "cache_misses_total",

View file

@ -8,7 +8,6 @@ import (
"github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
"github.com/coredns/coredns/plugin/pkg/cache" "github.com/coredns/coredns/plugin/pkg/cache"
clog "github.com/coredns/coredns/plugin/pkg/log" clog "github.com/coredns/coredns/plugin/pkg/log"
@ -30,11 +29,6 @@ func setup(c *caddy.Controller) error {
return New(zones, keys, splitkeys, next, ca) return New(zones, keys, splitkeys, next, ca)
}) })
c.OnStartup(func() error {
metrics.MustRegister(c, cacheSize, cacheHits, cacheMisses)
return nil
})
return nil return nil
} }

View file

@ -4,48 +4,49 @@ import (
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
) )
// Variables declared for monitoring. // Variables declared for monitoring.
var ( var (
RequestCount = prometheus.NewCounterVec(prometheus.CounterOpts{ RequestCount = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "forward", Subsystem: "forward",
Name: "requests_total", Name: "requests_total",
Help: "Counter of requests made per upstream.", Help: "Counter of requests made per upstream.",
}, []string{"to"}) }, []string{"to"})
RcodeCount = prometheus.NewCounterVec(prometheus.CounterOpts{ RcodeCount = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "forward", Subsystem: "forward",
Name: "responses_total", Name: "responses_total",
Help: "Counter of responses received per upstream.", Help: "Counter of responses received per upstream.",
}, []string{"rcode", "to"}) }, []string{"rcode", "to"})
RequestDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{ RequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "forward", Subsystem: "forward",
Name: "request_duration_seconds", Name: "request_duration_seconds",
Buckets: plugin.TimeBuckets, Buckets: plugin.TimeBuckets,
Help: "Histogram of the time each request took.", Help: "Histogram of the time each request took.",
}, []string{"to"}) }, []string{"to"})
HealthcheckFailureCount = prometheus.NewCounterVec(prometheus.CounterOpts{ HealthcheckFailureCount = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "forward", Subsystem: "forward",
Name: "healthcheck_failures_total", Name: "healthcheck_failures_total",
Help: "Counter of the number of failed healthchecks.", Help: "Counter of the number of failed healthchecks.",
}, []string{"to"}) }, []string{"to"})
HealthcheckBrokenCount = prometheus.NewCounter(prometheus.CounterOpts{ HealthcheckBrokenCount = promauto.NewCounter(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "forward", Subsystem: "forward",
Name: "healthcheck_broken_total", Name: "healthcheck_broken_total",
Help: "Counter of the number of complete failures of the healthchecks.", Help: "Counter of the number of complete failures of the healthchecks.",
}) })
SocketGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{ SocketGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "forward", Subsystem: "forward",
Name: "sockets_open", Name: "sockets_open",
Help: "Gauge of open sockets per upstream.", Help: "Gauge of open sockets per upstream.",
}, []string{"to"}) }, []string{"to"})
MaxConcurrentRejectCount = prometheus.NewCounter(prometheus.CounterOpts{ MaxConcurrentRejectCount = promauto.NewCounter(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "forward", Subsystem: "forward",
Name: "max_concurrent_rejects_total", Name: "max_concurrent_rejects_total",

View file

@ -8,7 +8,6 @@ import (
"github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
"github.com/coredns/coredns/plugin/pkg/parse" "github.com/coredns/coredns/plugin/pkg/parse"
pkgtls "github.com/coredns/coredns/plugin/pkg/tls" pkgtls "github.com/coredns/coredns/plugin/pkg/tls"
"github.com/coredns/coredns/plugin/pkg/transport" "github.com/coredns/coredns/plugin/pkg/transport"
@ -33,7 +32,6 @@ func setup(c *caddy.Controller) error {
}) })
c.OnStartup(func() error { c.OnStartup(func() error {
metrics.MustRegister(c, RequestCount, RcodeCount, RequestDuration, HealthcheckFailureCount, HealthcheckBrokenCount, SocketGauge, MaxConcurrentRejectCount)
return f.OnStartup() return f.OnStartup()
}) })

View file

@ -4,23 +4,24 @@ import (
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
) )
// Variables declared for monitoring. // Variables declared for monitoring.
var ( var (
RequestCount = prometheus.NewCounterVec(prometheus.CounterOpts{ RequestCount = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "grpc", Subsystem: "grpc",
Name: "requests_total", Name: "requests_total",
Help: "Counter of requests made per upstream.", Help: "Counter of requests made per upstream.",
}, []string{"to"}) }, []string{"to"})
RcodeCount = prometheus.NewCounterVec(prometheus.CounterOpts{ RcodeCount = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "grpc", Subsystem: "grpc",
Name: "responses_total", Name: "responses_total",
Help: "Counter of requests made per upstream.", Help: "Counter of requests made per upstream.",
}, []string{"rcode", "to"}) }, []string{"rcode", "to"})
RequestDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{ RequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "grpc", Subsystem: "grpc",
Name: "request_duration_seconds", Name: "request_duration_seconds",

View file

@ -6,7 +6,6 @@ import (
"github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
"github.com/coredns/coredns/plugin/pkg/parse" "github.com/coredns/coredns/plugin/pkg/parse"
pkgtls "github.com/coredns/coredns/plugin/pkg/tls" pkgtls "github.com/coredns/coredns/plugin/pkg/tls"
@ -30,11 +29,6 @@ func setup(c *caddy.Controller) error {
return g return g
}) })
c.OnStartup(func() error {
metrics.MustRegister(c, RequestCount, RcodeCount, RequestDuration)
return nil
})
return nil return nil
} }

View file

@ -7,6 +7,7 @@ import (
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
) )
// overloaded queries the health end point and updates a metrics showing how long it took. // overloaded queries the health end point and updates a metrics showing how long it took.
@ -39,7 +40,7 @@ func (h *health) overloaded() {
var ( var (
// HealthDuration is the metric used for exporting how fast we can retrieve the /health endpoint. // HealthDuration is the metric used for exporting how fast we can retrieve the /health endpoint.
HealthDuration = prometheus.NewHistogram(prometheus.HistogramOpts{ HealthDuration = promauto.NewHistogram(prometheus.HistogramOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "health", Subsystem: "health",
Name: "request_duration_seconds", Name: "request_duration_seconds",

View file

@ -6,7 +6,6 @@ import (
"time" "time"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
"github.com/caddyserver/caddy" "github.com/caddyserver/caddy"
) )
@ -21,11 +20,6 @@ func setup(c *caddy.Controller) error {
h := &health{Addr: addr, stop: make(chan bool), lameduck: lame} h := &health{Addr: addr, stop: make(chan bool), lameduck: lame}
c.OnStartup(func() error {
metrics.MustRegister(c, HealthDuration)
return nil
})
c.OnStartup(h.OnStartup) c.OnStartup(h.OnStartup)
c.OnRestart(h.OnFinalShutdown) c.OnRestart(h.OnFinalShutdown)
c.OnFinalShutdown(h.OnFinalShutdown) c.OnFinalShutdown(h.OnFinalShutdown)

View file

@ -4,18 +4,19 @@ import (
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
) )
var ( var (
// hostsEntries is the combined number of entries in hosts and Corefile. // hostsEntries is the combined number of entries in hosts and Corefile.
hostsEntries = prometheus.NewGaugeVec(prometheus.GaugeOpts{ hostsEntries = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "hosts", Subsystem: "hosts",
Name: "entries", Name: "entries",
Help: "The combined number of entries in hosts and Corefile.", Help: "The combined number of entries in hosts and Corefile.",
}, []string{}) }, []string{})
// hostsReloadTime is the timestamp of the last reload of hosts file. // hostsReloadTime is the timestamp of the last reload of hosts file.
hostsReloadTime = prometheus.NewGauge(prometheus.GaugeOpts{ hostsReloadTime = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "hosts", Subsystem: "hosts",
Name: "reload_timestamp_seconds", Name: "reload_timestamp_seconds",

View file

@ -9,7 +9,6 @@ import (
"github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
clog "github.com/coredns/coredns/plugin/pkg/log" clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/caddyserver/caddy" "github.com/caddyserver/caddy"
@ -53,12 +52,6 @@ func setup(c *caddy.Controller) error {
return nil return nil
}) })
c.OnStartup(func() error {
metrics.MustRegister(c, hostsEntries)
metrics.MustRegister(c, hostsReloadTime)
return nil
})
c.OnShutdown(func() error { c.OnShutdown(func() error {
close(parseChan) close(parseChan)
return nil return nil

View file

@ -5,7 +5,9 @@ import (
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/kubernetes/object" "github.com/coredns/coredns/plugin/kubernetes/object"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
api "k8s.io/api/core/v1" api "k8s.io/api/core/v1"
) )
@ -21,7 +23,7 @@ var (
// * cluster_ip // * cluster_ip
// * headless_with_selector // * headless_with_selector
// * headless_without_selector // * headless_without_selector
DnsProgrammingLatency = prometheus.NewHistogramVec(prometheus.HistogramOpts{ DnsProgrammingLatency = promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: pluginName, Subsystem: pluginName,
Name: "dns_programming_duration_seconds", Name: "dns_programming_duration_seconds",

View file

@ -11,7 +11,6 @@ import (
"github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
"github.com/coredns/coredns/plugin/pkg/dnsutil" "github.com/coredns/coredns/plugin/pkg/dnsutil"
clog "github.com/coredns/coredns/plugin/pkg/log" clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/parse" "github.com/coredns/coredns/plugin/pkg/parse"
@ -48,11 +47,6 @@ func setup(c *caddy.Controller) error {
k.RegisterKubeCache(c) k.RegisterKubeCache(c)
c.OnStartup(func() error {
metrics.MustRegister(c, DnsProgrammingLatency)
return nil
})
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler { dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
k.Next = next k.Next = next
return k return k

View file

@ -9,10 +9,10 @@ import (
"time" "time"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics/vars"
"github.com/coredns/coredns/plugin/pkg/reuseport" "github.com/coredns/coredns/plugin/pkg/reuseport"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
) )
@ -37,23 +37,9 @@ type Metrics struct {
func New(addr string) *Metrics { func New(addr string) *Metrics {
met := &Metrics{ met := &Metrics{
Addr: addr, Addr: addr,
Reg: prometheus.NewRegistry(), Reg: prometheus.DefaultRegisterer.(*prometheus.Registry),
zoneMap: make(map[string]struct{}), zoneMap: make(map[string]struct{}),
} }
// Add the default collectors
met.MustRegister(prometheus.NewGoCollector())
met.MustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}))
// Add all of our collectors
met.MustRegister(buildInfo)
met.MustRegister(vars.Panic)
met.MustRegister(vars.RequestCount)
met.MustRegister(vars.RequestDuration)
met.MustRegister(vars.RequestSize)
met.MustRegister(vars.RequestDo)
met.MustRegister(vars.ResponseSize)
met.MustRegister(vars.ResponseRcode)
met.MustRegister(vars.PluginEnabled)
return met return met
} }
@ -162,7 +148,7 @@ var ListenAddr string
// before erroring when it tries to close the metrics server // before erroring when it tries to close the metrics server
const shutdownTimeout time.Duration = time.Second * 5 const shutdownTimeout time.Duration = time.Second * 5
var buildInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{ var buildInfo = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Name: "build_info", Name: "build_info",
Help: "A metric with a constant '1' value labeled by version, revision, and goversion from which CoreDNS was built.", Help: "A metric with a constant '1' value labeled by version, revision, and goversion from which CoreDNS was built.",

View file

@ -1,23 +0,0 @@
package metrics
import (
"github.com/coredns/coredns/core/dnsserver"
"github.com/caddyserver/caddy"
"github.com/prometheus/client_golang/prometheus"
)
// MustRegister registers the prometheus Collectors when the metrics plugin is used.
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)
}
}

View file

@ -4,18 +4,19 @@ import (
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
) )
// Request* and Response* are the prometheus counters and gauges we are using for exporting metrics. // Request* and Response* are the prometheus counters and gauges we are using for exporting metrics.
var ( var (
RequestCount = prometheus.NewCounterVec(prometheus.CounterOpts{ RequestCount = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: subsystem, Subsystem: subsystem,
Name: "requests_total", Name: "requests_total",
Help: "Counter of DNS requests made per zone, protocol and family.", Help: "Counter of DNS requests made per zone, protocol and family.",
}, []string{"server", "zone", "proto", "family", "type"}) }, []string{"server", "zone", "proto", "family", "type"})
RequestDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{ RequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: subsystem, Subsystem: subsystem,
Name: "request_duration_seconds", Name: "request_duration_seconds",
@ -23,7 +24,7 @@ var (
Help: "Histogram of the time (in seconds) each request took.", Help: "Histogram of the time (in seconds) each request took.",
}, []string{"server", "zone", "type"}) }, []string{"server", "zone", "type"})
RequestSize = prometheus.NewHistogramVec(prometheus.HistogramOpts{ RequestSize = promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: subsystem, Subsystem: subsystem,
Name: "request_size_bytes", Name: "request_size_bytes",
@ -31,14 +32,14 @@ var (
Buckets: []float64{0, 100, 200, 300, 400, 511, 1023, 2047, 4095, 8291, 16e3, 32e3, 48e3, 64e3}, Buckets: []float64{0, 100, 200, 300, 400, 511, 1023, 2047, 4095, 8291, 16e3, 32e3, 48e3, 64e3},
}, []string{"server", "zone", "proto"}) }, []string{"server", "zone", "proto"})
RequestDo = prometheus.NewCounterVec(prometheus.CounterOpts{ RequestDo = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: subsystem, Subsystem: subsystem,
Name: "do_requests_total", Name: "do_requests_total",
Help: "Counter of DNS requests with DO bit set per zone.", Help: "Counter of DNS requests with DO bit set per zone.",
}, []string{"server", "zone"}) }, []string{"server", "zone"})
ResponseSize = prometheus.NewHistogramVec(prometheus.HistogramOpts{ ResponseSize = promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: subsystem, Subsystem: subsystem,
Name: "response_size_bytes", Name: "response_size_bytes",
@ -46,20 +47,20 @@ var (
Buckets: []float64{0, 100, 200, 300, 400, 511, 1023, 2047, 4095, 8291, 16e3, 32e3, 48e3, 64e3}, Buckets: []float64{0, 100, 200, 300, 400, 511, 1023, 2047, 4095, 8291, 16e3, 32e3, 48e3, 64e3},
}, []string{"server", "zone", "proto"}) }, []string{"server", "zone", "proto"})
ResponseRcode = prometheus.NewCounterVec(prometheus.CounterOpts{ ResponseRcode = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: subsystem, Subsystem: subsystem,
Name: "responses_total", Name: "responses_total",
Help: "Counter of response status codes.", Help: "Counter of response status codes.",
}, []string{"server", "zone", "rcode"}) }, []string{"server", "zone", "rcode"})
Panic = prometheus.NewCounter(prometheus.CounterOpts{ Panic = promauto.NewCounter(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Name: "panics_total", Name: "panics_total",
Help: "A metrics that counts the number of panics.", Help: "A metrics that counts the number of panics.",
}) })
PluginEnabled = prometheus.NewGaugeVec(prometheus.GaugeOpts{ PluginEnabled = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Name: "plugin_enabled", Name: "plugin_enabled",
Help: "A metric that indicates whether a plugin is enabled on per server and zone basis.", Help: "A metric that indicates whether a plugin is enabled on per server and zone basis.",

View file

@ -4,19 +4,20 @@ import (
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
) )
// Metrics for the reload plugin // Metrics for the reload plugin
var ( var (
// failedCount is the counter of the number of failed reload attempts. // failedCount is the counter of the number of failed reload attempts.
failedCount = prometheus.NewCounter(prometheus.CounterOpts{ failedCount = promauto.NewCounter(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "reload", Subsystem: "reload",
Name: "failed_total", Name: "failed_total",
Help: "Counter of the number of failed reload attempts.", Help: "Counter of the number of failed reload attempts.",
}) })
// reloadInfo is record the hash value during reload. // reloadInfo is record the hash value during reload.
reloadInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{ reloadInfo = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "reload", Subsystem: "reload",
Name: "version_info", Name: "version_info",

View file

@ -7,7 +7,6 @@ import (
"time" "time"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
clog "github.com/coredns/coredns/plugin/pkg/log" clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/caddyserver/caddy" "github.com/caddyserver/caddy"
@ -70,10 +69,6 @@ func setup(c *caddy.Controller) error {
r.setUsage(used) r.setUsage(used)
once.Do(func() { once.Do(func() {
caddy.RegisterEventHook("reload", hook) caddy.RegisterEventHook("reload", hook)
c.OnRestart(func() error {
metrics.MustRegister(c, reloadInfo, failedCount)
return nil
})
}) })
// re-register on finalShutDown as the instance most-likely will be changed // re-register on finalShutDown as the instance most-likely will be changed
shutOnce.Do(func() { shutOnce.Do(func() {

View file

@ -2,42 +2,30 @@ package template
import ( import (
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
"github.com/caddyserver/caddy"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
) )
var ( var (
// templateMatchesCount is the counter of template regex matches. // templateMatchesCount is the counter of template regex matches.
templateMatchesCount = prometheus.NewCounterVec(prometheus.CounterOpts{ templateMatchesCount = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "template", Subsystem: "template",
Name: "matches_total", Name: "matches_total",
Help: "Counter of template regex matches.", Help: "Counter of template regex matches.",
}, []string{"server", "zone", "class", "type"}) }, []string{"server", "zone", "class", "type"})
// templateFailureCount is the counter of go template failures. // templateFailureCount is the counter of go template failures.
templateFailureCount = prometheus.NewCounterVec(prometheus.CounterOpts{ templateFailureCount = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "template", Subsystem: "template",
Name: "template_failures_total", Name: "template_failures_total",
Help: "Counter of go template failures.", Help: "Counter of go template failures.",
}, []string{"server", "zone", "class", "type", "section", "template"}) }, []string{"server", "zone", "class", "type", "section", "template"})
// templateRRFailureCount is the counter of mis-templated RRs. // templateRRFailureCount is the counter of mis-templated RRs.
templateRRFailureCount = prometheus.NewCounterVec(prometheus.CounterOpts{ templateRRFailureCount = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "template", Subsystem: "template",
Name: "rr_failures_total", Name: "rr_failures_total",
Help: "Counter of mis-templated RRs.", Help: "Counter of mis-templated RRs.",
}, []string{"server", "zone", "class", "type", "section", "template"}) }, []string{"server", "zone", "class", "type", "section", "template"})
) )
// OnStartupMetrics sets up the metrics on startup.
func setupMetrics(c *caddy.Controller) error {
c.OnStartup(func() error {
metrics.MustRegister(c, templateMatchesCount, templateFailureCount, templateRRFailureCount)
return nil
})
return nil
}

View file

@ -20,10 +20,6 @@ func setupTemplate(c *caddy.Controller) error {
return plugin.Error("template", err) return plugin.Error("template", err)
} }
if err := setupMetrics(c); err != nil {
return plugin.Error("template", err)
}
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler { dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
handler.Next = next handler.Next = next
return handler return handler