Module: check_mk
Branch: master
Commit: 7b727432a71f824fd0e775ef03aae132b293e046
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7b727432a71f82…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Nov 8 17:51:43 2010 +0100
j4p_performance.mem: new experimental JMX memory check
---
ChangeLog | 1 +
agents/plugins/j4p_performance | 9 ++++-
checkman/j4p_performance.mem | 50 +++++++++++++++++++++++++++++++
checks/j4p_performance | 63 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 121 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ae06146..c285069 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -63,6 +63,7 @@
systems without dhcp server
* j4p_performance: Added experimental agent plugin fetching data via
jmx4perl agent (does not need jmx4perl on Nagios)
+ * j4p_performance.mem: added new experimental check for memory usage via JMX.
Multisite:
* The custom open/close states of custom links are now stored for each
diff --git a/agents/plugins/j4p_performance b/agents/plugins/j4p_performance
index 2af3363..12fa224 100755
--- a/agents/plugins/j4p_performance
+++ b/agents/plugins/j4p_performance
@@ -4,8 +4,10 @@ import urllib, sys, os
server = "localhost"
port = 8080
+instance = None
+
vars = [
- ( "java.lang:type=Memory/NonHeapMemoryUsage/used",
"NoneHeapMemoryUsage" ),
+ ( "java.lang:type=Memory/NonHeapMemoryUsage/used",
"NonHeapMemoryUsage" ),
( "java.lang:type=Memory/HeapMemoryUsage/used",
"HeapMemoryUsage" ),
( "java.lang:type=Threading/ThreadCount", "ThreadCount"
),
( "java.lang:type=Threading/DaemonhreadCount",
"DeamonThreadCount" ),
@@ -17,6 +19,9 @@ vars = [
conffile = os.getenv("MK_CONFDIR", "/etc/check_mk") +
"/j4p.conf"
+if instance == None:
+ instance = str(port)
+
if os.path.exists(conffile):
execfile(conffile)
@@ -33,7 +38,7 @@ for path, title in vars:
if first:
first = False
sys.stdout.write("<<<j4p_performance>>>\n")
- sys.stdout.write("%-30s %s\n" % (title, value))
+ sys.stdout.write("%s %-30s %s\n" % (instance, title, value))
except IOError:
sys.exit(1)
except:
diff --git a/checkman/j4p_performance.mem b/checkman/j4p_performance.mem
new file mode 100644
index 0000000..d8a2879
--- /dev/null
+++ b/checkman/j4p_performance.mem
@@ -0,0 +1,50 @@
+title: Check memory usage of Java application server via JMX and j4p.war
+agents: linux
+author: Mathias Kettner <mk(a)mathias-kettner.de>
+license: GPL
+distribution: check_mk
+description:
+ This checks uses the JSON HTTP service of j4p (from jmx4perl) to
+ monitor the current memory usage of a Java application server like
+ Tomcat or JBoss. You can define levels agains the total memory
+ usage of the Java machine (heap + non heap).
+
+ In order for the check to work, you need to load the j4p.war into your
+ application server. Furthermore you need the agent plugin {j4p_performance}
+ in your Check_MK agent's plugins directory. If you do not use the
+ default port 8080 for j4p - lets say {9090} - then you have to create
+ a configuration file {j4p.conf} in the agents configuration directory
+ (usually {/etc/check_mk/j4p.conf}) with the single line {port = 9090}.
+
+ Note: No jmx4perl is needed - neither on the target host nor
+ on the monitoring server. No Perl is needed, either.
+ The agent connects to the application server always via {localhost}.
+
+item:
+ The instance name as configured in {j4p.conf} with the variable
+ {instance}. If you do not specify an instance then the port number
+ converted to a string is used.
+
+ Please note that the current implementation of the agent plugin
+ supports only one instance per host.
+
+examples:
+ # Set default levels for heap memory to 500 MB / 800 MB
+ j4p_mem_default_levels = (500, 800)
+
+perfdata:
+ Two variables: the heap memory usage and the non heap memory usage
+ in MB.
+
+inventory:
+ One check is created for each JMX instance sent by the agent.
+ The agent currently supports only one instance, but that might
+ be changed in future.
+
+[parameters]
+warning (int): The warning level for used memory in MB
+critical (int): The critical level for used memory in MB
+
+[configuration]
+j4p_mem_default_levels (int, int): Default levels for memory usage in MB. This
+ is preset to {(1000, 2000)}.
diff --git a/checks/j4p_performance b/checks/j4p_performance
new file mode 100644
index 0000000..b11d40c
--- /dev/null
+++ b/checks/j4p_performance
@@ -0,0 +1,63 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2010 mk(a)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.
+
+j4p_mem_default_levels = ( 1000, 2000 ) # MB
+
+def j4p_performance_parse(info):
+ parsed = {}
+ for instance, var, value in info:
+ entry = parsed.get(instance, {})
+ parsed[instance] = entry
+ entry[var] = value
+ return parsed
+
+def inventory_j4p_performance_mem(checktype, info):
+ parsed = j4p_performance_parse(info)
+ return [ (k, "j4p_mem_default_levels") for k in parsed ]
+
+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)
+
+
+check_info["j4p_performance.mem"] = ( check_j4p_performance_mem, "JMX %s
Memory", 1, inventory_j4p_performance_mem )
+