fix update_every, PEP8 formatting
paulfantom committed
Jun 21, 2016 at 11:43 UTC
233b65cc1d9ac71d51438dc0502044bf086351b6
2 files changed
+24
-17
plugins.d/python.d.plugin
+20
-14
@@ -10,10 +10,6 @@ import time
10
11
12
MODULE_EXTENSION = ".chart.py"
13
-BASE_CONFIG = {'update_every': 1,
14
- 'priority': 90000,
15
- 'retries': 10}
16
-
13
14
# -----------------------------------------------------------------------------
15
# logging functions
@@ -21,6 +17,7 @@ BASE_CONFIG = {'update_every': 1,
17
PROGRAM = os.path.basename(__file__).replace(".plugin", "")
18
DEBUG_FLAG = False
19
20
+
21
def debug(*args):
22
"""
23
Print message on stderr.
@@ -33,6 +30,7 @@ def debug(*args):
30
sys.stderr.write("\n")
31
sys.stderr.flush()
32
33
+
34
def error(*args):
35
"""
36
Print message on stderr.
@@ -43,6 +41,7 @@ def error(*args):
41
sys.stderr.write("\n")
42
sys.stderr.flush()
43
44
+
45
def info(*args):
46
"""
47
Print message on stderr.
@@ -53,6 +52,7 @@ def info(*args):
52
sys.stderr.write("\n")
53
sys.stderr.flush()
54
55
+
56
def fatal(*args):
57
"""
58
Print message on stderr and exit.
@@ -66,14 +66,13 @@ def fatal(*args):
66
sys.exit(1)
67
68
69
-
69
# -----------------------------------------------------------------------------
70
# globals & python modules management
71
72
# setup environment
73
# https://github.com/firehol/netdata/wiki/External-Plugins#environment-variables
74
MODULES_DIR = os.path.abspath(os.getenv('NETDATA_PLUGINS_DIR',
76
- os.path.dirname(__file__)) + "/../python.d") + "/"
75
+ os.path.dirname(__file__)) + "/../python.d") + "/"
76
CONFIG_DIR = os.getenv('NETDATA_CONFIG_DIR', "/etc/netdata/")
77
UPDATE_EVERY = os.getenv('NETDATA_UPDATE_EVERY', 1)
78
# directories should end with '/'
@@ -81,6 +80,10 @@ if CONFIG_DIR[-1] != "/":
80
CONFIG_DIR += "/"
81
sys.path.append(MODULES_DIR + "python_modules")
82
83
+BASE_CONFIG = {'update_every': UPDATE_EVERY,
84
+ 'priority': 90000,
85
+ 'retries': 10}
86
+
87
try:
88
assert sys.version_info >= (3, 1)
89
import importlib.machinery
@@ -106,12 +109,13 @@ try:
109
except ImportError:
110
fatal('Cannot find yaml library')
111
112
+
113
class PythonCharts(object):
114
"""
115
Main class used to control every python module.
116
"""
117
def __init__(self,
114
- update_every=None,
118
+ update_every=None, # TODO remove this
119
modules=None,
120
modules_path='../python.d/',
121
modules_configs='../conf.d/',
@@ -141,9 +145,9 @@ class PythonCharts(object):
145
146
# good economy and prosperity:
147
self.jobs = self._create_jobs(configured_modules) # type: list
144
- if DEBUG_FLAG and update_every is not None:
145
- for job in self.jobs:
146
- job.create_timetable(update_every)
148
+# if DEBUG_FLAG and update_every is not None:
149
+# for job in self.jobs:
150
+# job.create_timetable(update_every)
151
152
@staticmethod
153
def _import_module(path, name=None):
@@ -532,7 +536,7 @@ def run():
536
conf = read_config(configfile)
537
if conf is not None:
538
try:
535
- # FIXME: is this right? exit the whole plugin?
539
+ # exit the whole plugin when 'enable: no' is set in 'python.d.conf'
540
if str(conf['enable']) is False:
541
fatal('disabled in configuration file.\n')
542
except (KeyError, TypeError):
@@ -552,9 +556,11 @@ def run():
556
disabled.append(k)
557
558
# parse passed command line arguments
555
- out = parse_cmdline(MODULES_DIR, *sys.argv)
556
- modules = out['modules']
557
- info("MODULES_DIR='" + MODULES_DIR + "', CONFIG_DIR='" + CONFIG_DIR + "', UPDATE_EVERY=" + str(UPDATE_EVERY) + ", ONLY_MODULES=" + str(out['modules']))
559
+ modules = parse_cmdline(MODULES_DIR, *sys.argv)
560
+ info("MODULES_DIR='" + MODULES_DIR +
561
+ "', CONFIG_DIR='" + CONFIG_DIR +
562
+ "', UPDATE_EVERY=" + str(UPDATE_EVERY) +
563
+ ", ONLY_MODULES=" + str(modules))
564
565
# run plugins
566
charts = PythonCharts(update_every, modules, MODULES_DIR, CONFIG_DIR + "python.d/", disabled)
python.d/python_modules/base.py
+4
-3
@@ -36,10 +36,11 @@ class BaseService(object):
36
'retries':0}
37
:param config: dict
38
"""
39
- self.update_every = int(config['update_every'])
40
- self.priority = int(config['priority'])
41
- self.retries = int(config['retries'])
39
+ self.update_every = int(config.pop('update_every'))
40
+ self.priority = int(config.pop('priority'))
41
+ self.retries = int(config.pop('retries'))
42
self.retries_left = self.retries
43
+ self.configuration = config
44
45
def create_timetable(self, freq=None):
46
"""