coredns/plugin/metrics/vars/report.go
Miek Gieben 9a8c301a42 Remove server addr from the context (#2722)
* more

Signed-off-by: Miek Gieben <miek@miek.nl>

* Remove server addr from the context

This was added twice, just leave the server which also holds the
address.

Conflicts with #2719 but should be easy to fix.

Signed-off-by: Miek Gieben <miek@miek.nl>

* doesn't need server context

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-03-25 10:46:44 -07:00

61 lines
1.5 KiB
Go

package vars
import (
"time"
"github.com/coredns/coredns/request"
"github.com/miekg/dns"
)
// Report reports the metrics data associated with request.
func Report(server string, req request.Request, zone, rcode string, size int, start time.Time) {
// Proto and Family.
net := req.Proto()
fam := "1"
if req.Family() == 2 {
fam = "2"
}
typ := req.QType()
RequestCount.WithLabelValues(server, zone, net, fam).Inc()
RequestDuration.WithLabelValues(server, zone).Observe(time.Since(start).Seconds())
if req.Do() {
RequestDo.WithLabelValues(server, zone).Inc()
}
if _, known := monitorType[typ]; known {
RequestType.WithLabelValues(server, zone, dns.Type(typ).String()).Inc()
} else {
RequestType.WithLabelValues(server, zone, other).Inc()
}
ResponseSize.WithLabelValues(server, zone, net).Observe(float64(size))
RequestSize.WithLabelValues(server, zone, net).Observe(float64(req.Len()))
ResponseRcode.WithLabelValues(server, zone, rcode).Inc()
}
var monitorType = map[uint16]struct{}{
dns.TypeAAAA: struct{}{},
dns.TypeA: struct{}{},
dns.TypeCNAME: struct{}{},
dns.TypeDNSKEY: struct{}{},
dns.TypeDS: struct{}{},
dns.TypeMX: struct{}{},
dns.TypeNSEC3: struct{}{},
dns.TypeNSEC: struct{}{},
dns.TypeNS: struct{}{},
dns.TypePTR: struct{}{},
dns.TypeRRSIG: struct{}{},
dns.TypeSOA: struct{}{},
dns.TypeSRV: struct{}{},
dns.TypeTXT: struct{}{},
// Meta Qtypes
dns.TypeIXFR: struct{}{},
dns.TypeAXFR: struct{}{},
dns.TypeANY: struct{}{},
}
const other = "other"