From 192fc433a2b4868d49f71b538b07cd8520cd2085 Mon Sep 17 00:00:00 2001 From: Chris Green <34572557+cgreen12@users.noreply.github.com> Date: Thu, 4 Jul 2019 03:06:29 -0400 Subject: [PATCH] Added metric for DNS failures Signed-off-by: Chris Green <34572557+cgreen12@users.noreply.github.com> --- pkg/goldpinger/client.go | 1 + pkg/goldpinger/stats.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pkg/goldpinger/client.go b/pkg/goldpinger/client.go index e5994d9..9157bb8 100644 --- a/pkg/goldpinger/client.go +++ b/pkg/goldpinger/client.go @@ -61,6 +61,7 @@ func checkDNS() *models.DNSResults { _, err := net.LookupIP(host) if err != nil { dnsResult.Error = err.Error() + CountDnsError(host) } dnsResult.ResponseTimeMs = time.Since(start).Nanoseconds() / int64(time.Millisecond) results[host] = dnsResult diff --git a/pkg/goldpinger/stats.go b/pkg/goldpinger/stats.go index a54b4ca..0ff5386 100644 --- a/pkg/goldpinger/stats.go +++ b/pkg/goldpinger/stats.go @@ -82,6 +82,16 @@ var ( "type", }, ) + goldpingerDnsErrorsCounter = prometheus.NewCounterVec( + prometheus.CounterOpts{ + Name: "goldpinger_dns_errors_total", + Help: "Statistics of DNS errors per instance", + }, + []string{ + "goldpinger_instance", + "host", + }, + ) bootTime = time.Now() ) @@ -92,6 +102,7 @@ func init() { prometheus.MustRegister(goldpingerResponseTimePeersHistogram) prometheus.MustRegister(goldpingerResponseTimeKubernetesHistogram) prometheus.MustRegister(goldpingerErrorsCounter) + prometheus.MustRegister(goldpingerDnsErrorsCounter) log.Println("Metrics setup - see /metrics") } @@ -131,6 +142,14 @@ func CountError(errorType string) { ).Inc() } +// counts instances of dns errors +func CountDnsError(host string) { + goldpingerDnsErrorsCounter.WithLabelValues( + GoldpingerConfig.Hostname, + host, + ).Inc() +} + // returns a timer for easy observing of the durations of calls to kubernetes API func GetLabeledKubernetesCallsTimer() *prometheus.Timer { return prometheus.NewTimer(