Search Exchange

Search All Sites

Nagios Log Server Now Available - Download Now

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

check_jmx

Bookmark and Share

Rating
10 votes
Favoured:
0
Hits
140891
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 (10)
MessageCount does not report the proper messages in a topic.

Synopsis:

MessageCount parameter returns 0. Then....Start hermes and connect to the same topic. If Heremes shows 6 messages in the topic, now run check_jmx and it will show 6 messages.

Now, connect Hermes on another machine (This is now the second instance of hermes) and connect it to the same topic. You now have two versions of heremes dispaying 6 messages. Now run check_jmx, and it will say that there are 12 messages.

Close both instances of hermes, and run check_jmx and it will now show 0 messages. This is crazy.

Took a long time to figure this out.
I had to declare a single command for each attribute i wanted to monitor. But i have 210 jmx checks to monitor.
So, after having tests about how to template jmx checks, finally syabru nagios plugin made it.

What i obtained with this "check_jmx" plugin with this setup :
- nrpe host client :
command[test_check_jmx]=/usr/local/nagios/libexec/check_jmx -U service:jmx:rmi:///jndi/rmi://localhost:$ARG1$/jmxrmi -O org.apache.camel:context=$ARG2$/mainContext,type=$ARG3$,name=\"$ARG4$\" -A $ARG5$ -w $ARG6$ -c $ARG7$
- nagios nrpe server :
./check_nrpe -H 10.20.0.11 -u -c test_check_jmx_dcd_failures -a 10010 satais-esb1 processors threadProcessor FailuresHandled 1 10
JMX UNKNOWN java.lang.NumberFormatException: For input string: "10satais-esb1/mainContext,type=processors,name="threadProcessor"" connecting to org.apache.camel:context=satais-esb1/mainContext,type=processors,name="threadProcessor" by URL service:jmx:rmi:///jndi/rmi://localhost:10010/jmxrmiorg.nagios.ParseError: java.lang.NumberFormatException: For input string: "10satais-esb1/mainContext,type=processors,name="threadProcessor"" at org.nagios.JMXQuery.parse(JMXQuery.java:250) at org.nagios.JMXQuery.main(JMXQuery.java:74) Caused by: java.lang.NumberFormatException: For input string: "10satais-esb1/mainContext,type=processors,name="threadProcessor"" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Long.parseLong(Long.java:438) at java.lang.Long.parseLong(Long.java:478) at org.nagios.JMXQuery.parse(JMXQuery.java:242) ... 1 more Usage: check_jmx -help

- And with the syabru nagios jmx plugin :
./check_nrpe -H 10.20.0.11 -u -c test_check_jmx_dcd_failures -a 10010 satais-esb1 processors threadProcessor FailuresHandled 1 10
JMX OK - FailuresHandled = 0 | 'FailuresHandled'=0;1;10;;
I really like this plugin. It works well once you get the performance data bit added.

However, I'm hitting a problem which isn't necessarily an issue with the plugin but I'm putting it out there because I can't find a resolution at the moment.

I can be monitoring away happily for my application running in Jboss AS4 and checks are working fine and I'm getting performance data graphs etc. Then I restart my application and my service checks stop working, reporting that the checks that were working perfectly well previously now can't find any registered MBeans. The error is something along the lines of InstanceNotFound and Mbean not registered.
The weird thing is, if I fire up jconsole and go to the MBeans tab, all the mbeans are there and soon after my check_jmx service checks start working! But they won't work until I fire up jconsole and access the MBeans tab.
Que?
bytoimtoimtoim, November 27, 2012
1 of 1 people found this review helpful
If you need perf data for your nagios then you could use this script. I have combined other things mentioned in past reviews and added little sed magic to format perf data in correct way.

Atleast for "check_jmx -U service:jmx:rmi:///jndi/rmi://localhost:8060/jmxrmi -O java.lang:type=Memory -A HeapMemoryUsage -K used -I HeapMemoryUsage -J used -vvvv -w 4248302272 -c 5498760192"

output seems to be ok
"JMX OK HeapMemoryUsage.used=70437104{committed=202899456;init=209715200;max=608174080;used=70437104} | committed=202899456; init=209715200; max=608174080; used=70437104;"


#!/bin/sh
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

RDIR=`dirname $0`
OUTPUT=$($JAVA_CMD -cp $RDIR/jmxquery.jar org.nagios.JMXQuery $@)
EXIT_STATUS=$?
STATUS=`echo $OUTPUT`
VALUE=$(echo $OUTPUT | sed 's/.*{\(.*\)}.*/\1;/' | sed 's/;/; /g')
echo "$STATUS | $VALUE"

exit $EXIT_STATUS
byjohntdyer, October 10, 2012
I am having some issue executing an operation via JMX

./check_jmx -U service:jmx:rmi:///jndi/rmi://127.0.0.1:47520/rmi -O "java.lang:type=Threading" -o findDeadlockedThreads

Anyone have any idea how I can programmatically monitor this operation to detect a threadlock ?
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