# Enable / disable the whole python.d.plugin (all its modules)
enabled: yes
+# Prevent log flood
+# Define how many log messages can be written to log file in one log_interval
+logs_per_interval: 200
+
+# Define how long is one logging interval (in seconds)
+log_interval: 3600
+
# ----------------------------------------------------------------------
# Enable / Disable python.d.plugin modules
#
# apache: yes
# apache_cache: yes
# cpufreq: yes
+# dovecot: yes
example: no
# exim: yes
# hddtemp: yes
# ipfs: yes
+# memcached: yes
# mysql: yes
# nginx: yes
# phpfpm: yes
DEBUG_FLAG = conf['debug']
except (KeyError, TypeError):
pass
+ try:
+ log_counter = conf['logs_per_interval']
+ except (KeyError, TypeError):
+ log_counter = 200
+ try:
+ log_interval = conf['log_interval']
+ except (KeyError, TypeError):
+ log_interval = 3600
for k, v in conf.items():
if k in ("update_every", "debug", "enabled"):
continue
# parse passed command line arguments
modules = parse_cmdline(MODULES_DIR, *sys.argv)
msg.DEBUG_FLAG = DEBUG_FLAG
+ msg.LOG_COUNTER = log_counter
+ msg.LOG_INTERVAL = log_interval
msg.info("MODULES_DIR='" + MODULES_DIR +
"', CONFIG_DIR='" + CONFIG_DIR +
"', UPDATE_EVERY=" + str(BASE_CONFIG['update_every']) +
# Description: logging for netdata python.d modules
import sys
+from time import time
DEBUG_FLAG = False
PROGRAM = ""
+LOG_COUNTER = 2
+LOG_INTERVAL = 5
+NEXT_CHECK = 0
+
+WRITE = sys.stderr.write
+FLUSH = sys.stderr.flush
def log_msg(msg_type, *args):
Print message on stderr.
:param msg_type: str
"""
- msg = "%s %s: %s" % (PROGRAM, str(msg_type), " ".join(args))
+ global LOG_COUNTER
+ if not DEBUG_FLAG:
+ LOG_COUNTER -= 1
+ now = time()
+ if LOG_COUNTER >= 0:
+ msg = "%s %s: %s" % (PROGRAM, str(msg_type), " ".join(args))
+ WRITE(msg + "\n")
+ FLUSH()
- sys.stderr.write(msg + "\n")
- sys.stderr.flush()
+ global NEXT_CHECK
+ if NEXT_CHECK <= now:
+ NEXT_CHECK = now - (now % LOG_INTERVAL) + LOG_INTERVAL
+ if LOG_COUNTER < 0:
+ msg = "Prevented %s log messages from displaying" % str(0 - LOG_COUNTER)
+ WRITE(msg + "\n")
+ FLUSH()
def debug(*args):