Module: check_mk
Branch: master
Commit: 5f813cfa30cfeacca84b1b0d1980cd571c473405
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5f813cfa30cfea…
Author: Kenneth Okoh <ko(a)mathias-kettner.de>
Date: Thu Nov 22 15:31:08 2018 +0100
Refactored performance snapin to new snapin API
Change-Id: I2314e1cdf7c6f6276ea2475aee6e615aa6d7321f
---
cmk/gui/plugins/sidebar/performance.py | 100 +++++++++++++++++++--------------
1 file changed, 58 insertions(+), 42 deletions(-)
diff --git a/cmk/gui/plugins/sidebar/performance.py
b/cmk/gui/plugins/sidebar/performance.py
index bed037c..98e4097 100644
--- a/cmk/gui/plugins/sidebar/performance.py
+++ b/cmk/gui/plugins/sidebar/performance.py
@@ -28,63 +28,81 @@ import cmk.gui.config as config
import cmk.gui.sites as sites
from cmk.gui.i18n import _
from cmk.gui.globals import html
-
from cmk.gui.plugins.sidebar import (
- sidebar_snapins,
+ SidebarSnapin,
+ snapin_registry,
snapin_width,
snapin_site_choice,
)
-def render_performance():
- only_sites = snapin_site_choice("performance", config.site_choices())
+(a)snapin_registry.register
+class Performance(SidebarSnapin):
+ @staticmethod
+ def type_name():
+ return "performance"
+
+ @classmethod
+ def title(cls):
+ return _("Server Performance")
- def write_line(left, right):
- html.open_tr()
- html.td(left, class_="left")
- html.td(html.render_strong(right), class_="right")
- html.close_tr()
+ @classmethod
+ def description(cls):
+ return _("Live monitor of the overall performance of all monitoring
servers")
- html.open_table(class_=["content_center", "performance"])
+ def show(self):
+ only_sites = snapin_site_choice("performance", config.site_choices())
- try:
- sites.live().set_only_sites(only_sites)
- data = sites.live().query("GET status\nColumns: service_checks_rate
host_checks_rate "
- "external_commands_rate connections_rate
forks_rate "
- "log_messages_rate cached_log_messages\n")
- finally:
- sites.live().set_only_sites(None)
+ def write_line(left, right):
+ html.open_tr()
+ html.td(left, class_="left")
+ html.td(html.render_strong(right), class_="right")
+ html.close_tr()
- for what, col, format_str in \
- [("Service checks", 0, "%.2f/s"),
- ("Host checks", 1, "%.2f/s"),
- ("External commands", 2, "%.2f/s"),
- ("Livestatus-conn.", 3, "%.2f/s"),
- ("Process creations", 4, "%.2f/s"),
- ("New log messages", 5, "%.2f/s"),
- ("Cached log messages", 6, "%d")]:
- write_line(what + ":", format_str % sum(row[col] for row in data))
+ html.open_table(class_=["content_center", "performance"])
- if only_sites is None and len(config.allsites()) == 1:
try:
- data = sites.live().query("GET status\nColumns:
external_command_buffer_slots "
- "external_command_buffer_max\n")
+ sites.live().set_only_sites(only_sites)
+ data = sites.live().query("GET status\nColumns: service_checks_rate
host_checks_rate "
+ "external_commands_rate connections_rate
forks_rate "
+ "log_messages_rate
cached_log_messages\n")
finally:
sites.live().set_only_sites(None)
- size = sum([row[0] for row in data])
- maxx = sum([row[1] for row in data])
- write_line(_('Com. buf. max/total'), "%d / %d" % (maxx, size))
- html.close_table()
+ for what, col, format_str in \
+ [("Service checks", 0, "%.2f/s"),
+ ("Host checks", 1, "%.2f/s"),
+ ("External commands", 2, "%.2f/s"),
+ ("Livestatus-conn.", 3, "%.2f/s"),
+ ("Process creations", 4, "%.2f/s"),
+ ("New log messages", 5, "%.2f/s"),
+ ("Cached log messages", 6, "%d")]:
+ write_line(what + ":", format_str % sum(row[col] for row in data))
+
+ if only_sites is None and len(config.allsites()) == 1:
+ try:
+ data = sites.live().query("GET status\nColumns:
external_command_buffer_slots "
+ "external_command_buffer_max\n")
+ finally:
+ sites.live().set_only_sites(None)
+ size = sum([row[0] for row in data])
+ maxx = sum([row[1] for row in data])
+ write_line(_('Com. buf. max/total'), "%d / %d" % (maxx,
size))
+
+ html.close_table()
+ @classmethod
+ def refresh_on_restart(cls):
+ return True
-sidebar_snapins["performance"] = {
- "title": _("Server Performance"),
- "description": _("Live monitor of the overall performance of all
monitoring servers"),
- "refresh": True,
- "render": render_performance,
- "allowed": ["admin",],
- "styles": """
+ @classmethod
+ def allowed_roles(cls):
+ return [
+ "admin",
+ ]
+
+ def styles(self):
+ return """
#snapin_performance select {
margin-bottom: 2px;
width: 100%%;
@@ -107,6 +125,4 @@ table.performance td.right {
padding-right: 1px;
white-space: nowrap;
}
-
""" % (snapin_width - 2)
-}