]> arthur.barton.de Git - netdata.git/blobdiff - plugins.d/python.d.plugin
python logging fixes
[netdata.git] / plugins.d / python.d.plugin
index 45c85c804716613a528938e351a99a6134143e51..9fe4373ce818d993df19149b3738b683a8604fb3 100755 (executable)
@@ -292,8 +292,8 @@ class PythonCharts(object):
         if job.name is not None and len(job.name) != 0:
             prefix += "/" + job.name
         try:
+            msg.error("DISABLED:", prefix)
             self.jobs.remove(job)
-            msg.info("Disabled", prefix)
         except Exception as e:
             msg.debug("This shouldn't happen. NO " + prefix + " IN LIST:" + str(self.jobs) + " ERROR: " + str(e))
 
@@ -335,25 +335,26 @@ class PythonCharts(object):
                     msg.error(job.chart_name, "check function failed.")
                     self._stop(job)
                 else:
-                    msg.debug(job.chart_name, "check succeeded")
+                    msg.info("CHECKED OK:", job.chart_name)
                     i += 1
                     try:
                         if job.override_name is not None:
                             new_name = job.__module__ + '_' + job.override_name
                             if new_name in overridden:
-                                msg.error(job.chart_name + " already exists. Stopping '" + job.name + "'")
+                                msg.info("DROPPED:", job.name, ", job '" + job.override_name + "' is already served by another job.")
                                 self._stop(job)
                                 i -= 1
                             else:
                                 job.name = job.override_name
-                                msg.debug(job.chart_name + " changing chart name to: '" + new_name + "'")
+                                msg.info("RENAMED:", new_name, ", from " + job.chart_name)
                                 job.chart_name = new_name
                                 overridden.append(job.chart_name)
                     except Exception:
                         pass
-            except AttributeError:
+            except AttributeError as e:
                 self._stop(job)
-                msg.error(job.chart_name, "cannot find check() function.")
+                msg.error(job.chart_name, "cannot find check() function or it thrown unhandled exception.")
+                msg.debug(str(e))
             except (UnboundLocalError, Exception) as e:
                 msg.error(job.chart_name, str(e))
                 self._stop(job)
@@ -389,7 +390,7 @@ class PythonCharts(object):
                     # sys.stdout.flush()
                     i += 1
             except AttributeError:
-                msg.error(job.chart_name, "cannot find create() function.")
+                msg.error(job.chart_name, "cannot find create() function or it thrown unhandled exception.")
                 self._stop(job)
             except (UnboundLocalError, Exception) as e:
                 msg.error(job.chart_name, str(e))
@@ -476,6 +477,8 @@ def run():
     configfile = CONFIG_DIR + "python.d.conf"
     msg.PROGRAM = PROGRAM
     msg.info("reading configuration file:", configfile)
+    log_throttle = 200
+    log_interval = 3600
 
     conf = read_config(configfile)
     if conf is not None:
@@ -494,6 +497,14 @@ def run():
             DEBUG_FLAG = conf['debug']
         except (KeyError, TypeError):
             pass
+        try:
+            log_throttle = conf['logs_per_interval']
+        except (KeyError, TypeError):
+            pass
+        try:
+            log_interval = conf['log_interval']
+        except (KeyError, TypeError):
+            pass
         for k, v in conf.items():
             if k in ("update_every", "debug", "enabled"):
                 continue
@@ -503,6 +514,10 @@ def run():
     # parse passed command line arguments
     modules = parse_cmdline(MODULES_DIR, *sys.argv)
     msg.DEBUG_FLAG = DEBUG_FLAG
+    msg.LOG_THROTTLE = log_throttle
+    msg.LOG_INTERVAL = log_interval
+    msg.LOG_COUNTER = 0
+    msg.LOG_NEXT_CHECK = 0
     msg.info("MODULES_DIR='" + MODULES_DIR +
              "', CONFIG_DIR='" + CONFIG_DIR +
              "', UPDATE_EVERY=" + str(BASE_CONFIG['update_every']) +