Module: check_mk
Branch: master
Commit: d4a6e99afeea207808e2092ca7ea7df962320515
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d4a6e99afeea20…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Jun 1 10:13:43 2015 +0200
omd_apache: Added check for OMD site apache statistics
---
checks/omd_apache | 101 ++++++++++++++++++++++++++++++++++++++
modules/check_mk_base.py | 12 +++--
web/plugins/metrics/check_mk.py | 102 ++++++++++++++++++++++++++++++++++++++-
3 files changed, 209 insertions(+), 6 deletions(-)
diff --git a/checks/omd_apache b/checks/omd_apache
new file mode 100644
index 0000000..b90263e
--- /dev/null
+++ b/checks/omd_apache
@@ -0,0 +1,101 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2015 mk(a)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-
+# ails. 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.
+
+omd_apache_patterns = [
+ # perf keys url matching regex
+ ('cmk_views' , '^check_mk/view\.py'),
+ ('cmk_wato' , '^check_mk/wato\.py'),
+ ('cmk_bi' , '^check_mk/bi\.py'),
+ ('cmk_snapins' , '^check_mk/sidebar_snapin\.py'),
+ ('cmk_dashboards' , '^check_mk/dashboard\.py'),
+ ('cmk_other' , '^check_mk/.*\.py'),
+
+ ('nagvis_snapin' ,
'^nagvis/server/core/ajax_handler\.php?mod=Multisite&act=getMaps'),
+ ('nagvis_ajax' , '^nagvis/server/core/ajax_handler\.php'),
+ ('nagvis_other' , '^nagvis/.*\.php'),
+
+ ('images' , '\.(jpg|png|gif)$'),
+ ('styles' , '\.css$'),
+ ('scripts' , '\.js$'),
+ ('other' , '.*'),
+]
+
+def inventory_omd_apache(info):
+ for line in info:
+ if line[0][0] == '[':
+ yield line[0][1:-1], None
+
+def check_omd_apache(item, _no_params, info):
+ active = False
+ found = False
+ stats = {'requests': {}, 'secs': {}, 'bytes': {}}
+ for line in info:
+ if line[0] == '[' + item + ']':
+ active = True
+ elif active and line[0] == '[':
+ break
+ elif active:
+ method, url, status, size_bytes, microsec = line
+ for key, pattern in omd_apache_patterns:
+ # make url relative to site directory
+ if regex(pattern).search(url[len('/'+item+'/'):]):
+ found = True
+ stats['requests'].setdefault(key, 0)
+ stats['requests'][key] += 1
+
+ stats['secs'].setdefault(key, 0)
+ stats['secs'][key] += int(microsec) / 1000.0 / 1000.0
+
+ stats['bytes'].setdefault(key, 0)
+ stats['bytes'][key] += int(size_bytes)
+
+ break # don't call a line twice
+
+ if not found:
+ yield 0, "No activity since last check"
+ return
+
+ # Now process the result. Break down the gathered values to values per second.
+ # the output is showing total values, for the graphing we provide detailed data
+ this_time = time.time()
+ for ty, title in [ ('requests', 'Requests/s'), ('secs',
'Seconds serving/s'),
+ ('bytes', 'Sent/s') ]:
+ total = 0
+ for key, value in sorted(stats[ty].items(), key = lambda (k,v): v,
reverse=True):
+ rate = get_rate("omd_apache.%s.%s.%s" % (item, ty, key), this_time,
value,
+ onwrap=SKIP, is_rate=True)
+ total += rate
+ yield 0, None, [(ty+'_'+key, rate)]
+
+ total = ty == 'bytes' and get_bytes_human_readable(total) or
'%.2f' % total
+ yield 0, '%s %s' % (total, title)
+
+check_info['omd_apache'] = {
+ 'check_function' : check_omd_apache,
+ 'inventory_function' : inventory_omd_apache,
+ 'service_description' : 'OMD %s apache',
+ 'has_perfdata' : True,
+}
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 4d42ed6..5b1a339 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -1025,9 +1025,9 @@ def clear_counters(pattern, older_than):
# within one checked item. So e.g. you could use "bcast" as name and not
"if.%s.bcast" % item
# Idea (2): Check_MK should fetch a time stamp for each info. This should also be
# available as a global variable, so that this_time would be an optional argument.
-def get_rate(countername, this_time, this_val, allow_negative=False, onwrap=SKIP):
+def get_rate(countername, this_time, this_val, allow_negative=False, onwrap=SKIP,
is_rate=False):
try:
- timedif, rate = get_counter(countername, this_time, this_val, allow_negative)
+ timedif, rate = get_counter(countername, this_time, this_val, allow_negative,
is_rate)
return rate
except MKCounterWrapped, e:
if onwrap is RAISE:
@@ -1041,7 +1041,7 @@ def get_rate(countername, this_time, this_val, allow_negative=False,
onwrap=SKIP
# Legacy. Do not use this function in checks directly any more!
-def get_counter(countername, this_time, this_val, allow_negative=False):
+def get_counter(countername, this_time, this_val, allow_negative=False, is_rate=False):
global g_counters
# First time we see this counter? Do not return
@@ -1066,7 +1066,11 @@ def get_counter(countername, this_time, this_val,
allow_negative=False):
# update counter for next time
g_counters[countername] = (this_time, this_val)
- valuedif = this_val - last_val
+ if not is_rate:
+ valuedif = this_val - last_val
+ else:
+ valuedif = this_val
+
if valuedif < 0 and not allow_negative:
# Do not try to handle wrapper counters. We do not know
# wether they are 32 or 64 bit. It also could happen counter
diff --git a/web/plugins/metrics/check_mk.py b/web/plugins/metrics/check_mk.py
index 9029d9a..92db6aa 100644
--- a/web/plugins/metrics/check_mk.py
+++ b/web/plugins/metrics/check_mk.py
@@ -1070,12 +1070,90 @@ metric_info["messages"] = {
"color" : "#aa44cc",
}
-metric_info["call_legs"] = {
+metric_info["call_legs"] = {
"title" : _("Call legs"),
"unit" : "count",
"color" : "#60bbbb",
}
+metric_info["requests_cmk_views"] = {
+ "title" : _("%s Requests/s") % "Views",
+ "unit" : "1/s",
+ "color": "#ff8080",
+}
+
+metric_info["requests_cmk_wato"] = {
+ "title" : _("%s Requests/s") % "WATO",
+ "unit" : "1/s",
+ "color": "#377cab",
+}
+
+metric_info["requests_cmk_bi"] = {
+ "title" : _("%s Requests/s") % "BI",
+ "unit" : "1/s",
+ "color": "#4eb0f2",
+}
+
+metric_info["requests_cmk_snapins"] = {
+ "title" : _("%s Requests/s") % "Snapins",
+ "unit" : "1/s",
+ "color": "#ff4040",
+}
+
+metric_info["requests_cmk_dashboards"] = {
+ "title" : _("%s Requests/s") % "Dashboards",
+ "unit" : "1/s",
+ "color": "#4040ff",
+}
+
+metric_info["requests_cmk_other"] = {
+ "title" : _("%s Requests/s") % "Other",
+ "unit" : "1/s",
+ "color": "#5bb9eb",
+}
+
+metric_info["requests_nagvis_snapin"] = {
+ "title" : _("%s Requests/s") % "NagVis Snapin",
+ "unit" : "1/s",
+ "color": "#f2904e",
+}
+
+metric_info["requests_nagvis_ajax"] = {
+ "title" : _("%s Requests/s") % "NagVis AJAX",
+ "unit" : "1/s",
+ "color": "#af91eb",
+}
+
+metric_info["requests_nagvis_other"] = {
+ "title" : _("%s Requests/s") % "NagVis Other",
+ "unit" : "1/s",
+ "color": "#f2df40",
+}
+
+metric_info["requests_images"] = {
+ "title" : _("%s Requests/s") % "Image",
+ "unit" : "1/s",
+ "color": "#91cceb",
+}
+
+metric_info["requests_styles"] = {
+ "title" : _("%s Requests/s") % "Styles",
+ "unit" : "1/s",
+ "color": "#c6f24e",
+}
+
+metric_info["requests_scripts"] = {
+ "title" : _("%s Requests/s") % "Scripts",
+ "unit" : "1/s",
+ "color": "#4ef26c",
+}
+
+metric_info["requests_other"] = {
+ "title" : _("%s Requests/s") % "Other",
+ "unit" : "1/s",
+ "color": "#4eeaf2",
+}
+
#.
# .--Checks--------------------------------------------------------------.
# | ____ _ _ |
@@ -1350,7 +1428,7 @@ check_metrics["check_mk-cisco_srst_call_legs"] = {}
check_metrics["check_mk-logwatch.ec"] = {}
check_metrics["check_mk-logwatch.ec_single"] = {}
-
+check_metrics["check_mk-omd_apache"] = {}
#.
# .--Perf-O-Meters-------------------------------------------------------.
@@ -2047,3 +2125,23 @@ graph_info.append({
( "call_legs", "area" )
],
})
+
+graph_info.append({
+ "title" : _("Handled Requests"),
+ "metrics" : [
+ ("requests_cmk_views", "stack"),
+ #("requests_cmk_wato'", "stack"),
+ #("requests_cmk_bi", "stack"),
+ #("requests_cmk_snapins", "stack"),
+ #("requests_cmk_dashboards", "stack"),
+ #("requests_cmk_other", "stack"),
+ #("requests_nagvis_snapin", "stack"),
+ #("requests_nagvis_ajax", "stack"),
+ #("requests_nagvis_other", "stack"),
+ #("requests_images", "stack"),
+ #("requests_styles", "stack"),
+ #("requests_scripts", "stack"),
+ #("requests_other", "stack"),
+ ],
+})
+