/usr/share/check_mk/web/plugins/views/perfometer.py is in check-mk-multisite 1.2.8p16-1ubuntu0.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | #!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# | ____ _ _ __ __ _ __ |
# | / ___| |__ ___ ___| | __ | \/ | |/ / |
# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
# | | |___| | | | __/ (__| < | | | | . \ |
# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
# | |
# | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation in version 2. check_mk is distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
# tails. You should have received a copy of the GNU General Public
# License along with GNU Make; see the file COPYING. If not, write
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
# Painters for Perf-O-Meter
import math
import metrics
perfometers = {}
# TODO: Umbau: alle Funktionen perfometer_.. geben eine logische Struktur
# zurück.
# perfometer_td() -> perfometer_segment() ergebit (breite_in_proz, farbe)
# Ein perfometer ist eine Liste von Listen.
# [ [segment, segment, segment], [segment, segment] ] --> horizontal gespaltet.
# Darin die vertikalen Balken.
# .--Old Style-----------------------------------------------------------.
# | ___ _ _ ____ _ _ |
# | / _ \| | __| | / ___|| |_ _ _| | ___ |
# | | | | | |/ _` | \___ \| __| | | | |/ _ \ |
# | | |_| | | (_| | ___) | |_| |_| | | __/ |
# | \___/|_|\__,_| |____/ \__|\__, |_|\___| |
# | |___/ |
# +----------------------------------------------------------------------+
# | Perf-O-Meter helper functions for old classical Perf-O-Meters. |
# '----------------------------------------------------------------------'
def perfometer_td(perc, color):
return '<td class="inner" style="background-color: %s; ' \
'width: %d%%;"></td>' % (color, int(float(perc)))
# Paint linear performeter with one value
def perfometer_linear(perc, color):
return "<table><tr>" + \
perfometer_td(perc, color) + \
perfometer_td(100 - perc, "white") + \
"</tr></table>"
# Paint logarithm with base 10, half_value is being
# displayed at 50% of the width
def perfometer_logarithmic(value, half_value, base, color):
return render_metricometer([metrics.metricometer_logarithmic(value, half_value, base, color)])
# Dual logarithmic Perf-O-Meter
def perfometer_logarithmic_dual(value_left, color_left, value_right, color_right, half_value, base):
result = '<table><tr>'
for where, value, color in [
("left", value_left, color_left),
("right", value_right, color_right) ]:
value = float(value)
if value == 0.0:
pos = 0
else:
half_value = float(half_value)
h = math.log(half_value, base) # value to be displayed at 50%
pos = 25 + 10.0 * (math.log(value, base) - h)
if pos < 1:
pos = 1
if pos > 49:
pos = 49
if where == "right":
result += perfometer_td(pos, color) + \
perfometer_td(50 - pos, "white")
else:
result += perfometer_td(50 - pos, "white") + \
perfometer_td(pos, color)
return result + '</tr></table>'
def perfometer_logarithmic_dual_independent\
(value_left, color_left, half_value_left, base_left, value_right, color_right, half_value_right, base_right):
result = '<table><tr>'
for where, value, color, half_value, base in [
("left", value_left, color_left, half_value_left, base_left),
("right", value_right, color_right, half_value_right, base_left) ]:
value = float(value)
if value == 0.0:
pos = 0
else:
half_value = float(half_value)
h = math.log(half_value, base) # value to be displayed at 50%
pos = 25 + 10.0 * (math.log(value, base) - h)
if pos < 1:
pos = 1
if pos > 49:
pos = 49
if where == "right":
result += perfometer_td(pos, color) + \
perfometer_td(50 - pos, "white")
else:
result += perfometer_td(50 - pos, "white") + \
perfometer_td(pos, color)
return result + '</tr></table>'
def paint_perfometer(row):
perf_data_string = unicode(row["service_perf_data"].strip())
if not perf_data_string:
return "", ""
perf_data, check_command = metrics.parse_perf_data(perf_data_string, row["service_check_command"])
if not perf_data:
return "", ""
if is_stale(row):
stale_css = " stale"
else:
stale_css = ""
try:
# Try new metrics module
title = None
translated_metrics = metrics.translate_metrics(perf_data, check_command)
if translated_metrics: # definition for this check type exists
perfometer_definitions = list(metrics.get_perfometers(translated_metrics))
if perfometer_definitions:
title, h = render_metrics_perfometer(perfometer_definitions[0], translated_metrics)
# Legacy Perf-O-Meters: find matching Perf-O-Meter function
if title == None:
perf_painter = perfometers.get(check_command)
if not perf_painter:
return "", ""
title, h = perf_painter(row, check_command, perf_data)
if not h:
return "", ""
# Test code for optically detecting old-style Perf-O-Meters
if config.debug:
title = '{ ' + title + ' }'
except Exception, e:
if config.debug:
raise
return "perfometer", ("invalid data: %s" % e)
content = '<div class=content>%s</div>' % h
content += '<div class=title>%s</div>' % title
content += '<img class=glass src="images/perfometer-bg.png">'
# pnpgraph_present: -1 means unknown (path not configured), 0: no, 1: yes
if 'X' in html.display_options and \
row["service_pnpgraph_present"] != 0:
if metrics.cmk_graphs_possible():
url = new_graphing_url(row, "service")
else:
url = pnp_url(row, "service")
return "perfometer" + stale_css, ('<a href="%s">%s</a>' % (url, content))
else:
return "perfometer" + stale_css, content
#.
# .--New Style--(Metric-O-Meters)----------------------------------------.
# | _ _ ____ _ _ |
# | | \ | | _____ __ / ___|| |_ _ _| | ___ |
# | | \| |/ _ \ \ /\ / / \___ \| __| | | | |/ _ \ |
# | | |\ | __/\ V V / ___) | |_| |_| | | __/ |
# | |_| \_|\___| \_/\_/ |____/ \__|\__, |_|\___| |
# | |___/ |
# +----------------------------------------------------------------------+
# | Perf-O-Meters created by new metrics system |
# '----------------------------------------------------------------------'
# Create HTML representation of Perf-O-Meter
def render_metricometer(stack):
if len(stack) not in (1, 2):
raise MKGeneralException(_("Invalid Perf-O-Meter definition %r: only one or two entries are allowed") % stack)
h = ""
if len(stack) == 2:
h += '<div class="stacked">'
for entry in stack:
h += '<table><tr>'
for percentage, color in entry:
h += perfometer_td(percentage, color)
h += "</tr></table>"
if len(stack) == 2:
h += '</div>'
return h
# Compute logarithmic Perf-O-Meter
def render_metrics_perfometer(perfometer, translated_metrics):
label, stack = metrics.build_perfometer(perfometer, translated_metrics)
return label, render_metricometer(stack)
multisite_painters["perfometer"] = {
"title" : _("Service Perf-O-Meter"),
"short" : _("Perf-O-Meter"),
"columns" : [ "service_perf_data", "service_state",
"service_check_command", "service_pnpgraph_present", "service_plugin_output" ],
"paint" : paint_perfometer,
"sorter" : "svc_perf_val01",
"printable" : "perfometer", # Special rendering in PDFs
}
load_web_plugins("perfometer", globals())
|