This commit is contained in:
pegasko 2023-10-29 20:19:35 +03:00
parent ca40b25c5e
commit f7ed1accfc
2 changed files with 13 additions and 2 deletions

View file

@ -7,10 +7,15 @@ import (
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/miekg/dns"
)
// Define log to be a logger with the plugin name in it. This way we can just use log.Info and
// friends to log.
var log = clog.NewWithPlugin("dnsstat")
// Dump implement the plugin interface.
type DNSStat struct {
Next plugin.Handler
@ -35,9 +40,15 @@ func setup(c *caddy.Controller) error {
// ServeDNS implements the plugin.Handler interface.
func (d DNSStat) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
// Debug log that we've have seen the query. This will only be shown when the debug plugin is loaded.
log.Error("Received response")
// Wrap.
pw := NewResponsePrinter(w)
// Metric increment
requestCount.WithLabelValues(metrics.WithServer(ctx)).Inc()
return plugin.NextOrFailure(d.Name(), d.Next, ctx, w, r)
return plugin.NextOrFailure(d.Name(), d.Next, ctx, pw, r)
}
// Name implements the Handler interface.

View file

@ -13,7 +13,7 @@ import (
var requestCount = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace,
Subsystem: "dnsstat",
Name: "request_count_total",
Name: "dnsstat_request_count_total",
Help: "Counter of requests made.",
}, []string{"server"})