summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2016-11-12 14:17:01 +0200
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2016-11-12 14:17:01 +0200
commita8204a0e864b4e0226ee07243adeb61f007fedf1 (patch)
tree243c3e066bd5b5581a138478ba41bbcbb3d28de2
parent56ec680880032bc9e8dcfb32bb163a1e783a6a59 (diff)
enabled option "trace" to get python traces on errors
-rwxr-xr-xplugins.d/python.d.plugin18
-rw-r--r--python.d/python_modules/msg.py5
2 files changed, 21 insertions, 2 deletions
diff --git a/plugins.d/python.d.plugin b/plugins.d/python.d.plugin
index 83fdd17c8f..05d23b9ae0 100755
--- a/plugins.d/python.d.plugin
+++ b/plugins.d/python.d.plugin
@@ -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
diff --git a/python.d/python_modules/msg.py b/python.d/python_modules/msg.py
index acce1d0f3c..b835c94045 100644
--- a/python.d/python_modules/msg.py
+++ b/python.d/python_modules/msg.py
@@ -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):