Improved error and timeout handling.
Chris committed
Feb 20, 2018 at 23:37 UTC
239a31150b1193b1e3dcdd2a1bb16231c61bc6c9
3 files changed
+8
-7
conf.d/python.d/httpcheck.conf
+1
-1
@@ -52,7 +52,7 @@
52
# update_every: 1 # [optional] the JOB's data collection frequency
53
# priority: 60000 # [optional] the JOB's order on the dashboard
54
# retries: 60 # [optional] the JOB's number of restoration attempts
55
-# request_timeout: 1 # [optional] the timeout when connecting
55
+# timeout: 1 # [optional] the timeout when connecting, supports decimals (e.g. 0.5s)
56
# url: 'http[s]://host-ip-or-dns[:port][path]'
57
# # [required] the remote host url to connect to. If [:port] is missing, it defaults to 80
58
# # for HTTP and 443 for HTTPS. [path] is optional too, defaults to /
python.d/README.md
+1
-1
@@ -881,7 +881,7 @@ server:
881
url: 'http://host:port/path' # required
882
status_accepted: # optional
883
- 200
884
- request_timeout: 1 # optional
884
+ timeout: 1 # optional, supports decimals (e.g. 0.2)
885
update_every: 1 # optional
886
regex: '.*' # optional
887
redirect: yes # optional
python.d/httpcheck.chart.py
+6
-5
@@ -82,9 +82,10 @@ class Service(UrlService):
82
data[HTTP_ERROR] = 0
83
url = self.url
84
try:
85
+ retries = 1 if self.follow_redirect else False
86
start = time.time()
87
response = self._manager.request(
87
- method='GET', url=url, timeout=self.request_timeout, retries=1, headers=self._manager.headers,
88
+ method='GET', url=url, timeout=self.request_timeout, retries=retries, headers=self._manager.headers,
89
redirect=self.follow_redirect
90
)
91
diff = time.time() - start
@@ -102,12 +103,12 @@ class Service(UrlService):
103
else:
104
data[HTTP_ERROR] = STATUS_NOT_ACCEPTED
105
105
- except urllib3.exceptions.TimeoutError:
106
- self.debug("Connection timed out: {url}".format(url=url))
106
+ except (urllib3.exceptions.TimeoutError, urllib3.exceptions.PoolError) as error:
107
+ self.debug("Connection timed out: {url}. Error: {error}".format(url=url, error=error))
108
data[HTTP_ERROR] = CONNECTION_TIMED_OUT
109
109
- except urllib3.exceptions.HTTPError:
110
- self.debug("Connection timed out: {url}".format(url=url))
110
+ except urllib3.exceptions.HTTPError as error:
111
+ self.debug("Connection failed: {url}. Error: {error}".format(url=url, error=error))
112
data[HTTP_ERROR] = CONNECTION_FAILED
113
114
except (TypeError, AttributeError) as error: