From bd67875f26d7f5e7cea7c77a451b27c47b8d000b Mon Sep 17 00:00:00 2001 From: paulfantom Date: Wed, 22 Jun 2016 20:40:20 +0200 Subject: [PATCH] fix some timeout issues --- plugins.d/python.d.plugin | 5 ++++- python.d/apache.chart.py | 5 ++++- python.d/nginx.chart.py | 4 ++-- python.d/phpfpm.chart.py | 5 ++++- python.d/python_modules/base.py | 8 ++++++-- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/plugins.d/python.d.plugin b/plugins.d/python.d.plugin index f1aba16c..e9f1d5de 100755 --- a/plugins.d/python.d.plugin +++ b/plugins.d/python.d.plugin @@ -477,7 +477,10 @@ class PythonCharts(object): i += 1 if len(next_runs) == 0: fatal('no python.d modules loaded.') - time.sleep(min(next_runs) - time.time()) + try: + time.sleep(min(next_runs) - time.time()) + except IOError: + pass def read_config(path): diff --git a/python.d/apache.chart.py b/python.d/apache.chart.py index 2de62b7e..71a68ba8 100644 --- a/python.d/apache.chart.py +++ b/python.d/apache.chart.py @@ -102,7 +102,10 @@ class Service(UrlService): Format data received from http request :return: dict """ - raw = self._get_data().split("\n") + try: + raw = self._get_data().split("\n") + except AttributeError: + return None data = {} for row in raw: tmp = row.split(":") diff --git a/python.d/nginx.chart.py b/python.d/nginx.chart.py index 17c151f7..89752f56 100644 --- a/python.d/nginx.chart.py +++ b/python.d/nginx.chart.py @@ -67,8 +67,8 @@ class Service(UrlService): Format data received from http request :return: dict """ - raw = self._get_data().split(" ") try: + raw = self._get_data().split(" ") return {'active': int(raw[2]), 'requests': int(raw[7]), 'reading': int(raw[11]), @@ -76,5 +76,5 @@ class Service(UrlService): 'waiting': int(raw[15]), 'accepts': int(raw[8]), 'handled': int(raw[9])} - except ValueError: + except (ValueError, AttributeError): return None diff --git a/python.d/phpfpm.chart.py b/python.d/phpfpm.chart.py index f75faaca..8fadf2be 100755 --- a/python.d/phpfpm.chart.py +++ b/python.d/phpfpm.chart.py @@ -68,7 +68,10 @@ class Service(UrlService): Format data received from http request :return: dict """ - raw = self._get_data().split('\n') + try: + raw = self._get_data().split('\n') + except AttributeError: + return None data = {} for row in raw: tmp = row.split(":") diff --git a/python.d/python_modules/base.py b/python.d/python_modules/base.py index cfb27abf..710ead1b 100644 --- a/python.d/python_modules/base.py +++ b/python.d/python_modules/base.py @@ -123,13 +123,17 @@ class UrlService(BaseService): Get raw data from http request :return: str """ + raw = None try: f = urlopen(self.url, timeout=self.update_every) raw = f.read().decode('utf-8') - f.close() except Exception as e: self.error(self.__module__, str(e)) - return None + finally: + try: + f.close() + except: + pass return raw def _formatted_data(self): -- 2.39.2