Cleanup config.nodes_of
[check_mk.git] / checks / omd_apache
blobfd14621936a89fe696bc9b314d1398e4e99ee2ad
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2015 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
27 # <<<omd_apache:sep(124)>>>
28 # [heute]
29 # /heute/check_mk/view.py?view_name=allhosts&_display_options=htbfcoderuw&_do_actions=&_ajaxid=1433252694|200|5067|13465
30 # /heute/check_mk/sidebar_snapin.py?names=tactical_overview,admin|200|4046|8109
31 # /heute/check_mk/index.py?start_url=%2Fheute%2Fcheck_mk%2Fview.py%3Fview_name%3Dallhosts|200|515|7528
32 # /heute/check_mk/view.py?view_name=allhosts|200|37656|57298
33 # /heute/check_mk/side.py|200|39885|108178
34 # /heute/check_mk/js/graphs-2015.06.02.js|200|28895|1823
35 # [heute2]
37 omd_apache_patterns = [
38 # perf keys url matching regex
39 ('cmk_views', r'^check_mk/view\.py'),
40 ('cmk_wato', r'^check_mk/wato\.py'),
41 ('cmk_bi', r'^check_mk/bi\.py'),
42 ('cmk_snapins', r'^check_mk/sidebar_snapin\.py'),
43 ('cmk_dashboards', r'^check_mk/dashboard\.py'),
44 ('cmk_other', r'^check_mk/.*\.py'),
45 ('nagvis_snapin', r'^nagvis/server/core/ajax_handler\.php?mod=Multisite&act=getMaps'),
46 ('nagvis_ajax', r'^nagvis/server/core/ajax_handler\.php'),
47 ('nagvis_other', r'^nagvis/.*\.php'),
48 ('images', r'\.(jpg|png|gif)$'),
49 ('styles', r'\.css$'),
50 ('scripts', r'\.js$'),
51 ('other', '.*'),
55 # Parses the agent data to a dictionary, using the site name as keys
56 # which holds
57 def parse_omd_apache(info):
58 parsed = {}
59 site = None
60 for line in info:
61 if line[0][0] == '[':
62 site = line[0][1:-1]
63 parsed[site] = []
64 elif site:
65 parsed[site].append(line)
66 return parsed
69 def inventory_omd_apache(parsed):
70 return [(k, None) for k in parsed.keys()]
73 def check_omd_apache(item, _no_params, parsed):
74 # First initialize all possible values to be able to always report all perf keys
75 stats = {'requests': {}, 'secs': {}, 'bytes': {}}
76 for key, pattern in omd_apache_patterns:
77 stats['requests'][key] = 0
78 stats['secs'][key] = 0
79 stats['bytes'][key] = 0
81 if item not in parsed:
82 return
83 elif not parsed[item]:
84 yield 0, "No activity since last check"
85 return
87 for line in parsed[item]:
88 if len(line) < 3:
89 continue
90 elif len(line) == 4:
91 url, _status, size_bytes, microsec = line
92 else:
93 url = " ".join(line[:-3])
94 _status, size_bytes, microsec = line[-3:]
96 for key, pattern in omd_apache_patterns:
97 # make url relative to site directory
98 if regex(pattern).search(url[len('/' + item + '/'):]):
99 stats['requests'].setdefault(key, 0)
100 stats['requests'][key] += 1
102 stats['secs'].setdefault(key, 0)
103 stats['secs'][key] += int(microsec) / 1000.0 / 1000.0
105 stats['bytes'].setdefault(key, 0)
106 stats['bytes'][key] += int(size_bytes)
108 break # don't call a line twice
110 # Now process the result. Break down the gathered values to values per second.
111 # the output is showing total values, for the graphing we provide detailed data
112 this_time = time.time()
113 for ty, title in [
114 ('requests', 'Requests/s'),
115 ('secs', 'Seconds serving/s'),
116 ('bytes', 'Sent/s'),
118 total = 0
119 for key, value in sorted(stats[ty].items(), key=lambda k_v: k_v[1], reverse=True):
120 rate = get_rate(
121 "omd_apache.%s.%s.%s" % (item, ty, key),
122 this_time,
123 value,
124 onwrap=SKIP,
125 is_rate=True)
126 total += rate
127 yield 0, '', [(ty + '_' + key, rate)]
129 total = get_bytes_human_readable(total) if ty == "bytes" else ("%.2f" % total)
130 yield 0, '%s %s' % (total, title)
133 check_info['omd_apache'] = {
134 'parse_function': parse_omd_apache,
135 'check_function': check_omd_apache,
136 'inventory_function': inventory_omd_apache,
137 'service_description': 'OMD %s apache',
138 'has_perfdata': True,