This commit is contained in:
pegasko 2023-10-30 00:03:46 +03:00
parent 53a0036b59
commit 7568ed5650
3 changed files with 28 additions and 27 deletions

10
Corefile Normal file
View file

@ -0,0 +1,10 @@
.:9999 {
reload 2s
log
errors
dnsstat
prometheus 0.0.0.0:51273
forward . 1.1.1.1
}

View file

@ -8,6 +8,8 @@ import (
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
"github.com/coredns/coredns/request"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/miekg/dns"
)
@ -19,6 +21,7 @@ type DNSStat struct {
func init() { plugin.Register("dnsstat", setup) }
// Register
func setup(c *caddy.Controller) error {
for c.Next() {
if c.NextArg() {
@ -33,6 +36,21 @@ func setup(c *caddy.Controller) error {
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.
func (d DNSStat) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
state := request.Request{W: w, Req: r}

View file

@ -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