From 1862f5286130a6cae0c8658a200bbcfc70d136f2 Mon Sep 17 00:00:00 2001 From: Alex Nozdriukhin Date: Sun, 17 May 2020 23:40:13 +0300 Subject: [PATCH] Fix behavior on failed connection --- main.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index c2bf74e..3841b5f 100644 --- a/main.go +++ b/main.go @@ -119,18 +119,18 @@ func getMetrics(options *Options) map[string]string { } } - conn, err = dialer.Dial("tcp", tcpaddr.String()) - if err != nil { - continue - } - res = sendZookeeperCmd(conn, h, "ruok") zkRuok := fmt.Sprintf("zk_ruok{%s}", hostLabel) - if res == "imok" { - metrics[zkRuok] = "1" - } else { - if strings.Contains(res, cmdNotExecutedSffx) { - logNotAllowed("ruok", hostLabel) + if conn, err = dialer.Dial("tcp", tcpaddr.String()); err == nil { + res = sendZookeeperCmd(conn, h, "ruok") + if res == "imok" { + metrics[zkRuok] = "1" + } else { + if strings.Contains(res, cmdNotExecutedSffx) { + logNotAllowed("ruok", hostLabel) + } + metrics[zkRuok] = "0" } + } else { metrics[zkRuok] = "0" }