* middleware/metrics: add more metrics middleware/cache: Add metrics for number of elements in the cache. Also export the total size. Update README to detail the new metrics. middleware/metrics Move metrics into subpackage called "vars". This breaks the import cycle and is cleaner. This allows vars.Report to be used in the the dnsserver to log refused queries. middleware/metrics: tests Add tests to the metrics framework. The metrics/test subpackage allows scraping of the local server. Do a few test scrape of the metrics that are defined in the metrics middleware. This also allows metrics integration tests to check if the caching and dnssec middleware export their metrics correctly. * update README * typos * fix tests
33 lines
895 B
Go
33 lines
895 B
Go
package metrics
|
|
|
|
import (
|
|
"github.com/miekg/coredns/middleware"
|
|
"github.com/miekg/coredns/middleware/metrics/vars"
|
|
"github.com/miekg/coredns/middleware/pkg/dnsrecorder"
|
|
"github.com/miekg/coredns/middleware/pkg/rcode"
|
|
"github.com/miekg/coredns/request"
|
|
|
|
"github.com/miekg/dns"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
// ServeDNS implements the Handler interface.
|
|
func (m *Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
|
state := request.Request{W: w, Req: r}
|
|
|
|
qname := state.QName()
|
|
zone := middleware.Zones(m.ZoneNames()).Matches(qname)
|
|
if zone == "" {
|
|
zone = "."
|
|
}
|
|
|
|
// Record response to get status code and size of the reply.
|
|
rw := dnsrecorder.New(w)
|
|
status, err := m.Next.ServeDNS(ctx, rw, r)
|
|
|
|
vars.Report(state, zone, rcode.ToString(rw.Rcode), rw.Size, rw.Start)
|
|
|
|
return status, err
|
|
}
|
|
|
|
func (m *Metrics) Name() string { return "prometheus" }
|