From 74ffcc8d2e97bd4c19c62fda637e4ce19678889f Mon Sep 17 00:00:00 2001 From: Chris Green <34572557+cgreen12@users.noreply.github.com> Date: Sun, 2 Jun 2019 13:18:40 -0400 Subject: [PATCH] Do the dns lookup Signed-off-by: Chris Green <34572557+cgreen12@users.noreply.github.com> --- pkg/goldpinger/stats.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/goldpinger/stats.go b/pkg/goldpinger/stats.go index a54b4ca..ad0b899 100644 --- a/pkg/goldpinger/stats.go +++ b/pkg/goldpinger/stats.go @@ -16,6 +16,7 @@ package goldpinger import ( "log" + "net" "time" "github.com/bloomberg/goldpinger/pkg/models" @@ -97,8 +98,24 @@ func init() { func GetStats() *models.PingResults { // GetStats no longer populates the received and made calls - use metrics for that instead + dnsResults := models.DNSResults{} + if len(GoldpingerConfig.DnsHosts) > 0 { + for _, host := range GoldpingerConfig.DnsHosts{ + + var dnsResult models.DNSResult + + start := time.Now() + _, err := net.LookupIP(host) + if err != nil { + dnsResult.Error = err.Error() + } + dnsResult.ResponseTimeMs = time.Since(start).Nanoseconds() / int64(time.Millisecond) + dnsResults[host] = dnsResult + } + } return &models.PingResults{ BootTime: strfmt.DateTime(bootTime), + DNSResults: dnsResults, } }