diff options
author | 2018-04-18 09:42:20 +0100 | |
---|---|---|
committer | 2018-04-18 09:42:20 +0100 | |
commit | 08443a9f009fa0529a6d5cbb4708790165c16a0c (patch) | |
tree | ce8af5908e61dde11c271e025175aa9704adc926 /plugin/metrics/vars/report.go | |
parent | 573ad62b770b7320f5499a1fc64a70b8f118e3b9 (diff) | |
download | coredns-08443a9f009fa0529a6d5cbb4708790165c16a0c.tar.gz coredns-08443a9f009fa0529a6d5cbb4708790165c16a0c.tar.zst coredns-08443a9f009fa0529a6d5cbb4708790165c16a0c.zip |
plugin/metrics: add 'server' label (#1682)
* plugin/metrics: add 'server' label
This uses the new WithServer(ctx) to get the current server from the
context.
First in a larger refactor to make all plugins do this.
* compile
* compile
* lala test
* compile and test
* typos
* Dont duplicate the code
Diffstat (limited to 'plugin/metrics/vars/report.go')
-rw-r--r-- | plugin/metrics/vars/report.go | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/plugin/metrics/vars/report.go b/plugin/metrics/vars/report.go index 568a291e3..dc597c610 100644 --- a/plugin/metrics/vars/report.go +++ b/plugin/metrics/vars/report.go @@ -3,13 +3,15 @@ package vars import ( "time" + "github.com/coredns/coredns/plugin" "github.com/coredns/coredns/request" "github.com/miekg/dns" + "golang.org/x/net/context" ) // Report reports the metrics data associcated with request. -func Report(req request.Request, zone, rcode string, size int, start time.Time) { +func Report(ctx context.Context, req request.Request, zone, rcode string, size int, start time.Time) { // Proto and Family. net := req.Proto() fam := "1" @@ -17,25 +19,35 @@ func Report(req request.Request, zone, rcode string, size int, start time.Time) fam = "2" } - typ := req.QType() + server := WithServer(ctx) - RequestCount.WithLabelValues(zone, net, fam).Inc() - RequestDuration.WithLabelValues(zone).Observe(time.Since(start).Seconds()) + typ := req.QType() + RequestCount.WithLabelValues(server, zone, net, fam).Inc() + RequestDuration.WithLabelValues(server, zone).Observe(time.Since(start).Seconds()) if req.Do() { - RequestDo.WithLabelValues(zone).Inc() + RequestDo.WithLabelValues(server, zone).Inc() } if _, known := monitorType[typ]; known { - RequestType.WithLabelValues(zone, dns.Type(typ).String()).Inc() + RequestType.WithLabelValues(server, zone, dns.Type(typ).String()).Inc() } else { - RequestType.WithLabelValues(zone, other).Inc() + RequestType.WithLabelValues(server, zone, other).Inc() } - ResponseSize.WithLabelValues(zone, net).Observe(float64(size)) - RequestSize.WithLabelValues(zone, net).Observe(float64(req.Len())) + ResponseSize.WithLabelValues(server, zone, net).Observe(float64(size)) + RequestSize.WithLabelValues(server, zone, net).Observe(float64(req.Len())) - ResponseRcode.WithLabelValues(zone, rcode).Inc() + 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]bool{ |