Module: check_mk
Branch: master
Commit: c4d1a4fd6122436fbc7c30f3f4b65f30678000be
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c4d1a4fd612243…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Sep 27 11:41:59 2017 +0200
5212 FIX check_mkevents: Improved performance
The performance of the check check_mkevents has been improved. This
check is used when you configure the WATO rule "Check event state in Event Console".
Change-Id: Ib8b5d24b5528f69c4c1df4df51ba9cf4ec77d32e
---
.werks/5212 | 11 +++++++++++
active_checks/check_mkevents.cc | 14 +++++---------
bin/mkeventd | 16 +++++++++++-----
3 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/.werks/5212 b/.werks/5212
new file mode 100644
index 0000000..3a3e882
--- /dev/null
+++ b/.werks/5212
@@ -0,0 +1,11 @@
+Title: check_mkevents: Improved performance
+Level: 1
+Component: ec
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1506505155
+Class: fix
+
+The performance of the check check_mkevents has been improved. This
+check is used when you configure the WATO rule "Check event state in Event Console".
diff --git a/active_checks/check_mkevents.cc b/active_checks/check_mkevents.cc
index e4986ef..3155fad 100644
--- a/active_checks/check_mkevents.cc
+++ b/active_checks/check_mkevents.cc
@@ -97,15 +97,12 @@ void usage() {
" HOST may be a hostname, and IP address or hostname/IP-address.");
}
-string prepare_hostname_regex(const char *s) {
+string prepare_host_match_list(const char *s) {
const char *scan = s;
string result;
while (*scan != 0) {
- if (strchr(R"([](){}^$.*+?|\)", *scan) != nullptr) {
- result += R"(\)";
- result += *scan;
- } else if (*scan == '/') {
- result += "|";
+ if (*scan == '/') {
+ result += " ";
} else {
result += *scan;
}
@@ -228,9 +225,8 @@ int main(int argc, char **argv) {
string query_message;
query_message += "GET events\nFilter: event_host ";
if (strchr(host, '/') != nullptr) {
- query_message += "~~ ^(";
- query_message += prepare_hostname_regex(host);
- query_message += ")$";
+ query_message += "in ";
+ query_message += prepare_host_match_list(host);
} else {
query_message += "=~ ";
query_message += host;
diff --git a/bin/mkeventd b/bin/mkeventd
index c64d962..9d8449c 100755
--- a/bin/mkeventd
+++ b/bin/mkeventd
@@ -3474,9 +3474,11 @@ class StatusServer(object):
argument = argument.strip()
if header == "Filter":
name, opfunc, argument = self.parse_filter(argument, columns)
- # Needed for later optimization
- if name == "event_host" and opfunc == filter_operators['=']:
- only_host = argument
+
+ # Needed for later optimization (check_mkevents)
+ if name == "event_host" and opfunc == filter_operators['in']:
+ only_host = set(argument)
+
filters.append((name, opfunc, argument))
elif header == "Limit":
limit = int(argument)
@@ -4042,14 +4044,18 @@ class EventStatus(object):
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:
+ # Optimize filters that are set by the check_mkevents active check. Since users
+ # may have a lot of those checks running, it is a good idea to optimize this.
+ if only_host and event["host"] not in only_host:
continue
+
event_line = []
for col_name, col_default in event_columns:
without_prefix = col_name[6:] # drop event_
event_line.append(event.get(without_prefix, col_default))
+
result.append(event_line)
+
return [ e[0] for e in event_columns ], result
Module: check_mk
Branch: master
Commit: ec24b918acc34b3a285d42451033dd79874717c5
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ec24b918acc34b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Sep 26 15:39:25 2017 +0200
5211 FIX Agent bakery: Reduced agent baking time when monitoring 0 hosts from central site
When having a distributed Check_MK/WATO environment where the central management site
has zero hosts configured to be monitored, the time needed to bake agents was increased
by a broken cache. This cache is now being used even when the central site is not monitoring
any host.
You could workaround this issue by adding a single host to be monitored from the central site.
Change-Id: I448f69dcf59d5469f0aaf5c0f9457c34d8b49cfd
---
.werks/5211 | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/.werks/5211 b/.werks/5211
new file mode 100644
index 0000000..2d65eb3
--- /dev/null
+++ b/.werks/5211
@@ -0,0 +1,16 @@
+Title: Agent bakery: Reduced agent baking time when monitoring 0 hosts from central site
+Level: 1
+Component: agents
+Class: fix
+Compatible: compat
+Edition: cee
+State: unknown
+Version: 1.5.0i1
+Date: 1506432991
+
+When having a distributed Check_MK/WATO environment where the central management site
+has zero hosts configured to be monitored, the time needed to bake agents was increased
+by a broken cache. This cache is now being used even when the central site is not monitoring
+any host.
+
+You could workaround this issue by adding a single host to be monitored from the central site.
Module: check_mk
Branch: master
Commit: edf26498dcc5d7a44415707f683d58d428d3a37f
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=edf26498dcc5d7…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Sep 26 15:42:41 2017 +0200
Fixed wrong cache usage
An empty cache does not mean that it has not be populated. An empty
population result can also be a regular case in which the calculation
should not be done twice.
Example: A sites needs to detect the list of hosts to be monitored
locally. Even when there are hundret of sites with thousands of hosts
monitored on all sites, a empty result has to be cached for a site
that does not monitor any host.
Change-Id: Id69612525c3e8ffc3b02e578f8a4543aad055cc3
---
cmk_base/caching.py | 15 +++++++++++++++
cmk_base/config.py | 21 ++++++++++++++-------
tests/cmk_base/test_caching.py | 18 ++++++++++++++++++
3 files changed, 47 insertions(+), 7 deletions(-)
diff --git a/cmk_base/caching.py b/cmk_base/caching.py
index e6451fa..28227b2 100644
--- a/cmk_base/caching.py
+++ b/cmk_base/caching.py
@@ -76,10 +76,25 @@ class CacheManager(object):
class Cache(object):
+ _populated = False
+
def is_empty(self):
+ """Whether or not there is something in the collection at the moment"""
return not self
+ def is_populated(self):
+ """Whether or not the cache has been marked as populated. This is just a flag
+ to tell the caller the initialization state of the cache. It has to be set
+ to True manually by using self.set_populated()"""
+ return self._populated
+
+
+ def set_populated(self):
+ self._populated = True
+
+
+
# Just a small wrapper round a dict to get some caching specific functionality
# for analysis etc.
class DictCache(dict, Cache):
diff --git a/cmk_base/config.py b/cmk_base/config.py
index b44c070..a8e37fb 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -399,8 +399,9 @@ def collect_hosttags():
# Returns a set of all active hosts
def all_active_hosts():
cache = cmk_base.config_cache.get_set("all_active_hosts")
- if cache.is_empty():
+ if not cache.is_populated():
cache.update(all_active_realhosts(), all_active_clusters())
+ cache.set_populated()
return cache
@@ -409,8 +410,9 @@ def all_active_hosts():
def all_active_realhosts():
active_realhosts = cmk_base.config_cache.get_set("active_realhosts")
- if active_realhosts.is_empty():
+ if not active_realhosts.is_populated():
active_realhosts.update(filter_active_hosts(all_configured_realhosts()))
+ active_realhosts.set_populated()
return active_realhosts
@@ -420,8 +422,9 @@ def all_active_realhosts():
def all_active_clusters():
active_clusters = cmk_base.config_cache.get_set("active_clusters")
- if active_clusters.is_empty():
+ if not active_clusters.is_populated():
active_clusters.update(filter_active_hosts(all_configured_clusters()))
+ active_clusters.set_populated()
return active_clusters
@@ -430,8 +433,9 @@ def all_active_clusters():
# disabled or monitored on a remote site.
def all_configured_hosts():
cache = cmk_base.config_cache.get_set("all_configured_hosts")
- if cache.is_empty():
+ if not cache.is_populated():
cache.update(all_configured_realhosts(), all_configured_clusters())
+ cache.set_populated()
return cache
@@ -440,8 +444,9 @@ def all_configured_hosts():
# cluster hosts.
def all_configured_realhosts():
cache = cmk_base.config_cache.get_set("all_configured_realhosts")
- if cache.is_empty():
+ if not cache.is_populated():
cache.update(strip_tags(all_hosts))
+ cache.set_populated()
return cache
@@ -450,8 +455,9 @@ def all_configured_realhosts():
# normal hosts.
def all_configured_clusters():
cache = cmk_base.config_cache.get_set("all_configured_clusters")
- if cache.is_empty():
+ if not cache.is_populated():
cache.update(strip_tags(clusters.keys()))
+ cache.set_populated()
return cache
@@ -570,11 +576,12 @@ def parents_of(hostname):
# If not, return an empty list.
def clusters_of(hostname):
cache = cmk_base.config_cache.get_dict("clusters_of")
- if cache.is_empty():
+ if not cache.is_populated():
for cluster, hosts in clusters.items():
clustername = cluster.split('|', 1)[0]
for name in hosts:
cache.setdefault(name, []).append(clustername)
+ cache.set_populated()
return cache.get(hostname, [])
diff --git a/tests/cmk_base/test_caching.py b/tests/cmk_base/test_caching.py
index 33191eb..26deb00 100644
--- a/tests/cmk_base/test_caching.py
+++ b/tests/cmk_base/test_caching.py
@@ -71,3 +71,21 @@ def test_clear_all():
assert dict_cache.is_empty()
assert set_cache.is_empty()
+
+def test_populated():
+ mgr = cmk_base.caching.CacheManager()
+
+ cache = mgr.get_set("test1")
+ assert not cache.is_populated()
+ cache.set_populated()
+ assert cache.is_populated()
+
+ cache = mgr.get_dict("test2")
+ assert not cache.is_populated()
+ cache.set_populated()
+ assert cache.is_populated()
+
+ cache = mgr.get_list("test3")
+ assert not cache.is_populated()
+ cache.set_populated()
+ assert cache.is_populated()