Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / appdynamics_web_container
blob8faef25ce643eedaac8d09e4c9be30e5b6cc04dd
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 # +------------------------------------------------------------------+
12 # Written by comNET GmbH, Ringo Hartmann
14 # This file is part of Check_MK.
15 # The official homepage is at http://mathias-kettner.de/check_mk.
17 # check_mk is free software; you can redistribute it and/or modify it
18 # under the terms of the GNU General Public License as published by
19 # the Free Software Foundation in version 2. check_mk is distributed
20 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
21 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
22 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
23 # tails. You should have received a copy of the GNU General Public
24 # License along with GNU Make; see the file COPYING. If not, write
25 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
26 # Boston, MA 02110-1301 USA.
28 # <<<appdynamics_web_container:sep(124)>>>
29 # Hans|http-8180|Error Count:0|Busy Threads:0|Current Threads In Pool:0|Request Count:0|Maximum Threads:200
30 # Hans|jk-8109|Error Count:0|Request Count:2
33 def inventory_appdynamics_web_container(info):
34 for line in info:
35 yield ' '.join(line[0:2]), {}
38 def check_appdynamics_web_container(item, params, info):
39 for line in info:
40 if item == ' '.join(line[0:2]):
41 values = {}
42 for metric in line[2:]:
43 name, value = metric.split(':')
44 values[name] = int(value)
46 error_count = values.get('Error Count', None)
47 request_count = values.get('Request Count', None)
49 current_threads = values.get('Current Threads In Pool', None)
50 busy_threads = values.get('Busy Threads', None)
51 max_threads = values.get('Maximum Threads', None)
53 if isinstance(params, tuple):
54 warn, crit = params
55 else:
56 warn, crit = (None, None)
58 if current_threads is not None:
59 state = 0
60 if crit and current_threads >= crit:
61 state = 2
62 elif warn and current_threads >= warn:
63 state = 1
65 thread_levels_label = ''
66 if state > 0:
67 thread_levels_label = ' (warn/crit at %d/%d)' % (warn, crit)
69 if max_threads is not None:
70 perfdata = [('current_threads', current_threads, warn, crit, 0, max_threads)]
71 threads_percent = (100.0 * current_threads / max(1, max_threads))
72 max_info = ' of %d (%.2f%%)' % (max_threads, threads_percent)
73 else:
74 perfdata = [('current_threads', current_threads, warn, crit)]
75 max_info = ''
76 yield state, 'Current threads: %d%s%s' % (current_threads, max_info,
77 thread_levels_label), perfdata
79 if busy_threads is not None:
80 perfdata = [('busy_threads', busy_threads)]
81 yield 0, 'Busy threads: %d' % busy_threads, perfdata
83 now = time.time()
85 if error_count is not None:
86 rate_id = 'appdynamics_web_container.%s.error' % (item.lower().replace(' ', '_'))
87 error_rate = get_rate(rate_id, now, error_count)
88 perfdata = [('error_rate', error_rate)]
89 yield 0, 'Errors: %.2f/sec' % error_rate, perfdata
91 if request_count is not None:
92 rate_id = 'appdynamics_web_container.%s.request' % (item.lower().replace(' ', '_'))
93 request_rate = get_rate(rate_id, now, request_count)
94 perfdata = [('request_rate', request_rate)]
95 yield 0, 'Requests: %.2f/sec' % request_rate, perfdata
98 check_info['appdynamics_web_container'] = {
99 'inventory_function': inventory_appdynamics_web_container,
100 'check_function': check_appdynamics_web_container,
101 'service_description': 'AppDynamics Web Container %s',
102 'has_perfdata': True,
103 'group': 'jvm_threads',