[checkmk-commits] Check_MK Git: check_mk: mkeventd: performance optimization for check_mkevents

git version control git at mathias-kettner.de
Sun Nov 18 11:04:12 CET 2012


Module: check_mk
Branch: master
Commit: c4496ac8931e30ed1729e0b34c0b86fd3fe2e497
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c4496ac8931e30ed1729e0b34c0b86fd3fe2e497

Author: Mathias Kettner <mk at mathias-kettner.de>
Date:   Sun Nov 18 11:04:06 2012 +0100

mkeventd: performance optimization for check_mkevents

---

 mkeventd/bin/mkeventd                    |   20 +++++++++++++++-----
 mkeventd/web/plugins/sidebar/mkeventd.py |    9 ++++++---
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/mkeventd/bin/mkeventd b/mkeventd/bin/mkeventd
index 6fdff42..0ad51e8 100755
--- a/mkeventd/bin/mkeventd
+++ b/mkeventd/bin/mkeventd
@@ -523,7 +523,7 @@ class Perfcounters:
         if counter not in self._times:
             self._times[counter] = ptime
         else:
-            weight = self._weights(counter)
+            weight = self._weights[counter]
             self._times[counter] *= weight
             self._times[counter] += (1.00 - weight) * ptime
 
@@ -1609,17 +1609,23 @@ class StatusServer:
             raise MKClientError("Invalid table %s, we only have 'events', 'history' and 'status'" % table)
 
         filters = []
+        only_host = None
         for line in headerlines:
             try:
                 header, argument = line.rstrip().split(":", 1)
                 argument = argument.strip()
                 if header == "Filter":
-                    filters.append(self.parse_filter(argument, columns))
+                    name, opfunc, argument = self.parse_filter(argument, columns)
+                    # Needed for later optimization
+                    if name == "event_host" and filter_operators['=']:
+                        only_host = argument
+                    filters.append((name, opfunc, argument))
+                    
             except Exception, e:
                 raise MKClientError("Invalid header line '%s': %s" % (line.rstrip(), e))
 
         if table == "events":
-            headers, list_rows = g_event_status.get_events()
+            headers, list_rows = g_event_status.get_events(only_host)
         elif table == "history":
             headers, list_rows = get_event_history(filters)
         else:
@@ -2007,9 +2013,12 @@ class EventStatus():
                 return
         raise MKClientError("No event with id %s" % event_id)
 
-    def get_events(self):
+    def get_events(self, only_host = None):
         result = []
         for event in self._events:
+            # A small optimization for check_mkevents
+            if only_host and event["host"] != only_host:
+                continue
             event_line = []
             for col_name, col_default in event_columns:
                 without_prefix = col_name[6:] # drop event_
@@ -2225,7 +2234,8 @@ def load_master_config():
         log("Replication: restored %d rules and %d actions from %s" %
             (len(config["rules"]), len(config["actions"]), path))
     except:
-        log("Replication: no previously saved master state available")
+        if is_replication_slave():
+            log("Replication: no previously saved master state available")
 
 
 def get_state_from_master():
diff --git a/mkeventd/web/plugins/sidebar/mkeventd.py b/mkeventd/web/plugins/sidebar/mkeventd.py
index 97b92f2..279e722 100644
--- a/mkeventd/web/plugins/sidebar/mkeventd.py
+++ b/mkeventd/web/plugins/sidebar/mkeventd.py
@@ -52,22 +52,25 @@ def render_mkeventd_performance():
 
     # Hit rate
     try:
-        write_line(_("Rule hit ratio"), "%.2f%%" % (
+        write_line(_("Rule hit ratio"), "%.2f %%" % (
            data["status_average_rule_hit_rate"] / 
            data["status_average_rule_trie_rate"] * 100))
     except: # division by zero
+        write_line(_("Rule hit ratio"), _("-.-- %"))
         pass
 
     # Time columns
     time_columns = [
         (_("Processing time per message"), "processing"),
-        (_("Processing time per client request"), "request"),
-        (_("Replication synchronization (avg)"), "sync"),
+        (_("Tiime per client request"), "request"),
+        (_("Replication synchronization"), "sync"),
     ]
     for title, name in time_columns:
         value = data.get("status_average_%s_time" % name)
         if value:
             write_line(title, "%.2f ms" % (value * 1000))
+        else:
+            write_line(title, _("-.-- ms"))
     html.write("</table>\n")
 
 if mkeventd_enabled:



More information about the checkmk-commits mailing list