middleware/metrics: export actual size (#448)

The `*_size*` metrics now export the actual packet length, not the
advertised one (although that might be nice as well).
This commit is contained in:
Miek Gieben
2016-11-29 11:02:43 +00:00
committed by GitHub
parent 4cfd19c7c9
commit 8c8b37a30e
5 changed files with 12 additions and 9 deletions

View File

@@ -16,7 +16,7 @@ import (
type Recorder struct {
dns.ResponseWriter
Rcode int
Size int
Len int
Msg *dns.Msg
Start time.Time
}
@@ -39,16 +39,16 @@ func (r *Recorder) WriteMsg(res *dns.Msg) error {
r.Rcode = res.Rcode
// We may get called multiple times (axfr for instance).
// Save the last message, but add the sizes.
r.Size += res.Len()
r.Len += res.Len()
r.Msg = res
return r.ResponseWriter.WriteMsg(res)
}
// Write is a wrapper that records the size of the message that gets written.
// Write is a wrapper that records the length of the message that gets written.
func (r *Recorder) Write(buf []byte) (int, error) {
n, err := r.ResponseWriter.Write(buf)
if err == nil {
r.Size += n
r.Len += n
}
return n, err
}

View File

@@ -53,7 +53,7 @@ func New(r *dns.Msg, rr *dnsrecorder.Recorder, emptyValue string) Replacer {
rcode = strconv.Itoa(rr.Rcode)
}
rep.replacements["{rcode}"] = rcode
rep.replacements["{size}"] = strconv.Itoa(rr.Size)
rep.replacements["{size}"] = strconv.Itoa(rr.Len)
rep.replacements["{duration}"] = time.Since(rr.Start).String()
}