diff options
author | 2016-04-06 14:13:29 +0100 | |
---|---|---|
committer | 2016-04-06 14:13:29 +0100 | |
commit | 7e05aa8069b35166832b9a09c98e4de15b2b35f3 (patch) | |
tree | c9de95494da8ef2cce90f43070d6bef070384bcd | |
parent | 9f5e081a097d92c6ddd4592251222da1760fbd34 (diff) | |
download | coredns-7e05aa8069b35166832b9a09c98e4de15b2b35f3.tar.gz coredns-7e05aa8069b35166832b9a09c98e4de15b2b35f3.tar.zst coredns-7e05aa8069b35166832b9a09c98e4de15b2b35f3.zip |
Enable monitoring for non middleware
If monitoring is enabled for one zone, also enable it for when the
server reports REFUSED. Normally the metrics are only enabled if
you enter the middleware, with this you'll see REFUSED queries.
Each of these are reported agains the root zone otherwise
-rw-r--r-- | middleware/prometheus/handler.go | 17 | ||||
-rw-r--r-- | server/server.go | 13 |
2 files changed, 25 insertions, 5 deletions
diff --git a/middleware/prometheus/handler.go b/middleware/prometheus/handler.go index 866cda6a7..b3ef79554 100644 --- a/middleware/prometheus/handler.go +++ b/middleware/prometheus/handler.go @@ -22,14 +22,21 @@ func (m Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) rw := middleware.NewResponseRecorder(w) status, err := m.Next.ServeDNS(ctx, rw, r) - m.Report(zone, qtype, rw) + Report(zone, qtype, rw.Rcode(), rw.Size(), rw.Start()) return status, err } -func (m Metrics) Report(zone, qtype string, rw *middleware.ResponseRecorder) { +// Report is a plain reporting function that the server can use for REFUSED and other +// queries that are turned down because they don't match any middleware. +func Report(zone, qtype, rcode string, size int, start time.Time) { + if requestCount == nil { + // no metrics are enabled + return + } + requestCount.WithLabelValues(zone, qtype).Inc() - requestDuration.WithLabelValues(zone, qtype).Observe(float64(time.Since(rw.Start()) / time.Second)) - responseSize.WithLabelValues(zone, qtype).Observe(float64(rw.Size())) - responseRcode.WithLabelValues(zone, rw.Rcode(), qtype).Inc() + requestDuration.WithLabelValues(zone, qtype).Observe(float64(time.Since(start) / time.Second)) + responseSize.WithLabelValues(zone, qtype).Observe(float64(size)) + responseRcode.WithLabelValues(zone, rcode, qtype).Inc() } diff --git a/server/server.go b/server/server.go index c186c82d2..60727f2e8 100644 --- a/server/server.go +++ b/server/server.go @@ -12,12 +12,15 @@ import ( "net" "os" "runtime" + "strconv" "sync" "time" "golang.org/x/net/context" + "github.com/miekg/coredns/middleware" "github.com/miekg/coredns/middleware/chaos" + "github.com/miekg/coredns/middleware/prometheus" "github.com/miekg/dns" ) @@ -329,8 +332,18 @@ func (s *Server) ServeDNS(w dns.ResponseWriter, r *dns.Msg) { // DefaultErrorFunc responds to an HTTP request with a simple description // of the specified HTTP status code. func DefaultErrorFunc(w dns.ResponseWriter, r *dns.Msg, rcode int) { + // this code is duplicated a few times, TODO(miek) + rc := dns.RcodeToString[rcode] + if rc == "" { + rc = "RCODE" + strconv.Itoa(rcode) + } answer := new(dns.Msg) answer.SetRcode(r, rcode) + + state := middleware.State{W: w, Req: r} + // Default zone to "." here to not blow up this metric + metrics.Report(".", state.Type(), rc, answer.Len(), time.Now()) + w.WriteMsg(answer) } |