aboba
This commit is contained in:
commit
8d1e9e7334
2 changed files with 70 additions and 0 deletions
50
dnsstat.go
Normal file
50
dnsstat.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
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" }
|
20
metrics.go
Normal file
20
metrics.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package dnsstat
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
// requestCount exports a prometheus metric that is incremented every time a query is seen by the example plugin.
|
||||
var requestCount = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "dnsstat",
|
||||
Name: "request_count_total",
|
||||
Help: "Counter of requests made.",
|
||||
}, []string{"server"})
|
||||
|
||||
var once sync.Once
|
Loading…
Reference in a new issue