summaryrefslogtreecommitdiffstats
path: root/collectors/python.d.plugin/python_modules
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2019-05-21 18:56:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2019-05-21 18:56:05 +0000
commit54deae27eed83a162ee438ef6bad4a23767757dd (patch)
treeda5333377dfacf22177375aef822a8e696f007eb /collectors/python.d.plugin/python_modules
parentReleasing debian version 1.14.0-1. (diff)
downloadnetdata-54deae27eed83a162ee438ef6bad4a23767757dd.tar.xz
netdata-54deae27eed83a162ee438ef6bad4a23767757dd.zip
Merging upstream version 1.15.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'collectors/python.d.plugin/python_modules')
-rw-r--r--collectors/python.d.plugin/python_modules/bases/FrameworkServices/SocketService.py23
-rw-r--r--collectors/python.d.plugin/python_modules/bases/FrameworkServices/UrlService.py9
2 files changed, 23 insertions, 9 deletions
diff --git a/collectors/python.d.plugin/python_modules/bases/FrameworkServices/SocketService.py b/collectors/python.d.plugin/python_modules/bases/FrameworkServices/SocketService.py
index c8b2724da..27519b76a 100644
--- a/collectors/python.d.plugin/python_modules/bases/FrameworkServices/SocketService.py
+++ b/collectors/python.d.plugin/python_modules/bases/FrameworkServices/SocketService.py
@@ -16,6 +16,11 @@ else:
from bases.FrameworkServices.SimpleService import SimpleService
+DEFAULT_CONNECT_TIMEOUT = 2.0
+DEFAULT_READ_TIMEOUT = 2.0
+DEFAULT_WRITE_TIMEOUT = 2.0
+
+
class SocketService(SimpleService):
def __init__(self, configuration=None, name=None):
self._sock = None
@@ -31,6 +36,9 @@ class SocketService(SimpleService):
self.__socket_config = None
self.__empty_request = "".encode()
SimpleService.__init__(self, configuration=configuration, name=name)
+ self.connect_timeout = configuration.get('connect_timeout', DEFAULT_CONNECT_TIMEOUT)
+ self.read_timeout = configuration.get('read_timeout', DEFAULT_READ_TIMEOUT)
+ self.write_timeout = configuration.get('write_timeout', DEFAULT_WRITE_TIMEOUT)
def _socket_error(self, message=None):
if self.unix_socket is not None:
@@ -86,6 +94,8 @@ class SocketService(SimpleService):
try:
self.debug('connecting socket to "{address}", port {port}'.format(address=sa[0], port=sa[1]))
+ self._sock.settimeout(self.connect_timeout)
+ self.debug('set socket connect timeout to: {0}'.format(self._sock.gettimeout()))
self._sock.connect(sa)
except (socket.error, ssl.SSLError) as error:
self.error('Failed to connect to "{address}", port {port}, error: {error}'.format(address=sa[0],
@@ -111,6 +121,8 @@ class SocketService(SimpleService):
try:
self.debug('attempting DGRAM unix socket "{0}"'.format(self.unix_socket))
self._sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
+ self._sock.settimeout(self.connect_timeout)
+ self.debug('set socket connect timeout to: {0}'.format(self._sock.gettimeout()))
self._sock.connect(self.unix_socket)
self.debug('connected DGRAM unix socket "{0}"'.format(self.unix_socket))
return True
@@ -121,6 +133,8 @@ class SocketService(SimpleService):
try:
self.debug('attempting STREAM unix socket "{0}"'.format(self.unix_socket))
self._sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ self._sock.settimeout(self.connect_timeout)
+ self.debug('set socket connect timeout to: {0}'.format(self._sock.gettimeout()))
self._sock.connect(self.unix_socket)
self.debug('connected STREAM unix socket "{0}"'.format(self.unix_socket))
return True
@@ -156,11 +170,6 @@ class SocketService(SimpleService):
self._sock = None
self.__socket_config = None
- if self._sock is not None:
- self._sock.setblocking(0)
- self._sock.settimeout(5)
- self.debug('set socket timeout to: {0}'.format(self._sock.gettimeout()))
-
def _disconnect(self):
"""
Close socket connection
@@ -183,6 +192,8 @@ class SocketService(SimpleService):
# Send request if it is needed
if self.request != self.__empty_request:
try:
+ self.debug('set socket write timeout to: {0}'.format(self._sock.gettimeout()))
+ self._sock.settimeout(self.write_timeout)
self.debug('sending request: {0}'.format(request or self.request))
self._sock.send(request or self.request)
except Exception as error:
@@ -203,6 +214,8 @@ class SocketService(SimpleService):
while True:
self.debug('receiving response')
try:
+ self.debug('set socket read timeout to: {0}'.format(self._sock.gettimeout()))
+ self._sock.settimeout(self.read_timeout)
buf = self._sock.recv(4096)
except Exception as error:
self._socket_error('failed to receive response: {0}'.format(error))
diff --git a/collectors/python.d.plugin/python_modules/bases/FrameworkServices/UrlService.py b/collectors/python.d.plugin/python_modules/bases/FrameworkServices/UrlService.py
index 1e87c9948..439456655 100644
--- a/collectors/python.d.plugin/python_modules/bases/FrameworkServices/UrlService.py
+++ b/collectors/python.d.plugin/python_modules/bases/FrameworkServices/UrlService.py
@@ -88,14 +88,14 @@ class UrlService(SimpleService):
self.error('build_manager() error:', str(error))
return None
- def _get_raw_data(self, url=None, manager=None):
+ def _get_raw_data(self, url=None, manager=None, **kwargs):
"""
Get raw data from http request
:return: str
"""
try:
- status, data = self._get_raw_data_with_status(url, manager)
- except (urllib3.exceptions.HTTPError, TypeError, AttributeError) as error:
+ status, data = self._get_raw_data_with_status(url, manager, **kwargs)
+ except Exception as error:
self.error('Url: {url}. Error: {error}'.format(url=url or self.url, error=error))
return None
@@ -105,7 +105,7 @@ class UrlService(SimpleService):
self.debug('Url: {url}. Http response status code: {code}'.format(url=url or self.url, code=status))
return None
- def _get_raw_data_with_status(self, url=None, manager=None, retries=1, redirect=True):
+ def _get_raw_data_with_status(self, url=None, manager=None, retries=1, redirect=True, **kwargs):
"""
Get status and response body content from http request. Does not catch exceptions
:return: int, str
@@ -123,6 +123,7 @@ class UrlService(SimpleService):
retries=retry,
headers=manager.headers,
redirect=redirect,
+ **kwargs
)
if isinstance(response.data, str):
return response.status, response.data