Cleanup config.nodes_of
[check_mk.git] / checks / jolokia_jvm_threading
blobacbdd1277faf94e723f3d8f140b3d869ef9489f6
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2014 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.
26 import json
28 factory_settings['jolokia_jvm_threading.pool'] = {
29 'currentThreadsBusy': (80, 90),
33 def parse_jolokia_json_output(info):
34 for line in info:
35 try:
36 instance, mbean, raw_json_data = line
37 yield instance, mbean, json.loads(raw_json_data)
38 except ValueError:
39 continue
42 def parse_jolokia_jvm_threading(info):
43 parsed = {}
44 for instance, mbean, data in parse_jolokia_json_output(info):
46 type_ = mbean.split("type=", 1)[-1].split(",", 1)[0].split("/", 1)[0]
47 parsed_data = parsed.setdefault(instance, {}).setdefault(type_, {})
49 if type_ == "ThreadPool":
50 for key in data:
51 name = key.split('name="', 1)[-1].split('"', 1)[0]
52 parsed_data[name] = data[key]
53 else:
54 parsed_data.update(data)
56 return parsed
59 @discover
60 def discover_jolokia_jvm_threading(_instance, data):
61 return bool(data.get("Threading"))
64 @get_parsed_item_data
65 def check_jolokia_jvm_threading(item, params, instance_data):
66 data = instance_data.get("Threading", {})
67 count = data.get('ThreadCount')
68 if count is not None:
69 levels = params.get('threadcount_levels')
70 yield check_levels(
71 count, 'ThreadCount', levels, infoname="Count", human_readable_func=lambda i: "%.f" % i)
73 counter = "jolokia_jvm_threading.count.%s" % item
74 thread_rate = get_rate(counter, time.time(), count, allow_negative=True)
75 levels = params.get('threadrate_levels')
76 yield check_levels(thread_rate, 'ThreadRate', levels, infoname="Rate")
78 for key, name in (
79 ('DaemonThreadCount', 'Daemon threads'),
80 ('PeakThreadCount', 'Peak count'),
81 ('TotalStartedThreadCount', 'Total started'),
83 value = data.get(key)
84 if value is None:
85 continue
86 levels = params.get('%s_levels' % key.lower())
87 yield check_levels(
88 value, key, levels, infoname=name, human_readable_func=lambda i: "%.f" % i)
91 check_info["jolokia_jvm_threading"] = {
92 "parse_function": parse_jolokia_jvm_threading,
93 "inventory_function": discover_jolokia_jvm_threading,
94 "check_function": check_jolokia_jvm_threading,
95 "service_description": "JVM %s Threading",
96 "group": "jvm_threading",
97 "has_perfdata": True,
101 def discover_jolokia_jvm_threading_pool(parsed):
102 for instance in parsed:
103 threadpool_data = parsed[instance].get("ThreadPool", {})
104 for name in threadpool_data:
105 yield "%s ThreadPool %s" % (instance, name), {}
108 def check_jolokia_jvm_threading_pool(item, params, parsed):
109 instance, pool_name = item.split(" ThreadPool ", 1)
110 thread_pools = parsed.get(instance, {}).get("ThreadPool", {})
111 threadpool_info = thread_pools.get(pool_name, {})
112 max_threads = threadpool_info.get("maxThreads")
113 if max_threads is None:
114 return
116 yield 0, "Maximum threads: %d" % max_threads
118 for key, name in (
119 ('currentThreadsBusy', 'Busy'),
120 ('currentThreadCount', 'Total'),
122 value = threadpool_info.get(key)
123 if value is None:
124 continue
125 result = check_levels(
126 value,
127 key,
128 params.get(key),
129 infoname=name,
130 factor=max_threads / 100.,
131 human_readable_func=lambda f: "%.f" % f)
132 result[2][0] = result[2][0][:4] + (None, max_threads)
133 yield result
136 check_info["jolokia_jvm_threading.pool"] = {
137 "inventory_function": discover_jolokia_jvm_threading_pool,
138 "check_function": check_jolokia_jvm_threading_pool,
139 "default_levels_variable": "jolokia_jvm_threading.pool",
140 "service_description": "JVM %s",
141 "group": "jvm_tp",
142 "has_perfdata": True,