]> arthur.barton.de Git - netdata.git/commitdiff
More code cleanup
authorpaulfantom <paulfantom@gmail.com>
Sun, 19 Jun 2016 13:37:43 +0000 (15:37 +0200)
committerpaulfantom <paulfantom@gmail.com>
Sun, 19 Jun 2016 13:37:43 +0000 (15:37 +0200)
plugins.d/python.d.plugin
python.d/example.chart.py
python.d/mysql.chart.py
python.d/python_modules/base.py

index 6b62278666a99a30758786aa5f9959531cd2f1c0..11109c982da0d78cf069d3c6eeedd25ffed00a0e 100755 (executable)
@@ -144,8 +144,8 @@ class PythonCharts(object):
                     mod.config = {None: {}}
                     for var in BASE_CONFIG:
                         try:
-                            mod.config[None][var] = getattr(var, mod)
-                        except Exception:
+                            mod.config[None][var] = getattr(mod, var)
+                        except AttributeError:
                             mod.config[None][var] = BASE_CONFIG[var]
         return modules
 
@@ -361,7 +361,6 @@ def run():
     if config_dir[-1] != '/':
         config_dir += '/'
     configfile = config_dir + "python.d.conf"
-    print(config_dir)
 
     try:
         conf = read_config(configfile)
@@ -395,7 +394,7 @@ def run():
             if v is False:
                 disabled.append(k)
     except FileNotFoundError:
-        modules_conf = config_dir
+        modules_conf = config_dir + "python.d/"
         modules_dir = main_dir.replace("plugins.d", "python.d")
 
     # directories should end with '/'
index 34fd232665c5ef9a5e37d62d7325aa618a0972e7..1f38e28e695079cc302562944de27e1f19500c30 100644 (file)
@@ -1,11 +1,10 @@
 # Description: example netdata python.d plugin
 # Author: Pawel Krupa (paulfantom)
 
-NAME = "example.chart.py"
-import sys
 import random
 from base import BaseService
 
+NAME = "example.chart.py"
 # default module values
 update_every = 3
 priority = 90000
@@ -13,7 +12,7 @@ retries = 7
 
 
 class Service(BaseService):
-    def __init__(self,configuration=None,name=None):
+    def __init__(self, configuration=None, name=None):
         super().__init__(configuration=configuration)
 
     def check(self):
@@ -24,7 +23,7 @@ class Service(BaseService):
         print("DIMENSION random1 '' absolute 1 1")
         return True
     
-    def update(self,interval):
+    def update(self, interval):
         print("BEGIN example.python_random "+str(interval))
         print("SET random1 = "+str(random.randint(0,100)))
         print("END")
index 04ccd4c4637be4b0f530d46d78e3d995fad43488..55be7551cb6fb4f77ff7f15982764f74953c9336 100644 (file)
@@ -1,8 +1,8 @@
 # Description: MySQL netdata python.d plugin
 # Author: Pawel Krupa (paulfantom)
 
-NAME = "mysql.chart.py"
 import sys
+NAME = "mysql.chart.py"
 
 # import 3rd party library to handle MySQL communication
 try:
@@ -20,7 +20,7 @@ except ImportError:
 
 from base import BaseService
 
-# default configuration (overriden by python.d.plugin)
+# default configuration (overridden by python.d.plugin)
 # FIXME change password
 config = {
     'local': {
@@ -41,19 +41,19 @@ retries = 7
 # query executed on MySQL server
 QUERY = "SHOW GLOBAL STATUS"
 
-# charts order (can be overriden if you want less charts, or different order)
-ORDER = ['net', 
-         'queries', 
-         'handlers', 
-         'table_locks', 
-         'join_issues', 
-         'sort_issues', 
-         'tmp', 
-         'connections', 
-         'binlog_cache', 
-         'threads', 
-         'thread_cache_misses', 
-         'innodb_io', 
+# charts order (can be overridden if you want less charts, or different order)
+ORDER = ['net',
+         'queries',
+         'handlers',
+         'table_locks',
+         'join_issues',
+         'sort_issues',
+         'tmp',
+         'connections',
+         'binlog_cache',
+         'threads',
+         'thread_cache_misses',
+         'innodb_io',
          'innodb_io_ops',
          'innodb_io_pending_ops',
          'innodb_log',
@@ -83,7 +83,7 @@ ORDER = ['net',
 #    'chart_name_in_netdata': (
 #        "parameters defining chart (passed to CHART statement)",
 #        [ # dimensions (lines) definitions
-#            ("dimension_name", "dimension parameters (passed to DIMENSION statement)", "additional parameter (optional)")
+#            ("dimension_name", "dimension parameters (passed to DIMENSION statement)")
 #        ])
 #    }
 
@@ -377,8 +377,8 @@ class Service(BaseService):
                                               connect_timeout=self.configuration['update_every'])
         except Exception as e:
             self.error(NAME + " has problem connecting to server:", e)
-            raise RuntimeError #stop creating module, need to catch it in supervisor
-    
+            raise RuntimeError  # stop creating module, need to catch it in supervisor
+
     def _get_data(self):
         if self.connection is None:
             self._connect()
@@ -391,7 +391,7 @@ class Service(BaseService):
             self.connection.close()
             self.connection = None
             return None
-        
+
         return dict(raw_data)
 
     def check(self):
@@ -407,7 +407,7 @@ class Service(BaseService):
             self.defs[name] = []
             for line in CHARTS[name][1]:
                 self.defs[name].append(line[0])
-   
+
         idx = 0
         data = self._get_data()
         for name in ORDER:
@@ -418,7 +418,7 @@ class Service(BaseService):
                      str(self.priority + idx) + " " + \
                      str(self.update_every)
             content = ""
-            # check if server has this datapoint
+            # check if server has this data point
             for line in CHARTS[name][1]:
                 if line[0] in data:
                      content += "DIMENSION " + line[0] + " " + line[1] + "\n"
@@ -426,17 +426,17 @@ class Service(BaseService):
                 print(header)
                 print(content)
                 idx += 1
-    
+
         if idx == 0:
             return False
         return True
 
-    def update(self,interval):
+    def update(self, interval):
         data = self._get_data()
         if data is None:
             return False
         try:
-            data['Thread cache misses'] = int( int(data['Threads_created']) * 10000 / int(data['Connections']))
+            data['Thread cache misses'] = int(int(data['Threads_created']) * 10000 / int(data['Connections']))
         except Exception:
             pass
         for chart, dimensions in self.defs.items():
@@ -449,5 +449,5 @@ class Service(BaseService):
                     pass
             if len(lines) > 0:
                 print(header + lines + "END")
-        
+
         return True
index 67505a33876b3067525cebfacc2da930f9bec77a..14c53070675167789665fb3dfa3d4f47ad72fb80 100644 (file)
@@ -38,16 +38,13 @@ class BaseService(object):
         sys.stderr.flush()
 
     def check(self):
-        # TODO notify about not overridden function
-        self.error("Where is your check()?")
+        self.error("Service " + str(self.__name__) + "doesn't implement check() function")
         return False
 
     def create(self):
-        # TODO notify about not overridden function
-        self.error("Where is your create()?")
+        self.error("Service " + str(self.__name__) + "doesn't implement create() function?")
         return False
 
     def update(self):
-        # TODO notify about not overridden function
-        self.error("Where is your update()?")
+        self.error("Service " + str(self.__name__) + "doesn't implement update() function")
         return False