2016-03-18 20:57:35 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
|
|
import (
|
2017-09-14 09:36:06 +01:00
|
|
|
"github.com/coredns/coredns/plugin"
|
|
|
|
|
"github.com/coredns/coredns/plugin/metrics/vars"
|
|
|
|
|
"github.com/coredns/coredns/plugin/pkg/dnsrecorder"
|
|
|
|
|
"github.com/coredns/coredns/plugin/pkg/rcode"
|
2017-02-21 22:51:47 -08:00
|
|
|
"github.com/coredns/coredns/request"
|
2016-04-28 10:26:58 +01:00
|
|
|
|
2016-03-18 20:57:35 +00:00
|
|
|
"github.com/miekg/dns"
|
2016-04-28 10:26:58 +01:00
|
|
|
"golang.org/x/net/context"
|
2016-03-18 20:57:35 +00:00
|
|
|
)
|
|
|
|
|
|
2016-09-23 09:14:12 +01:00
|
|
|
// ServeDNS implements the Handler interface.
|
2016-10-04 11:05:04 +01:00
|
|
|
func (m *Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
2016-09-07 11:10:16 +01:00
|
|
|
state := request.Request{W: w, Req: r}
|
2016-06-23 11:21:12 +01:00
|
|
|
|
|
|
|
|
qname := state.QName()
|
2017-09-14 09:36:06 +01:00
|
|
|
zone := plugin.Zones(m.ZoneNames()).Matches(qname)
|
2016-03-18 20:57:35 +00:00
|
|
|
if zone == "" {
|
|
|
|
|
zone = "."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Record response to get status code and size of the reply.
|
2016-09-07 11:10:16 +01:00
|
|
|
rw := dnsrecorder.New(w)
|
2017-09-14 09:36:06 +01:00
|
|
|
status, err := plugin.NextOrFailure(m.Name(), m.Next, ctx, rw, r)
|
2016-03-18 20:57:35 +00:00
|
|
|
|
2016-11-29 11:02:43 +00:00
|
|
|
vars.Report(state, zone, rcode.ToString(rw.Rcode), rw.Len, rw.Start)
|
2016-04-06 13:42:56 +01:00
|
|
|
|
|
|
|
|
return status, err
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-27 11:48:37 +00:00
|
|
|
// Name implements the Handler interface.
|
2016-10-26 10:01:52 +01:00
|
|
|
func (m *Metrics) Name() string { return "prometheus" }
|