@cryptotaxi247 / netdata-1 / commits / f8fb750e5

first run

paulfantom committed Jun 18, 2016 at 12:26 UTC f8fb750e5a96370c1f8c49feff1378b95f9081f0
3 files changed +21 -23
plugins.d/python.d.plugin
+11 -13
@@ -41,10 +41,11 @@ class PythonCharts(object):
41 loaded_modules = [ m for m in modules if m.__name__ not in modules_disabled ]
42
43 # load configuration files
44 - confiured_modules = self._load_configs(loaded_modules)
44 + configured_modules = self._load_configs(loaded_modules)
45
46 # good economy and prosperity:
47 self.jobs = self._create_jobs(configured_modules)
48 + debug(self.jobs)
49
50
51 def _create_jobs(self,modules):
@@ -120,7 +121,7 @@ class PythonCharts(object):
121 try:
122 setattr(mod,
123 'config',
123 - self._parse_config(mod,read_config(config_file))
124 + self._parse_config(mod,read_config(configfile)))
125 except Exception as e:
126 debug("something went wrong while loading configuration",e)
127 else:
@@ -146,16 +147,13 @@ class PythonCharts(object):
147 defaults[key] = BASE_CONFIG[key]
148
149 # assign variables needed by supervisor to every job configuration
149 - out = {}
150 for name in config:
151 - out[name] = {}
151 for key in BASE_CONFIG:
152 if key not in config[name]:
154 - out[name][key] = defaults[key]
155 - except (KeyError,ValueError):
156 -
153 + config[name][key] = defaults[key]
154 +
155 # return dictionary of jobs where every job has BASE_CONFIG variables
158 - return out
156 + return config
157
158 def _stop(self, job, reason=None): #FIXME test if Service has __name__
159 # modifies self.jobs
@@ -164,23 +162,23 @@ class PythonCharts(object):
162 return
163 elif reason[:3] == "no ":
164 debug("chart '" +
167 - job.__name__,
165 + job.execution_name,
166 "' does not seem to have " +
167 reason[3:] +
168 "() function. Disabling it.")
169 elif reason[:7] == "failed ":
170 debug("chart '" +
173 - job.__name__ + "' " +
171 + job.execution_name + "' " +
172 reason[7:] +
173 "() function reports failure.")
174 elif reason[:13] == "configuration":
177 - debug(job.__name__,
175 + debug(job.execution_name,
176 "configuration file '" +
177 self.configs +
180 - job.__name__ +
178 + job.execution_name +
179 ".conf' not found. Using defaults.")
180 elif reason[:11] == "misbehaving":
183 - debug(job.__name__, "is "+reason)
181 + debug(job.execution_name, "is "+reason)
182
183 def check(self):
184 # try to execute check() on every job
python.d/mysql.chart.py
+8 -9
@@ -23,16 +23,16 @@ from base import BaseService
23
24 # default configuration (overriden by python.d.plugin)
25 # FIXME change password
26 -config = [
27 - {
28 - 'name' : 'local',
26 +config = {
27 + 'local': {
28 'user' : 'root',
29 'password' : 'a',
30 'socket' : '/var/run/mysqld/mysqld.sock',
31 'update_every' : 3,
33 - 'retries' : 4
32 + 'retries' : 4,
33 + 'priority' : 100
34 }
35 -]
35 +}
36
37 # default module values (can be overridden per job in `config`)
38 update_every = 3
@@ -335,11 +335,11 @@ CHARTS = {
335
336 class Service(BaseService):
337 def __init__(self,configuration=None,name=None):
338 - super().__init__(configuration)
338 + super().__init__(configuration=configuration)
339 + self.name = name
340 self.configuration = self._parse_config(configuration)
341 self.connection = None
342 self.defs = {}
342 - self.name = name
343
344 def _parse_config(self,configuration):
345 # parse configuration to collect data from mysql server
@@ -405,7 +405,6 @@ class Service(BaseService):
405
406 def create(self):
407 for name in ORDER:
408 - print(name)
408 self.defs[name] = []
409 for line in CHARTS[name][1]:
410 self.defs[name].append(line[0])
@@ -456,7 +455,7 @@ class Service(BaseService):
455
456 #FIXME debug only:
457 if __name__ == "__main__":
459 - my = Service(config[0],'loc')
458 + my = Service(config['local'],'loc')
459 my.check()
460 my.create()
461 my.update(1)
python.d/python_modules/base.py
+2 -1
@@ -2,12 +2,13 @@
2 # Author: Pawel Krupa (paulfantom)
3
4 from time import time
5 +import sys
6
7
8 class BaseService(object):
9 def __init__(self,name=None,configuration=None):
10 + print(configuration)
11 if configuration is None:
10 - # use defaults
12 self.error("BaseService: no configuration parameters supplied. Cannot create Service.")
13 raise RuntimeError
14 else: