check_jmx

Bookmark and Share

Rating
5 votes
Favoured:
0
Hits
50842
Files:
FileDescription
check_jmx.tgzcheck_jmx version 0.3
Java JMX Nagios Plugin
Updated version of the original check_jmx plugin fixed to support values larger than an Integer could provide. There are no other changes.

Example usage (where $hostname and $port are the hostname and port to check):
./check_jmx -U service:jmx:rmi:///jndi/rmi://$hostname:$port/jmxrmi -O java.lang:type=Memory -A HeapMemoryUsage -K used -I HeapMemoryUsage -J used -vvvv -w 4248302272 -c 5498760192

Original Description:
Java JMX Nagios plugin enables you to monitor JMX attributes in Nagios.
As soon as JMX embedded in Java 5, any Java process may expose parameters to be monitored using JMX interface,
look http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html and http://java.sun.com/jmx for details
In Java version <5 it is still possible to expose JMX interface using third party libraries

To see what can be monitored by JMX, run /bin/jconsole.exe and connect to
the host/port you setup in your Java process.

Some examples are:
* standard Java JMX implementation exposes memory, threads, OS, garbage collector parameters
* Tomcat exposes multiple parameters - requests, processing time, threads, etc..
* spring framework allows to expose Java beans parameters to JMX
* your application may expose any attributes for JMX by declaration or explicitly.
* can monitor localhost or remote processes

Includes Munin plugin for JMX as well.
Reviews (5)
byrayzeller, May 3, 2012
This is an old version. If you want this to work with nrpe, you must have the following: {noformat}

#!/bin/sh
#
# Nagios JMX plugin.
#

JAVA_CMD=`which java`

if [ -z $JAVA_CMD ]
then

if [ -x $JAVA_HOME/bin/java ]
then
JAVA_CMD=$JAVA_HOME/bin/java
else
echo JMX CRITICAL - java not found.
exit 2
fi

fi

DIR=`dirname $0`
$JAVA_CMD -jar $DIR/check_jmx.jar "$@"
{noformat}
as your check_jmx. Otherwise nrpe will not be able to find java.
The problem is most likely permissions. To check what was going on, I executed the script as the nagios user on the remote
machine:

bash /usr/lib/nagios/plugins/contrib/check_jmx -U service:jmx:rmi:///jndi/rmi://localhost:8997/jmxrmi -O java.lang:type=Memory -A HeapMemoryUsage -K used -I HeapMemoryUsage -J used -vvvv -w 10000000 -c 100000000
/usr/lib/nagios/plugins/contrib
Exception in thread "main" java.lang.NoClassDefFoundError: org/nagios/JMXQuery
Caused by: java.lang.ClassNotFoundException: org.nagios.JMXQuery
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

Was the output. the issue was the permissions of the jmxquery.jar file:

root@dvl_app-1:/usr/lib/nagios/plugins/contrib# ls -al
total 56
drwxrwxr-x 2 root root 4096 2011-09-19 10:47 .
drwxrwxr-x 3 root root 4096 2011-09-16 17:04 ..
-r-xr-xr-x 1 root root 28423 2011-09-16 17:04 check_diskio
-rwxr-xr-x 1 nagios nagios 177 2011-09-19 10:52 check_jmx
-rwx------ 1 root root 13225 2011-09-19 09:55 jmxquery.jar

Was what I had. To fix I ran:
chown nagios.nagios /usr/lib/nagios/plugins/contrib/jmxquery.jar

and from my nagios monitoring machine I ran:

/usr/local/nagios/libexec/check_nrpe -H 184.73.5.19 -c check_jmx
JMX CRITICAL HeapMemoryUsage.used=233372176{committed=266797056;init=0;max=266797056;used=233372176}
The current check_jmx shell script won't return information to the performance gathering subsystem in Nagios. Add-ons like PNP4nagios aren't able to pick up the returned values without the proper output.

I offer this little hack...


RDIR=`dirname $0`
OUTPUT=`java -cp $RDIR/jmxquery.jar org.nagios.JMXQuery $@`
EXIT_STATUS=$?
STATUS=`echo $OUTPUT`
VALUE=`echo $OUTPUT | awk '{print $NF}'`
echo "$STATUS | $VALUE"

exit $EXIT_STATUS
byrremingt, November 15, 2010
I'm working on using check_jmx over NRPE. I'm sure the issue has something to do with the limits on data passed between check_nrpe and the remote nrpe daemon. I use NRPE with the perl-based check_multi plug-in and have to increase the data buffer sizes in the C code itself. I'll write again if I have success in getting check_jmx working with NRPE...
Looks like a good start, but it is missing some informations. There is no way I can make it work with NRPE, even if I run it ok directly in my shell account :

[nagios@myserver ~]$ /usr/local/nagios/libexec/check_jmx -U service:jmx:rmi:///jndi/rmi://localhost:8999/jmxrmi -O java.lang:type=Memory -A HeapMemoryUsage -K used -I HeapMemoryUsage -J used -vvvv -w 800000000 -c 1500000000
JMX WARNING HeapMemoryUsage.used=842512960{committed=1042808832;init=1073741824;max=1042808832;used=842512960}


I checked a lot of things, but I am still stuck with the following message :

[nagios@myserver ~]$ /usr/local/nagios/libexec/check_nrpe -H localhost -c check_jmx
NRPE: Unable to read output