gnvoerk
This commit is contained in:
parent
53a0036b59
commit
7568ed5650
3 changed files with 28 additions and 27 deletions
10
Corefile
Normal file
10
Corefile
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
.:9999 {
|
||||||
|
reload 2s
|
||||||
|
log
|
||||||
|
errors
|
||||||
|
dnsstat
|
||||||
|
|
||||||
|
prometheus 0.0.0.0:51273
|
||||||
|
|
||||||
|
forward . 1.1.1.1
|
||||||
|
}
|
18
dnsstat.go
18
dnsstat.go
|
@ -8,6 +8,8 @@ import (
|
||||||
"github.com/coredns/coredns/plugin"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/plugin/metrics"
|
"github.com/coredns/coredns/plugin/metrics"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
@ -19,6 +21,7 @@ type DNSStat struct {
|
||||||
|
|
||||||
func init() { plugin.Register("dnsstat", setup) }
|
func init() { plugin.Register("dnsstat", setup) }
|
||||||
|
|
||||||
|
// Register
|
||||||
func setup(c *caddy.Controller) error {
|
func setup(c *caddy.Controller) error {
|
||||||
for c.Next() {
|
for c.Next() {
|
||||||
if c.NextArg() {
|
if c.NextArg() {
|
||||||
|
@ -33,6 +36,21 @@ func setup(c *caddy.Controller) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Metrics counter
|
||||||
|
var requestCount = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||||
|
Namespace: plugin.Namespace,
|
||||||
|
Subsystem: "dnsstat",
|
||||||
|
Name: "dnsstat_request_count_total",
|
||||||
|
Help: "Counter of requests made.",
|
||||||
|
}, []string{
|
||||||
|
"server",
|
||||||
|
"zone",
|
||||||
|
"class",
|
||||||
|
"type",
|
||||||
|
"name",
|
||||||
|
"client_ip",
|
||||||
|
})
|
||||||
|
|
||||||
// ServeDNS implements the plugin.Handler interface.
|
// ServeDNS implements the plugin.Handler interface.
|
||||||
func (d DNSStat) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
func (d DNSStat) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||||
state := request.Request{W: w, Req: r}
|
state := request.Request{W: w, Req: r}
|
||||||
|
|
27
metrics.go
27
metrics.go
|
@ -1,27 +0,0 @@
|
||||||
package dnsstat
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/coredns/coredns/plugin"
|
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Track total requests made to given domain name + misc
|
|
||||||
var requestCount = promauto.NewCounterVec(prometheus.CounterOpts{
|
|
||||||
Namespace: plugin.Namespace,
|
|
||||||
Subsystem: "dnsstat",
|
|
||||||
Name: "dnsstat_request_count_total",
|
|
||||||
Help: "Counter of requests made.",
|
|
||||||
}, []string{
|
|
||||||
"server",
|
|
||||||
"zone",
|
|
||||||
"class",
|
|
||||||
"type",
|
|
||||||
"name",
|
|
||||||
"client_ip",
|
|
||||||
})
|
|
||||||
|
|
||||||
var once sync.Once
|
|
Loading…
Reference in a new issue