From a4dc11167f237e591349d61fc40a1837f5570b07 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Mon, 21 Dec 2015 17:01:28 -0800 Subject: [PATCH 1/2] Adds telemetry on number of DNS queries served, per-agent. --- command/agent/dns.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/command/agent/dns.go b/command/agent/dns.go index 33db8ba7e4..cabae31f9e 100644 --- a/command/agent/dns.go +++ b/command/agent/dns.go @@ -9,6 +9,7 @@ import ( "sync" "time" + "github.com/armon/go-metrics" "github.com/hashicorp/consul/consul" "github.com/hashicorp/consul/consul/structs" "github.com/miekg/dns" @@ -221,6 +222,8 @@ func (d *DNSServer) handlePtr(resp dns.ResponseWriter, req *dns.Msg) { if err := resp.WriteMsg(m); err != nil { d.logger.Printf("[WARN] dns: failed to respond: %v", err) } + + metrics.IncrCounter([]string{"consul", "dns", "query", d.agent.config.NodeName}, 1) } // handleQuery is used to handle DNS queries in the configured domain @@ -256,6 +259,8 @@ func (d *DNSServer) handleQuery(resp dns.ResponseWriter, req *dns.Msg) { if err := resp.WriteMsg(m); err != nil { d.logger.Printf("[WARN] dns: failed to respond: %v", err) } + + metrics.IncrCounter([]string{"consul", "dns", "query", d.agent.config.NodeName}, 1) } // addSOA is used to add an SOA record to a message for the given domain From 651f255b9ba04b302b24d853ec262d5f8ae9ebda Mon Sep 17 00:00:00 2001 From: James Phillips Date: Mon, 21 Dec 2015 18:25:09 -0800 Subject: [PATCH 2/2] Converts the DNS metric to a gauge which gives us a count and a time. --- command/agent/dns.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/command/agent/dns.go b/command/agent/dns.go index cabae31f9e..6cbb89f590 100644 --- a/command/agent/dns.go +++ b/command/agent/dns.go @@ -166,6 +166,7 @@ START: func (d *DNSServer) handlePtr(resp dns.ResponseWriter, req *dns.Msg) { q := req.Question[0] defer func(s time.Time) { + metrics.MeasureSince([]string{"consul", "dns", "ptr_query", d.agent.config.NodeName}, s) d.logger.Printf("[DEBUG] dns: request for %v (%v) from client %s (%s)", q, time.Now().Sub(s), resp.RemoteAddr().String(), resp.RemoteAddr().Network()) @@ -222,14 +223,13 @@ func (d *DNSServer) handlePtr(resp dns.ResponseWriter, req *dns.Msg) { if err := resp.WriteMsg(m); err != nil { d.logger.Printf("[WARN] dns: failed to respond: %v", err) } - - metrics.IncrCounter([]string{"consul", "dns", "query", d.agent.config.NodeName}, 1) } // handleQuery is used to handle DNS queries in the configured domain func (d *DNSServer) handleQuery(resp dns.ResponseWriter, req *dns.Msg) { q := req.Question[0] defer func(s time.Time) { + metrics.MeasureSince([]string{"consul", "dns", "domain_query", d.agent.config.NodeName}, s) d.logger.Printf("[DEBUG] dns: request for %v (%v) from client %s (%s)", q, time.Now().Sub(s), resp.RemoteAddr().String(), resp.RemoteAddr().Network()) @@ -259,8 +259,6 @@ func (d *DNSServer) handleQuery(resp dns.ResponseWriter, req *dns.Msg) { if err := resp.WriteMsg(m); err != nil { d.logger.Printf("[WARN] dns: failed to respond: %v", err) } - - metrics.IncrCounter([]string{"consul", "dns", "query", d.agent.config.NodeName}, 1) } // addSOA is used to add an SOA record to a message for the given domain