]> arthur.barton.de Git - netdata.git/commitdiff
enabled option "trace" to get python traces on errors
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 12 Nov 2016 12:17:01 +0000 (14:17 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 12 Nov 2016 12:17:01 +0000 (14:17 +0200)
plugins.d/python.d.plugin
python.d/python_modules/msg.py

index 83fdd17c8f59a239a2cd70f151fb95f896f51a23..05d23b9ae09f98ab8b165d929b3214fe6f2d9060 100755 (executable)
@@ -28,6 +28,7 @@ sys.path.append(MODULES_DIR + "python_modules")
 
 PROGRAM = os.path.basename(__file__).replace(".plugin", "")
 DEBUG_FLAG = False
+TRACE_FLAG = False
 OVERRIDE_UPDATE_EVERY = False
 
 # -----------------------------------------------------------------------------
@@ -435,7 +436,7 @@ def parse_cmdline(directory, *commands):
     :param commands: list of str
     :return: dict
     """
-    global DEBUG_FLAG
+    global DEBUG_FLAG, TRACE_FLAG
     global OVERRIDE_UPDATE_EVERY
     global BASE_CONFIG
 
@@ -447,6 +448,8 @@ def parse_cmdline(directory, *commands):
         elif cmd == "debug" or cmd == "all":
             DEBUG_FLAG = True
             # redirect stderr to stdout?
+        elif cmd == "trace" or cmd == "all":
+            TRACE_FLAG = True
         elif os.path.isfile(directory + cmd + ".chart.py") or os.path.isfile(directory + cmd):
             #DEBUG_FLAG = True
             mods.append(cmd.replace(".chart.py", ""))
@@ -470,7 +473,7 @@ def run():
     """
     Main program.
     """
-    global DEBUG_FLAG, BASE_CONFIG
+    global DEBUG_FLAG, TRACE_FLAG, BASE_CONFIG
 
     # read configuration file
     disabled = []
@@ -488,23 +491,33 @@ def run():
                 msg.fatal('disabled in configuration file.\n')
         except (KeyError, TypeError):
             pass
+
         try:
             for param in BASE_CONFIG:
                 BASE_CONFIG[param] = conf[param]
         except (KeyError, TypeError):
             pass  # use default update_every from NETDATA_UPDATE_EVERY
+
         try:
             DEBUG_FLAG = conf['debug']
         except (KeyError, TypeError):
             pass
+
+        try:
+            TRACE_FLAG = conf['trace']
+        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
@@ -514,6 +527,7 @@ def run():
     # parse passed command line arguments
     modules = parse_cmdline(MODULES_DIR, *sys.argv)
     msg.DEBUG_FLAG = DEBUG_FLAG
+    msg.TRACE_FLAG = TRACE_FLAG
     msg.LOG_THROTTLE = log_throttle
     msg.LOG_INTERVAL = log_interval
     msg.LOG_COUNTER = 0
index acce1d0f3c7e526dcddbceb66e7b46a7aad7a69e..b835c940459c2836ae1c3c96e8d3624f58766656 100644 (file)
@@ -1,10 +1,12 @@
 # -*- coding: utf-8 -*-
 # Description: logging for netdata python.d modules
 
+import traceback
 import sys
 from time import time, strftime
 
 DEBUG_FLAG = False
+TRACE_FLAG = False
 PROGRAM = ""
 LOG_COUNTER = 0
 LOG_THROTTLE = 10000 # has to be too big during init
@@ -51,6 +53,9 @@ def log_msg(msg_type, *args):
         LOG_NEXT_CHECK = now - (now % LOG_INTERVAL) + LOG_INTERVAL
         LOG_COUNTER = 0
 
+    if TRACE_FLAG:
+        if msg_type == "FATAL" or msg_type == "ERROR" or msg_type == "ALERT":
+            traceback.print_exc()
 
 
 def debug(*args):