aboutsummaryrefslogtreecommitdiff
path: root/plugin/metrics/vars/report.go
blob: fe6a5dccd5b7dbecc6c15e1aab875181190172a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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"