more debug
paulfantom committed
Jun 21, 2016 at 17:28 UTC
661f5455e8e2d8571ad4612ee7d2b757ee461eaa
2 files changed
+31
-23
plugins.d/python.d.plugin
+30
-21
@@ -31,50 +31,51 @@ OVERRIDE_UPDATE_EVERY = False
31
32
# -----------------------------------------------------------------------------
33
# logging functions
34
-def debug(*args):
34
+def log_msg(msg_type, *args):
35
"""
36
Print message on stderr.
37
+ :param msg_type: str
38
"""
38
- if not DEBUG_FLAG:
39
- return
40
- sys.stderr.write(PROGRAM + " DEBUG :")
39
+ sys.stderr.write(PROGRAM)
40
+ sys.stderr.write(" ")
41
+ sys.stderr.write(msg_type)
42
+ sys.stderr.write(": ")
43
for i in args:
42
- sys.stderr.write(" " + str(i))
44
+ sys.stderr.write(" ")
45
+ sys.stderr.write(str(i))
46
sys.stderr.write("\n")
47
sys.stderr.flush()
48
49
50
+def debug(*args):
51
+ """
52
+ Print debug message on stderr.
53
+ """
54
+ if not DEBUG_FLAG:
55
+ return
56
+
57
+ log_msg("DEBUG", *args)
58
+
59
+
60
def error(*args):
61
"""
62
Print message on stderr.
63
"""
51
- sys.stderr.write(PROGRAM + " ERROR :")
52
- for i in args:
53
- sys.stderr.write(" " + str(i))
54
- sys.stderr.write("\n")
55
- sys.stderr.flush()
64
+ log_msg("ERROR", *args)
65
66
67
def info(*args):
68
"""
69
Print message on stderr.
70
"""
62
- sys.stderr.write(PROGRAM + " INFO :")
63
- for i in args:
64
- sys.stderr.write(" " + str(i))
65
- sys.stderr.write("\n")
66
- sys.stderr.flush()
71
+ log_msg("INFO", *args)
72
73
74
def fatal(*args):
75
"""
76
Print message on stderr and exit.
77
"""
73
- sys.stderr.write(PROGRAM + " FATAL :")
74
- for i in args:
75
- sys.stderr.write(" " + str(i))
76
- sys.stderr.write("\n")
77
- sys.stderr.flush()
78
+ log_msg("FATAL", *args)
79
sys.stdout.write('DISABLE\n')
80
sys.exit(1)
81
@@ -228,6 +229,7 @@ class PythonCharts(object):
229
error(mod.__name__ + ": configuration file '" + configfile + "' not found. Using defaults.")
230
# set config if not found
231
if not hasattr(mod, 'config'):
232
+ debug(mod.__name__ + ": setting configuration for only one job")
233
mod.config = {None: {}}
234
for var in BASE_CONFIG:
235
try:
@@ -253,6 +255,7 @@ class PythonCharts(object):
255
# get default values
256
defaults = {}
257
for key in BASE_CONFIG:
258
+ debug(module.__name__ + ": reading configuration")
259
try:
260
# get defaults from module config
261
defaults[key] = int(config.pop(key))
@@ -381,6 +384,7 @@ class PythonCharts(object):
384
if not job.create():
385
self._stop(job, "failed create")
386
else:
387
+ debug("created charts for", job.chart_name)
388
chart = job.chart_name
389
sys.stdout.write(
390
"CHART netdata.plugin_pythond_" +
@@ -435,8 +439,10 @@ class PythonCharts(object):
439
t_end = time.time()
440
job.timetable['next'] = t_end - (t_end % job.timetable['freq']) + job.timetable['freq']
441
# draw performance graph
442
+ run_time = str(int((t_end - t_start) * 1000))
443
+ debug(job.chart_name, "updated in", run_time)
444
sys.stdout.write("BEGIN netdata.plugin_pythond_" + job.chart_name + " " + str(since_last) + '\n')
439
- sys.stdout.write("SET run_time = " + str(int((t_end - t_start) * 1000)) + '\n')
445
+ sys.stdout.write("SET run_time = " + run_time + '\n')
446
sys.stdout.write("END\n")
447
# sys.stdout.flush()
448
job.timetable['last'] = t_start
@@ -509,6 +515,7 @@ def parse_cmdline(directory, *commands):
515
try:
516
BASE_CONFIG['update_every'] = int(cmd)
517
OVERRIDE_UPDATE_EVERY = True
518
+ debug(PROGRAM, "overriding update interval to", str(int(cmd)))
519
except ValueError:
520
pass
521
@@ -527,6 +534,7 @@ def run():
534
# read configuration file
535
disabled = []
536
configfile = CONFIG_DIR + "python.d.conf"
537
+ debug(PROGRAM, "reading configuration file:", configfile)
538
539
conf = read_config(configfile)
540
if conf is not None:
@@ -559,6 +567,7 @@ def run():
567
", ONLY_MODULES=" + str(modules))
568
569
# run plugins
570
+ modules = ['nginx']
571
charts = PythonCharts(modules, MODULES_DIR, CONFIG_DIR + "python.d/", disabled)
572
charts.check()
573
charts.create()
python.d/mysql.chart.py
+1
-2
@@ -4,6 +4,7 @@
4
5
import os
6
import sys
7
+from base import BaseService
8
9
NAME = os.path.basename(__file__).replace(".chart.py", "")
10
@@ -23,8 +24,6 @@ except ImportError:
24
sys.stderr.write(NAME + ": You need to install MySQLdb or PyMySQL module to use mysql.chart.py plugin\n")
25
raise ImportError
26
26
-from base import BaseService
27
-
27
# default module values (can be overridden per job in `config`)
28
update_every = 3
29
priority = 90000