Module: check_mk
Branch: master
Commit: 86c8e32f810e1a64b943eaabc506cd3114cc4597
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=86c8e32f810e1a…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Jan 17 14:38:19 2017 +0100
Event console performance snapin: The site to get the values from can now be choosen in
distributed EC environments
Change-Id: Ib5a1dd890ce5e46fbb15477703fe88a446de8b73
---
web/htdocs/js/sidebar.js | 8 ++++++++
web/htdocs/mkeventd.py | 20 +++++++++++++-------
web/htdocs/sidebar.py | 12 ++++++++++++
web/plugins/pages/shipped.py | 1 +
web/plugins/sidebar/mkeventd.py | 25 ++++++++++++++++++++++---
5 files changed, 56 insertions(+), 10 deletions(-)
diff --git a/web/htdocs/js/sidebar.js b/web/htdocs/js/sidebar.js
index 0251792..6a7470d 100644
--- a/web/htdocs/js/sidebar.js
+++ b/web/htdocs/js/sidebar.js
@@ -898,6 +898,14 @@ function add_html_var(url, varname, value) {
return new_url;
}
+/************************************************
+ * Event console site selection
+ *************************************************/
+
+function mkeventd_performance_set_ec_site(select_field) {
+ get_url('sidebar_ajax_set_ec_site.py?site=' +
encodeURIComponent(select_field.value));
+ location.reload();
+}
/************************************************
* Popup Message Handling
diff --git a/web/htdocs/mkeventd.py b/web/htdocs/mkeventd.py
index 9d3b9d7..5cc4292 100644
--- a/web/htdocs/mkeventd.py
+++ b/web/htdocs/mkeventd.py
@@ -225,7 +225,7 @@ def execute_command(name, args=None, site=None):
sites.live().command(query, site)
-def get_total_stats():
+def get_total_stats(only_sites):
stats_keys = [
"status_average_message_rate",
"status_average_rule_trie_rate",
@@ -240,7 +240,7 @@ def get_total_stats():
"status_average_sync_time",
]
- stats_per_site = list(get_stats_per_site(stats_keys))
+ stats_per_site = list(get_stats_per_site(only_sites, stats_keys))
# First simply add rates. Times must then be averaged
# weighted by message rate or connect rate
@@ -251,7 +251,10 @@ def get_total_stats():
total_stats.setdefault(key, 0.0)
total_stats[key] += value
if not total_stats:
- return None # No site answered
+ if only_sites is None:
+ raise MKGeneralException(_("Got no data from any site"))
+ else:
+ raise MKGeneralException(_("Got no data from this site"))
for row in stats_per_site:
for time_key, in_relation_to in [
@@ -276,10 +279,13 @@ def get_total_stats():
return total_stats
-def get_stats_per_site(stats_keys):
- for list_row in sites.live().query("GET eventconsolestatus\nColumns: %s" %
" ".join(stats_keys)):
- yield dict(zip(stats_keys, list_row))
-
+def get_stats_per_site(only_sites, stats_keys):
+ try:
+ sites.live().set_only_sites(only_sites)
+ for list_row in sites.live().query("GET eventconsolestatus\nColumns:
%s" % " ".join(stats_keys)):
+ yield dict(zip(stats_keys, list_row))
+ finally:
+ sites.live().set_only_sites(None)
# Rule matching for simulation. Yes - there is some hateful code duplication
diff --git a/web/htdocs/sidebar.py b/web/htdocs/sidebar.py
index 6c90b7c..d2baaa8 100644
--- a/web/htdocs/sidebar.py
+++ b/web/htdocs/sidebar.py
@@ -622,6 +622,18 @@ def ajax_tag_tree_enter():
config.user.save_file("virtual_host_tree", tree_conf)
+def ajax_set_ec_site():
+ site = html.var("site")
+ import wato
+ site_choices = dict([ ("", _("All sites")), ] \
+ + wato.get_event_console_site_choices())
+
+ if site not in site_choices:
+ raise MKUserError(None, _("Invalid site"))
+
+ config.user.save_file("mkeventd_performance_site", site)
+
+
def ajax_switch_site():
# _site_switch=sitename1:on,sitename2:off,...
if not config.user.may("sidesnap.sitestatus"):
diff --git a/web/plugins/pages/shipped.py b/web/plugins/pages/shipped.py
index e4e3610..2d4e0f0 100644
--- a/web/plugins/pages/shipped.py
+++ b/web/plugins/pages/shipped.py
@@ -81,6 +81,7 @@ pagehandlers.update({
"sidebar_ajax_speedometer" : sidebar.ajax_speedometer,
"sidebar_ajax_tag_tree" : sidebar.ajax_tag_tree,
"sidebar_ajax_tag_tree_enter" : sidebar.ajax_tag_tree_enter,
+ "sidebar_ajax_set_ec_site" : sidebar.ajax_set_ec_site,
"sidebar_get_messages" : sidebar.ajax_get_messages,
"sidebar_message_read" : sidebar.ajax_message_read,
"ajax_search" : sidebar.ajax_search,
diff --git a/web/plugins/sidebar/mkeventd.py b/web/plugins/sidebar/mkeventd.py
index 72a180b..6ba13fa 100644
--- a/web/plugins/sidebar/mkeventd.py
+++ b/web/plugins/sidebar/mkeventd.py
@@ -32,8 +32,8 @@ except:
mkeventd_enabled = False
-def mkeventd_performance_entries():
- status = mkeventd.get_total_stats() # combination of several sites
+def mkeventd_performance_entries(only_sites):
+ status = mkeventd.get_total_stats(only_sites) # combination of several sites
entries = []
# TODO: Reorder these values and create a useful order.
@@ -82,8 +82,22 @@ def mkeventd_performance_entries():
def render_mkeventd_performance():
+ site = config.user.load_file("mkeventd_performance_site", "")
+ if site == "":
+ only_sites = None
+ else:
+ only_sites = [site]
+
+ import wato
+ site_choices = wato.get_event_console_site_choices()
+ if len(site_choices) > 1:
+ site_choices = [ ("", _("All sites")), ] + site_choices
+ html.select("site", site_choices, site,
onchange="mkeventd_performance_set_ec_site(this)")
+ else:
+ only_sites = None
+
try:
- entries = mkeventd_performance_entries()
+ entries = mkeventd_performance_entries(only_sites)
except Exception, e:
html.show_error(e)
return
@@ -113,6 +127,11 @@ if mkeventd_enabled:
border-width: 1.5px; */
}
+ #snapin_mkeventd_performance select {
+ margin-bottom: 2px;
+ width: 100%%;
+ }
+
table.mkeventd_performance td {
padding: 0px 2px;
font-size: 8pt;