50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package dnsstat
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/coredns/caddy"
|
|
"github.com/coredns/coredns/core/dnsserver"
|
|
"github.com/coredns/coredns/plugin"
|
|
"github.com/coredns/coredns/plugin/pkg/dnstest"
|
|
"github.com/coredns/coredns/plugin/pkg/replacer"
|
|
"github.com/coredns/coredns/request"
|
|
|
|
"github.com/miekg/dns"
|
|
)
|
|
|
|
// Dump implement the plugin interface.
|
|
type DNSStat struct {
|
|
Next plugin.Handler
|
|
}
|
|
|
|
func init() { plugin.Register("dnsstat", setup) }
|
|
|
|
func setup(c *caddy.Controller) error {
|
|
for c.Next() {
|
|
if c.NextArg() {
|
|
return plugin.Error("dnsstat", c.ArgErr())
|
|
}
|
|
}
|
|
|
|
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
|
return DNSStat{Next: next}
|
|
})
|
|
|
|
return nil
|
|
}
|
|
|
|
// 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}
|
|
|
|
// Metric increment
|
|
requestCount.WithLabelValues(metrics.WithServer(ctx)).Inc()
|
|
return plugin.NextOrFailure(d.Name(), d.Next, ctx, w, r)
|
|
}
|
|
|
|
// Name implements the Handler interface.
|
|
func (d DNSStat) Name() string { return "dnsstat" }
|