Module: check_mk
Branch: master
Commit: 462e7ea3cacfced7a56f613765fb023ec6762bb0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=462e7ea3cacfce…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Sep 28 09:02:21 2017 +0200
EC: Readded (now real) debug logging for thread locking
Change-Id: I04b467214459209cb8fe5deb552aca12e7199487
---
bin/mkeventd | 46 ++++++++++++++++++++++++++++++++++++++++----
web/plugins/wato/mkeventd.py | 3 +++
2 files changed, 45 insertions(+), 4 deletions(-)
diff --git a/bin/mkeventd b/bin/mkeventd
index d4d8a34..e42d132 100755
--- a/bin/mkeventd
+++ b/bin/mkeventd
@@ -291,6 +291,40 @@ filter_operators = {
# | Various helper functions |
# '----------------------------------------------------------------------'
+class ECLock(object):
+ def __init__(self, ident):
+ super(ECLock, self).__init__()
+ self._lock = threading.Lock()
+ self.logger = logger.getChild("lock.%s" % ident)
+
+
+ def acquire(self, blocking=True):
+ self.logger.debug("[%s] Trying to acquire lock",
threading.current_thread().name)
+
+ ret = self._lock.acquire(blocking)
+ if ret == True:
+ self.logger.debug("[%s] Acquired lock",
threading.current_thread().name)
+ else:
+ self.logger.debug("[%s] Non-blocking aquire failed",
threading.current_thread().name)
+
+ return ret
+
+
+ def release(self):
+ self.logger.debug("[%s] Releasing lock",
threading.current_thread().name)
+ self._lock.release()
+
+
+ def __enter__(self):
+ self.acquire()
+
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ self.release()
+ return False # Do not swallow exceptions
+
+
+
def bail_out(reason):
logger.error("FATAL ERROR: %s" % reason)
sys.exit(1)
@@ -1129,7 +1163,7 @@ def get_logfile_timespan(path):
# '----------------------------------------------------------------------'
class Perfcounters(object):
def __init__(self):
- self._lock = thread.allocate_lock()
+ self._lock = ECLock("perfcounters")
# Event counters
self._counters = {
"messages": 0,
@@ -4700,6 +4734,7 @@ def load_configuration():
"cmk.mkeventd.EventServer": log_level,
"cmk.mkeventd.EventStatus": log_level,
"cmk.mkeventd.StatusServer": log_level,
+ "cmk.mkeventd.lock": log_level,
}
logger.setLevel(g_config["log_level"]["cmk.mkeventd"])
@@ -4707,6 +4742,9 @@ def load_configuration():
logger.getChild("EventStatus").setLevel(g_config["log_level"]["cmk.mkeventd.EventStatus"])
logger.getChild("StatusServer").setLevel(g_config["log_level"]["cmk.mkeventd.StatusServer"])
+ if "cmk.mkeventd.lock" in g_config["log_level"]:
+
logger.getChild("lock").setLevel(g_config["log_level"]["cmk.mkeventd.lock"])
+
# Configure the auto deleting indexes in the DB when mongodb is enabled
if g_config['archive_mode'] == 'mongodb':
update_mongodb_indexes()
@@ -4796,9 +4834,9 @@ The following paths are used by the Event Console:
# '----------------------------------------------------------------------'
# Create locks for global data structures
-lock_eventstatus = thread.allocate_lock()
-lock_configuration = thread.allocate_lock()
-lock_logging = thread.allocate_lock()
+lock_eventstatus = ECLock("eventstatus")
+lock_configuration = ECLock("configuration")
+lock_logging = ECLock("history")
if __name__ == "__main__":
os.unsetenv("LANG")
diff --git a/web/plugins/wato/mkeventd.py b/web/plugins/wato/mkeventd.py
index 01b6680..7c294c4 100644
--- a/web/plugins/wato/mkeventd.py
+++ b/web/plugins/wato/mkeventd.py
@@ -2770,6 +2770,9 @@ if mkeventd_enabled:
_("Log level for managing already created events")),
("cmk.mkeventd.StatusServer", _("Status queries"),
_("Log level for handling of incoming queries to the status
socket")),
+ ("cmk.mkeventd.lock", _("Locking"),
+ _("Log level for the locking mechanics. Setting this to debug will
enable "
+ "log entries for each lock/unlock action.")),
]:
elements.append(
(component, DropdownChoice(