2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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)>>>
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
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$'),
55 # Parses the agent data to a dictionary, using the site name as keys
57 def parse_omd_apache(info
):
65 parsed
[site
].append(line
)
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
:
83 elif not parsed
[item
]:
84 yield 0, "No activity since last check"
87 for line
in parsed
[item
]:
91 url
, _status
, size_bytes
, microsec
= line
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()
114 ('requests', 'Requests/s'),
115 ('secs', 'Seconds serving/s'),
119 for key
, value
in sorted(stats
[ty
].items(), key
=lambda k_v
: k_v
[1], reverse
=True):
121 "omd_apache.%s.%s.%s" % (item
, ty
, key
),
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,