Some monitoring refactoring

This commit is contained in:
Miek Gieben
2016-04-06 13:42:56 +01:00
parent be80bf518a
commit 9f5e081a09
3 changed files with 15 additions and 9 deletions

View File

@@ -1,7 +1,6 @@
package metrics
import (
"strconv"
"time"
"golang.org/x/net/context"
@@ -12,7 +11,6 @@ import (
func (m Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
state := middleware.State{W: w, Req: r}
qname := state.Name()
qtype := state.Type()
zone := middleware.Zones(m.ZoneNames).Matches(qname)
@@ -24,10 +22,14 @@ 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)
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, strconv.Itoa(rw.Rcode()), qtype).Inc()
m.Report(zone, qtype, rw)
return status, err
}
func (m Metrics) Report(zone, qtype string, rw *middleware.ResponseRecorder) {
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()
}