]> arthur.barton.de Git - netdata.git/commitdiff
better debug messages. don't require specific python version
authorpaulfantom <paulfantom@gmail.com>
Mon, 20 Jun 2016 07:46:48 +0000 (09:46 +0200)
committerpaulfantom <paulfantom@gmail.com>
Mon, 20 Jun 2016 07:46:48 +0000 (09:46 +0200)
plugins.d/python.d.plugin
python.d/example.chart.py
python.d/mysql.chart.py
python.d/python_modules/base.py

index 0f0997422e249a7abc10c6553deae944fe12b798..679094b8949a950b24160876f43db8ec7ed9a06c 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
 
 import os
 import sys
@@ -140,7 +140,7 @@ class PythonCharts(object):
                     continue
                 m = self._import_module(path + mod)
                 if m is not None:
-                    debug("loading chart: '" + path + mod + "'")
+                    debug("loading module: '" + path + mod + "'")
                     loaded.append(m)
         return loaded
 
@@ -155,7 +155,7 @@ class PythonCharts(object):
         for mod in modules:
             configfile = self.configs + mod.__name__ + ".conf"
             if os.path.isfile(configfile):
-                debug("loading chart options: '" + configfile + "'")
+                debug("loading module configuration: '" + configfile + "'")
                 try:
                     setattr(mod,
                             'config',
@@ -248,10 +248,10 @@ class PythonCharts(object):
                           str(e))
                     return None
                 else:
-                    # set execution_name (needed to plot run time graphs)
-                    job.execution_name = module.__name__
+                    # set chart_name (needed to plot run time graphs)
+                    job.chart_name = module.__name__
                     if name is not None:
-                        job.execution_name += "_" + name
+                        job.chart_name += "_" + name
                 jobs.append(job)
 
         return [j for j in jobs if j is not None]
@@ -263,28 +263,31 @@ class PythonCharts(object):
         :param job: object
         :param reason: str
         """
+        prefix = ""
+        if job.name is not None:
+            prefix = "'" + job.name + "' in "
+
+        prefix += "'" + job.__module__ + "' "
         self.jobs.remove(job)
         if reason is None:
             return
         elif reason[:3] == "no ":
-            debug("chart '" +
-                  job.execution_name,
-                  "' does not seem to have " +
+            debug(prefix +
+                  "does not seem to have " +
                   reason[3:] +
                   "() function. Disabling it.")
         elif reason[:7] == "failed ":
-            debug("chart '" +
-                  job.execution_name + "' " +
+            debug(prefix +
                   reason[7:] +
                   "() function reports failure.")
         elif reason[:13] == "configuration":
-            debug(job.execution_name,
+            debug(prefix +
                   "configuration file '" +
                   self.configs +
-                  job.execution_name +
+                  job.__module__ +
                   ".conf' not found. Using defaults.")
         elif reason[:11] == "misbehaving":
-            debug(job.execution_name, "is " + reason)
+            debug(prefix + "is " + reason)
 
     def check(self):
         """
@@ -313,7 +316,7 @@ class PythonCharts(object):
                 if not job.create():
                     self._stop(job, "failed create")
                 else:
-                    chart = job.execution_name
+                    chart = job.chart_name
                     sys.stdout.write(
                         "CHART netdata.plugin_pythond_" +
                         chart +
@@ -363,7 +366,7 @@ class PythonCharts(object):
         t_end = time.time()
         job.timetable['next'] = t_end - (t_end % job.timetable['freq']) + job.timetable['freq']
         # draw performance graph
-        sys.stdout.write("BEGIN netdata.plugin_pythond_" + job.execution_name + " " + str(since_last) + '\n')
+        sys.stdout.write("BEGIN netdata.plugin_pythond_" + job.chart_name + " " + str(since_last) + '\n')
         sys.stdout.write("SET run_time = " + str(int((t_end - t_start) * 1000)) + '\n')
         sys.stdout.write("END\n")
         sys.stdout.flush()
index cf93d41b7342bf258934e06bd0b0e372efbbd9e5..ec97415c2c13d15edf3a6e50573f1c35f62511bc 100644 (file)
@@ -13,7 +13,7 @@ retries = 7
 
 class Service(BaseService):
     def __init__(self, configuration=None, name=None):
-        super(self.__class__,self).__init__(configuration=configuration)
+        super(self.__class__,self).__init__(configuration=configuration, name=name)
 
     def check(self):
         return True
index 7466533c27b815da9bd6edc03b81ff39f6fad654..e9df071e0a425300bf9ab2722fa017f83b1e3ab5 100644 (file)
@@ -336,8 +336,7 @@ CHARTS = {
 
 class Service(BaseService):
     def __init__(self, configuration=None, name=None):
-        super(self.__class__, self).__init__(configuration=configuration)
-        self.name = name
+        super(self.__class__, self).__init__(configuration=configuration, name=name)
         self.configuration = self._parse_config(configuration)
         self.connection = None
         self.defs = {}
index a168a560910ad8973f89de15d66778a8701a4d4e..a154d53381e54226b9cad75067a3db9fc639a1b0 100644 (file)
@@ -16,6 +16,7 @@ class BaseService(object):
         :param configuration: dict
         :param name: str
         """
+        self.name = name
         if configuration is None:
             self.error("BaseService: no configuration parameters supplied. Cannot create Service.")
             raise RuntimeError
@@ -23,7 +24,7 @@ class BaseService(object):
             self._extract_base_config(configuration)
             self.timetable = {}
             self.create_timetable()
-            self.execution_name = ""
+            self.chart_name = ""
 
     def _extract_base_config(self, config):
         """