forked from coredns/coredns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.go
74 lines (61 loc) · 1.79 KB
/
report.go
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
62
63
64
65
66
67
68
69
70
71
72
73
74
package vars
import (
"context"
"time"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/request"
"github.com/miekg/dns"
)
// Report reports the metrics data associated with request.
func Report(ctx context.Context, 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"
}
server := WithServer(ctx)
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()
}
// WithServer returns the current server handling the request.
func WithServer(ctx context.Context) string {
srv := ctx.Value(plugin.ServerCtx{})
if srv == nil {
return ""
}
return srv.(string)
}
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"