From 87cce1817d03daca8c31be82d781ec47a4560087 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 16 Mar 2019 08:50:45 +0100 Subject: Merging upstream version 1.13.0. Signed-off-by: Daniel Baumann --- .../bases/FrameworkServices/MySQLService.py | 6 +++ .../bases/FrameworkServices/SimpleService.py | 11 ++-- .../python_modules/bases/collection.py | 61 ---------------------- .../python_modules/bases/loaders.py | 57 ++++---------------- .../python_modules/bases/loggers.py | 2 +- 5 files changed, 21 insertions(+), 116 deletions(-) (limited to 'collectors/python.d.plugin/python_modules') diff --git a/collectors/python.d.plugin/python_modules/bases/FrameworkServices/MySQLService.py b/collectors/python.d.plugin/python_modules/bases/FrameworkServices/MySQLService.py index 9a694aa82..a09041ca4 100644 --- a/collectors/python.d.plugin/python_modules/bases/FrameworkServices/MySQLService.py +++ b/collectors/python.d.plugin/python_modules/bases/FrameworkServices/MySQLService.py @@ -44,6 +44,7 @@ class MySQLService(SimpleService): properties['user'] = conf['user'] if conf.get('pass'): properties['passwd'] = conf['pass'] + if conf.get('socket'): properties['unix_socket'] = conf['socket'] elif conf.get('host'): @@ -51,9 +52,14 @@ class MySQLService(SimpleService): properties['port'] = int(conf.get('port', 3306)) elif conf.get('my.cnf'): if MySQLdb.__name__ == 'pymysql': + # TODO: this is probablt wrong, it depends on version self.error('"my.cnf" parsing is not working for pymysql') else: properties['read_default_file'] = conf['my.cnf'] + + if conf.get('ssl'): + properties['ssl'] = conf['ssl'] + if isinstance(extra_conf, dict) and extra_conf: properties.update(extra_conf) diff --git a/collectors/python.d.plugin/python_modules/bases/FrameworkServices/SimpleService.py b/collectors/python.d.plugin/python_modules/bases/FrameworkServices/SimpleService.py index c7ab7f244..4c1d6ba64 100644 --- a/collectors/python.d.plugin/python_modules/bases/FrameworkServices/SimpleService.py +++ b/collectors/python.d.plugin/python_modules/bases/FrameworkServices/SimpleService.py @@ -4,13 +4,13 @@ # Author: Ilya Mashchenko (l2isbad) # SPDX-License-Identifier: GPL-3.0-or-later -from threading import Thread + from time import sleep, time from third_party.monotonic import monotonic from bases.charts import Charts, ChartError, create_runtime_chart -from bases.collection import OldVersionCompatibility, safe_print +from bases.collection import safe_print from bases.loggers import PythonDLimitedLogger RUNTIME_CHART_UPDATE = 'BEGIN netdata.runtime_{job_name} {since_last}\n' \ @@ -55,7 +55,7 @@ class RuntimeCounters: self.penalty = round(min(self.retries * self.update_every / 2, MAX_PENALTY)) -class SimpleService(Thread, PythonDLimitedLogger, OldVersionCompatibility, object): +class SimpleService(PythonDLimitedLogger, object): """ Prototype of Service class. Implemented basic functionality to run jobs by `python.d.plugin` @@ -65,10 +65,7 @@ class SimpleService(Thread, PythonDLimitedLogger, OldVersionCompatibility, objec :param configuration: :param name: """ - Thread.__init__(self) - self.daemon = True PythonDLimitedLogger.__init__(self) - OldVersionCompatibility.__init__(self) self.configuration = configuration self.order = list() self.definitions = dict() @@ -91,7 +88,7 @@ class SimpleService(Thread, PythonDLimitedLogger, OldVersionCompatibility, objec @property def name(self): - if self.job_name: + if self.job_name and self.job_name != self.module_name: return '_'.join([self.module_name, self.override_name or self.job_name]) return self.module_name diff --git a/collectors/python.d.plugin/python_modules/bases/collection.py b/collectors/python.d.plugin/python_modules/bases/collection.py index 479a3b610..7a3390bc6 100644 --- a/collectors/python.d.plugin/python_modules/bases/collection.py +++ b/collectors/python.d.plugin/python_modules/bases/collection.py @@ -82,64 +82,3 @@ def read_last_line(f): break result = opened.readline() return result.decode() - - -class OldVersionCompatibility: - - def __init__(self): - self._data_stream = str() - - def begin(self, type_id, microseconds=0): - """ - :param type_id: - :param microseconds: or : must be a digit - :return: - """ - self._data_stream += CHART_BEGIN.format(type_id, microseconds) - - def set(self, dim_id, value): - """ - :param dim_id: - :param value: or : must be a digit - :return: - """ - self._data_stream += DIMENSION_SET.format(dim_id, value) - - def end(self): - self._data_stream += 'END\n' - - def chart(self, type_id, name='', title='', units='', family='', category='', chart_type='line', - priority='', update_every=''): - """ - :param type_id: - :param name: - :param title: - :param units: - :param family: - :param category: - :param chart_type: - :param priority: or - :param update_every: or - :return: - """ - self._data_stream += CHART_CREATE.format(type_id, name, title, units, - family, category, chart_type, - priority, update_every) - - def dimension(self, dim_id, name=None, algorithm="absolute", multiplier=1, divisor=1, hidden=False): - """ - :param dim_id: - :param name: or None - :param algorithm: - :param multiplier: or : must be a digit - :param divisor: or : must be a digit - :param hidden: : literally "hidden" or "" - :return: - """ - self._data_stream += DIMENSION_CREATE.format(dim_id, name or dim_id, algorithm, - multiplier, divisor, hidden or str()) - - @on_try_except_finally(on_except=(exit, 1)) - def commit(self): - print(self._data_stream) - self._data_stream = str() diff --git a/collectors/python.d.plugin/python_modules/bases/loaders.py b/collectors/python.d.plugin/python_modules/bases/loaders.py index 9eb268ce7..d8b2ec815 100644 --- a/collectors/python.d.plugin/python_modules/bases/loaders.py +++ b/collectors/python.d.plugin/python_modules/bases/loaders.py @@ -3,7 +3,6 @@ # Author: Ilya Mashchenko (l2isbad) # SPDX-License-Identifier: GPL-3.0-or-later -import types from sys import version_info @@ -18,24 +17,23 @@ except ImportError: from yaml import SafeLoader as YamlSafeLoader -if PY_VERSION > (3, 1): - from importlib.machinery import SourceFileLoader - DEFAULT_MAPPING_TAG = 'tag:yaml.org,2002:map' -else: - from imp import load_source as SourceFileLoader - DEFAULT_MAPPING_TAG = u'tag:yaml.org,2002:map' - try: from collections import OrderedDict except ImportError: from third_party.ordereddict import OrderedDict +DEFAULT_MAPPING_TAG = 'tag:yaml.org,2002:map' if PY_VERSION > (3, 1) else u'tag:yaml.org,2002:map' + + def dict_constructor(loader, node): return OrderedDict(loader.construct_pairs(node)) -def safe_load(stream): +YamlSafeLoader.add_constructor(DEFAULT_MAPPING_TAG, dict_constructor) + + +def load_yaml(stream): loader = YamlSafeLoader(stream) try: return loader.get_single_data() @@ -43,41 +41,6 @@ def safe_load(stream): loader.dispose() -YamlSafeLoader.add_constructor(DEFAULT_MAPPING_TAG, dict_constructor) - - -class YamlOrderedLoader: - @staticmethod - def load_config_from_file(file_name): - opened, loaded = False, False - try: - stream = open(file_name, 'r') - opened = True - loader = YamlSafeLoader(stream) - loaded = True - parsed = loader.get_single_data() or dict() - except Exception as error: - return dict(), error - else: - return parsed, None - finally: - if opened: - stream.close() - if loaded: - loader.dispose() - - -class SourceLoader: - @staticmethod - def load_module_from_file(name, path): - try: - loaded = SourceFileLoader(name, path) - if isinstance(loaded, types.ModuleType): - return loaded, None - return loaded.load_module(), None - except Exception as error: - return None, error - - -class ModuleAndConfigLoader(YamlOrderedLoader, SourceLoader): - pass +def load_config(file_name): + with open(file_name, 'r') as stream: + return load_yaml(stream) diff --git a/collectors/python.d.plugin/python_modules/bases/loggers.py b/collectors/python.d.plugin/python_modules/bases/loggers.py index 098294d3e..aaf974952 100644 --- a/collectors/python.d.plugin/python_modules/bases/loggers.py +++ b/collectors/python.d.plugin/python_modules/bases/loggers.py @@ -26,7 +26,7 @@ LOGGING_LEVELS = {'CRITICAL': 50, DEFAULT_LOG_LINE_FORMAT = '%(asctime)s: %(name)s %(levelname)s : %(message)s' DEFAULT_LOG_TIME_FORMAT = '%Y-%m-%d %H:%M:%S' -PYTHON_D_LOG_LINE_FORMAT = '%(asctime)s: %(name)s %(levelname)s: %(module_name)s: %(job_name)s: %(message)s' +PYTHON_D_LOG_LINE_FORMAT = '%(asctime)s: %(name)s %(levelname)s: %(module_name)s[%(job_name)s] : %(message)s' PYTHON_D_LOG_NAME = 'python.d' -- cgit v1.2.3