/usr/share/check_mk/checks/j4p_performance is in check-mk-server 1.1.12-1ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | #!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# | ____ _ _ __ __ _ __ |
# | / ___| |__ ___ ___| | __ | \/ | |/ / |
# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
# | | |___| | | | __/ (__| < | | | | . \ |
# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
# | |
# | Copyright Mathias Kettner 2010 mk@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.
# MB warn, crit
j4p_performance_mem_default_levels = (1000, 2000)
# Number of threads warn, crit
j4p_performance_threads_default_levels = (80, 100)
# Number of sessions low crit, low warn, high warn, high crit
j4p_performance_app_sess_default_levels = (-1, -1, 800, 1000)
# Number of requests low crit, low warn, high warn, high crit
j4p_performance_serv_req_default_levels = (-1, -1, 5000, 6000)
def j4p_performance_parse(info):
parsed = {}
for inst, var, value in info:
app, servlet = None, None
if ',' in inst:
parts = inst.split(',')
if len(parts) == 3:
inst, app, servlet = parts
else:
inst, app = parts
parsed.setdefault(inst, {})
if servlet:
parsed[inst].setdefault('apps', {})
parsed[inst]['apps'][app].setdefault('servlets', {})
parsed[inst]['apps'][app]['servlets'].setdefault(servlet, {})
parsed[inst]['apps'][app]['servlets'][servlet][var] = value
elif app:
parsed[inst].setdefault('apps', {})
parsed[inst]['apps'].setdefault(app, {})
parsed[inst]['apps'][app][var] = value
else:
parsed[inst][var] = value
return parsed
def j4p_performance_app(info, (inst, app)):
parsed = j4p_performance_parse(info)
if not inst in parsed \
or not app in parsed[inst].get('apps', {}):
return None
return parsed[inst]['apps'][app]
def j4p_performance_serv(info, (inst, app, serv)):
app = j4p_performance_app(info, (inst, app))
if not app or not serv in app.get('servlets', {}):
return None
return app['servlets'][serv]
def inventory_j4p_performance(info, what):
parsed = j4p_performance_parse(info)
levels = None
if what == 'mem':
levels = 'j4p_performance_mem_default_levels'
elif what == 'threads':
levels = 'j4p_performance_threads_default_levels'
return [ (k, levels) for k in parsed ]
def inventory_j4p_performance_apps(info, what):
inv = []
parsed = j4p_performance_parse(info)
levels = None
if what == 'app_sess':
levels = 'j4p_performance_app_sess_default_levels'
for inst, vals in parsed.iteritems():
for app in vals.get('apps', {}).keys():
inv.append(('%s %s' % (inst, app), levels))
return inv
def inventory_j4p_performance_serv(info, what):
inv = []
parsed = j4p_performance_parse(info)
levels = None
if what == 'serv_req':
levels = 'j4p_performance_serv_req_default_levels'
for inst, vals in parsed.iteritems():
for app, val in vals.get('apps', {}).iteritems():
for serv in val.get('servlets', {}).keys():
inv.append(('%s %s %s' % (inst, app, serv), levels))
return inv
def check_j4p_performance_mem(item, params, info):
warn, crit = params
parsed = j4p_performance_parse(info)
if item not in parsed:
return (3, "UNKNOWN - data not found in agent output")
d = parsed[item]
mb = 1024 * 1024.0
heap = saveint(d["HeapMemoryUsage"]) / mb
non_heap = saveint(d["NonHeapMemoryUsage"]) / mb
total = heap + non_heap
perfdata = [ ("heap", heap, warn, crit),
("nonheap", non_heap, warn, crit) ]
infotext = "%.0f MB total (%.0f heap, %.0f MB non-heap), levels at %.0f/%.0f" % (total, heap, non_heap, warn, crit)
if total >= crit:
return (2, "CRIT - " + infotext, perfdata)
elif total >= warn:
return (1, "WARN - " + infotext, perfdata)
else:
return (0, "OK - " + infotext, perfdata)
def check_j4p_performance_threads(item, params, info):
warn, crit = params
parsed = j4p_performance_parse(info)
if item not in parsed:
return (3, "UNKNOWN - data not found in agent output")
d = parsed[item]
this_time = time.time()
wrapped = False
perfdata = []
output = []
status = 0
for key in [ 'ThreadCount', 'DeamonThreadCount', 'PeakThreadCount', 'TotalStartedThreadCount' ]:
val = saveint(d[key])
if key == 'ThreadCount':
# Thread count might lead to a warn/crit state
if val >= crit:
status = 2
elif val >= warn:
status = 1
# Calculate the thread increase rate
try:
timedif, rate = get_counter("j4p_performance.threads.%s" % item, this_time, val)
output.append('ThreadRate: %0.2f' % rate)
perfdata.append(('ThreadRate', rate))
except MKCounterWrapped:
wrapped = True
perfdata.append((key, val))
output.append('%s: %d' % (key, val))
# Only process the perfdata when no wrap occured
if wrapped:
return (status, '%s - %s' % (nagios_state_names[status], ', '.join(output)))
else:
return (status, '%s - %s' % (nagios_state_names[status], ', '.join(output)), perfdata)
def check_j4p_performance_uptime(item, _unused, info):
parsed = j4p_performance_parse(info)
if item not in parsed:
return (3, "UNKNOWN - data not found in agent output")
uptime = saveint(parsed[item]['Uptime']) / 1000
seconds = uptime % 60
rem = uptime / 60
minutes = rem % 60
hours = (rem % 1440) / 60
days = rem / 1440
now = int(time.time())
since = time.strftime("%c", time.localtime(now - uptime))
return (0, "OK - up since %s (%dd %02d:%02d:%02d)" % (since, days, hours, minutes, seconds), [ ("uptime", uptime) ])
def check_j4p_performance_app_state(item, _unused, info):
app = j4p_performance_app(info, item.split())
if not app or not 'Running' in app:
return (3, "UNKNOWN - data not found in agent output")
if app['Running'] == '1':
return (0, 'OK - application is running')
else:
return (2, 'CRIT - application is not running (Running: %s)')
def check_j4p_performance_app_sess(item, params, info):
lo_crit, lo_warn, hi_warn, hi_crit = params
app = j4p_performance_app(info, item.split())
if not app or not 'Sessions' in app:
return (3, "UNKNOWN - data not found in agent output")
sess = saveint(app['Sessions'])
status = 0
status_txt = ''
if lo_crit is not None and sess <= lo_crit:
status = 2
status_txt = ' (Below or equal %d)' % lo_crit
elif lo_warn is not None and sess <= lo_warn:
status = 1
status_txt = ' (Below or equal %d)' % lo_warn
elif hi_crit is not None and sess >= hi_crit:
status = 2
status_txt = ' (Above or equal %d)' % lo_warn
elif hi_warn is not None and sess >= hi_warn:
status = 1
status_txt = ' (Above or equal %d)' % lo_crit
return (status, '%s - %d Sessions%s' % (nagios_state_names[status], sess, status_txt),
[('sessions', sess, hi_warn, hi_crit)])
def check_j4p_performance_serv_req(item, params, info):
lo_crit, lo_warn, hi_warn, hi_crit = params
serv = j4p_performance_serv(info, item.split())
if not serv or not 'Requests' in serv:
return (3, "UNKNOWN - data not found in agent output")
req = saveint(serv['Requests'])
status = 0
status_txt = ''
if lo_crit is not None and req <= lo_crit:
status = 2
status_txt = ' (Below or equal %d)' % lo_crit
elif lo_warn is not None and req <= lo_warn:
status = 1
status_txt = ' (Below or equal %d)' % lo_warn
elif hi_crit is not None and req >= hi_crit:
status = 2
status_txt = ' (Above or equal %d)' % lo_warn
elif hi_warn is not None and req >= hi_warn:
status = 1
status_txt = ' (Above or equal %d)' % lo_crit
output = ['Requests: %d%s' % (req, status_txt)]
perfdata = [('Requests', req, hi_warn, hi_crit)]
wrapped = False
this_time = time.time()
try:
timedif, rate = get_counter("j4p_performance.serv_req.%s" % item, this_time, req)
output.append('RequestRate: %0.2f' % rate)
perfdata.append(('RequestRate', rate))
except MKCounterWrapped:
wrapped = True
if wrapped:
return (status, '%s - %s' % (nagios_state_names[status], ', '.join(output)))
else:
return (status, '%s - %s' % (nagios_state_names[status], ', '.join(output)), perfdata)
# General JVM checks
check_info["j4p_performance.mem"] = ( check_j4p_performance_mem, "JMX %s Memory", 1, lambda i: inventory_j4p_performance(i, "mem"))
check_info["j4p_performance.threads"] = ( check_j4p_performance_threads, "JMX %s Threads", 1, lambda i: inventory_j4p_performance(i, "threads"))
check_info["j4p_performance.uptime"] = ( check_j4p_performance_uptime, "JMX %s Uptime", 1, lambda i: inventory_j4p_performance(i, "uptime"))
# App specific checks
check_info["j4p_performance.app_state"] = ( check_j4p_performance_app_state, "JMX %s State", 0, lambda i: inventory_j4p_performance_apps(i, "app_state"))
check_info["j4p_performance.app_sess"] = ( check_j4p_performance_app_sess, "JMX %s Sessions", 1, lambda i: inventory_j4p_performance_apps(i, "app_sess"))
# Servlet specific checks
check_info["j4p_performance.serv_req"] = ( check_j4p_performance_serv_req, "JMX %s Requests", 1, lambda i: inventory_j4p_performance_serv(i, "serv_req"))
|