2016-10-26 10:01:52 +01:00
|
|
|
package vars
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
|
2017-02-21 22:51:47 -08:00
|
|
|
"github.com/coredns/coredns/request"
|
2016-10-26 10:01:52 +01:00
|
|
|
|
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
|
)
|
|
|
|
|
|
2019-03-25 19:04:03 +00:00
|
|
|
// Report reports the metrics data associated with request. This function is exported because it is also
|
|
|
|
|
// called from core/dnsserver to report requests hitting the server that should not be handled and are thus
|
|
|
|
|
// not sent down the plugin chain.
|
2019-03-25 17:46:44 +00:00
|
|
|
func Report(server string, req request.Request, zone, rcode string, size int, start time.Time) {
|
2016-11-29 11:02:43 +00:00
|
|
|
// Proto and Family.
|
2016-10-26 10:01:52 +01:00
|
|
|
net := req.Proto()
|
|
|
|
|
fam := "1"
|
|
|
|
|
if req.Family() == 2 {
|
|
|
|
|
fam = "2"
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-18 09:42:20 +01:00
|
|
|
typ := req.QType()
|
|
|
|
|
RequestCount.WithLabelValues(server, zone, net, fam).Inc()
|
|
|
|
|
RequestDuration.WithLabelValues(server, zone).Observe(time.Since(start).Seconds())
|
2016-10-26 10:01:52 +01:00
|
|
|
|
|
|
|
|
if req.Do() {
|
2018-04-18 09:42:20 +01:00
|
|
|
RequestDo.WithLabelValues(server, zone).Inc()
|
2016-10-26 10:01:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if _, known := monitorType[typ]; known {
|
2018-04-18 09:42:20 +01:00
|
|
|
RequestType.WithLabelValues(server, zone, dns.Type(typ).String()).Inc()
|
2016-10-26 10:01:52 +01:00
|
|
|
} else {
|
2018-04-18 09:42:20 +01:00
|
|
|
RequestType.WithLabelValues(server, zone, other).Inc()
|
2016-10-26 10:01:52 +01:00
|
|
|
}
|
|
|
|
|
|
2018-04-18 09:42:20 +01:00
|
|
|
ResponseSize.WithLabelValues(server, zone, net).Observe(float64(size))
|
|
|
|
|
RequestSize.WithLabelValues(server, zone, net).Observe(float64(req.Len()))
|
2016-10-26 10:01:52 +01:00
|
|
|
|
2018-04-18 09:42:20 +01:00
|
|
|
ResponseRcode.WithLabelValues(server, zone, rcode).Inc()
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-10 10:17:15 +00:00
|
|
|
var monitorType = map[uint16]struct{}{
|
2019-04-08 11:13:46 +01:00
|
|
|
dns.TypeAAAA: {},
|
|
|
|
|
dns.TypeA: {},
|
|
|
|
|
dns.TypeCNAME: {},
|
|
|
|
|
dns.TypeDNSKEY: {},
|
|
|
|
|
dns.TypeDS: {},
|
|
|
|
|
dns.TypeMX: {},
|
|
|
|
|
dns.TypeNSEC3: {},
|
|
|
|
|
dns.TypeNSEC: {},
|
|
|
|
|
dns.TypeNS: {},
|
|
|
|
|
dns.TypePTR: {},
|
|
|
|
|
dns.TypeRRSIG: {},
|
|
|
|
|
dns.TypeSOA: {},
|
|
|
|
|
dns.TypeSRV: {},
|
|
|
|
|
dns.TypeTXT: {},
|
2016-10-26 10:01:52 +01:00
|
|
|
// Meta Qtypes
|
2019-04-08 11:13:46 +01:00
|
|
|
dns.TypeIXFR: {},
|
|
|
|
|
dns.TypeAXFR: {},
|
|
|
|
|
dns.TypeANY: {},
|
2016-10-26 10:01:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const other = "other"
|