@cryptotaxi247 / netdata-1 / commits / 701a9968f

better debug messages. don't require specific python version

paulfantom committed Jun 20, 2016 at 09:46 UTC 701a9968f643dd2262ee3acd8c002624c4bcb830
4 files changed +23 -20
plugins.d/python.d.plugin
+19 -16
@@ -1,4 +1,4 @@
1 -#!/usr/bin/env python3
1 +#!/usr/bin/env python
2
3 import os
4 import sys
@@ -140,7 +140,7 @@ class PythonCharts(object):
140 continue
141 m = self._import_module(path + mod)
142 if m is not None:
143 - debug("loading chart: '" + path + mod + "'")
143 + debug("loading module: '" + path + mod + "'")
144 loaded.append(m)
145 return loaded
146
@@ -155,7 +155,7 @@ class PythonCharts(object):
155 for mod in modules:
156 configfile = self.configs + mod.__name__ + ".conf"
157 if os.path.isfile(configfile):
158 - debug("loading chart options: '" + configfile + "'")
158 + debug("loading module configuration: '" + configfile + "'")
159 try:
160 setattr(mod,
161 'config',
@@ -248,10 +248,10 @@ class PythonCharts(object):
248 str(e))
249 return None
250 else:
251 - # set execution_name (needed to plot run time graphs)
252 - job.execution_name = module.__name__
251 + # set chart_name (needed to plot run time graphs)
252 + job.chart_name = module.__name__
253 if name is not None:
254 - job.execution_name += "_" + name
254 + job.chart_name += "_" + name
255 jobs.append(job)
256
257 return [j for j in jobs if j is not None]
@@ -263,28 +263,31 @@ class PythonCharts(object):
263 :param job: object
264 :param reason: str
265 """
266 + prefix = ""
267 + if job.name is not None:
268 + prefix = "'" + job.name + "' in "
269 +
270 + prefix += "'" + job.__module__ + "' "
271 self.jobs.remove(job)
272 if reason is None:
273 return
274 elif reason[:3] == "no ":
270 - debug("chart '" +
271 - job.execution_name,
272 - "' does not seem to have " +
275 + debug(prefix +
276 + "does not seem to have " +
277 reason[3:] +
278 "() function. Disabling it.")
279 elif reason[:7] == "failed ":
276 - debug("chart '" +
277 - job.execution_name + "' " +
280 + debug(prefix +
281 reason[7:] +
282 "() function reports failure.")
283 elif reason[:13] == "configuration":
281 - debug(job.execution_name,
284 + debug(prefix +
285 "configuration file '" +
286 self.configs +
284 - job.execution_name +
287 + job.__module__ +
288 ".conf' not found. Using defaults.")
289 elif reason[:11] == "misbehaving":
287 - debug(job.execution_name, "is " + reason)
290 + debug(prefix + "is " + reason)
291
292 def check(self):
293 """
@@ -313,7 +316,7 @@ class PythonCharts(object):
316 if not job.create():
317 self._stop(job, "failed create")
318 else:
316 - chart = job.execution_name
319 + chart = job.chart_name
320 sys.stdout.write(
321 "CHART netdata.plugin_pythond_" +
322 chart +
@@ -363,7 +366,7 @@ class PythonCharts(object):
366 t_end = time.time()
367 job.timetable['next'] = t_end - (t_end % job.timetable['freq']) + job.timetable['freq']
368 # draw performance graph
366 - sys.stdout.write("BEGIN netdata.plugin_pythond_" + job.execution_name + " " + str(since_last) + '\n')
369 + sys.stdout.write("BEGIN netdata.plugin_pythond_" + job.chart_name + " " + str(since_last) + '\n')
370 sys.stdout.write("SET run_time = " + str(int((t_end - t_start) * 1000)) + '\n')
371 sys.stdout.write("END\n")
372 sys.stdout.flush()
python.d/example.chart.py
+1 -1
@@ -13,7 +13,7 @@ retries = 7
13
14 class Service(BaseService):
15 def __init__(self, configuration=None, name=None):
16 - super(self.__class__,self).__init__(configuration=configuration)
16 + super(self.__class__,self).__init__(configuration=configuration, name=name)
17
18 def check(self):
19 return True
python.d/mysql.chart.py
+1 -2
@@ -336,8 +336,7 @@ CHARTS = {
336
337 class Service(BaseService):
338 def __init__(self, configuration=None, name=None):
339 - super(self.__class__, self).__init__(configuration=configuration)
340 - self.name = name
339 + super(self.__class__, self).__init__(configuration=configuration, name=name)
340 self.configuration = self._parse_config(configuration)
341 self.connection = None
342 self.defs = {}
python.d/python_modules/base.py
+2 -1
@@ -16,6 +16,7 @@ class BaseService(object):
16 :param configuration: dict
17 :param name: str
18 """
19 + self.name = name
20 if configuration is None:
21 self.error("BaseService: no configuration parameters supplied. Cannot create Service.")
22 raise RuntimeError
@@ -23,7 +24,7 @@ class BaseService(object):
24 self._extract_base_config(configuration)
25 self.timetable = {}
26 self.create_timetable()
26 - self.execution_name = ""
27 + self.chart_name = ""
28
29 def _extract_base_config(self, config):
30 """