You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eagle.apache.org by ji...@apache.org on 2016/12/05 02:12:02 UTC

incubator-eagle git commit: [MINOR] add retry when read jmx timeout

Repository: incubator-eagle
Updated Branches:
  refs/heads/master 30e35de60 -> 3a84a2c62


[MINOR] add retry when read jmx timeout

Author: wujinhu <wu...@126.com>

Closes #686 from wujinhu/EAGLE-790.


Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/3a84a2c6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/3a84a2c6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/3a84a2c6

Branch: refs/heads/master
Commit: 3a84a2c6285146d7765a120ca64567183af6bdf8
Parents: 30e35de
Author: wujinhu <wu...@126.com>
Authored: Mon Dec 5 10:11:57 2016 +0800
Committer: wujinhu <wu...@126.com>
Committed: Mon Dec 5 10:11:57 2016 +0800

----------------------------------------------------------------------
 .../hadoop_jmx_collector/metric_collector.py    | 31 +++++++++++++-------
 1 file changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3a84a2c6/eagle-external/hadoop_jmx_collector/metric_collector.py
----------------------------------------------------------------------
diff --git a/eagle-external/hadoop_jmx_collector/metric_collector.py b/eagle-external/hadoop_jmx_collector/metric_collector.py
index 6eeec5a..c6eac35 100644
--- a/eagle-external/hadoop_jmx_collector/metric_collector.py
+++ b/eagle-external/hadoop_jmx_collector/metric_collector.py
@@ -95,17 +95,28 @@ class Helper:
         url = ":".join([host, str(port)])
         result = None
         response = None
+        attempts = 0
+        exception = None
+        while attempts < 2:
+            try:
+                if https:
+                    logging.info("Reading https://" + str(url) + path)
+                    c = httplib.HTTPSConnection(url, timeout=28)
+                    c.request("GET", path)
+                    response = c.getresponse()
+                else:
+                    logging.info("Reading http://" + str(url) + path)
+                    response = urllib2.urlopen("http://" + str(url) + path, timeout=28)
+                logging.debug("Got response")
+                result = response.read()
+                break
+            except Exception as e:
+                logging.warning(e)
+                exception = e
+                attempts += 1
         try:
-            if https:
-                logging.info("Reading https://" + str(url) + path)
-                c = httplib.HTTPSConnection(url, timeout=57)
-                c.request("GET", path)
-                response = c.getresponse()
-            else:
-                logging.info("Reading http://" + str(url) + path)
-                response = urllib2.urlopen("http://" + str(url) + path, timeout=57)
-            logging.debug("Got response")
-            result = response.read()
+            if attempts >= 2:
+                raise exception
         finally:
             if response is not None:
                 response.close()