About these ads

David Vassallo's Blog

If at first you don't succeed; call it version 1.0

Monitoring Tomcat via JMX–Lessons Learned: Part 1


Requirement : monitoring vital Tomcat statistics such as active & idle threads, memory consumption and so on.

JMX (java monitoring extensions) is quite well documented – so a google search should bring you up to speed, but in a nutshell, JMX is almost like a java-centric SNMP. Java app developers can make certain attributes such as number of threads used, etc, available via “MBeans” (java-style SNMP OIDs). So this lends itself quite well to monitoring.

To enable JMX on a CentOS based tomcat server:
– Navigate to /etc/tomcat/tomcat5.conf and add the following lines to the end of the “JAVA_OPTS” variable:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9990
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

The options are self-explanatory. The above does not use authentication

Notes:

- Make sure the file jmxremote.password exists in $JAVA_HOME/jre/lib/management – Edit the password file to set the password, even if (as above) authentication is actually disabled.

- Also make sure the password file is read only for the same owner as the java process. You can create the password file from the template file. (jmxremote.password.template)

- SYSTEM is the default owner of java process in Windows environment.

- If your remote app is running behind a NAT device, you need to add the additional line when starting the app to specify the remote hostname or ip address:

-Djava.rmi.server.hostname=<IP or hostname>

Please note, the IP or hostname must be the public IP of the tomcat server

To monitor JMX using nagios:

- download “jmxquery” script:
http://code.google.com/p/jmxquery/downloads/detail?name=jmxquery-1.0.zip

- Unzip the archive, and modify the script contained therein:

* change the JAVA_HOME variable
(hint: to set JAVA_HOME in the above two check the file /etc/tomcat/tomcat5.conf)

- note : the above script does not yet support outputting perfmon data for nagios graphing. I’ll post an add-on script in my next post.

- note on troubleshooting: if after following all instructions the check_jmx plugin returns “no route to host” , check the /etc/hosts file on the tomcat server to make sure you have the correct IP to hostname mapping for the server.

- install the package named “jakarta webapps” for tomcat app examples you may use to test JMX

- examples of JMX (check also http://tomcat.apache.org/tomcat-5.5-doc/monitoring.html), note the below should be on a single line, also if monitoring remotely remember to change “localhost” to the appropriate IP

— Heap Memory:
./check_jmx -U service:jmx:rmi:///jndi/rmi://localhost:9003/jmxrmi -O java.lang:type=Memory -A HeapMemoryUsage -K used -I HeapMemoryUsage

— Active Sessions:
./check_jmx -U service:jmx:rmi:///jndi/rmi://localhost:9003/jmxrmi -O Catalina:type=Manager,path=/servlets-examples,host=localhost -A activeSessions

— Max Active Sessions:
./check_jmx -U service:jmx:rmi:///jndi/rmi://localhost:9003/jmxrmi -O Catalina:type=Manager,path=/servlets-examples,host=localhost -A maxActiveSessions

— Thread Count:
./check_jmx -U service:jmx:rmi:///jndi/rmi://localhost:9003/jmxrmi -O java.lang:type=Threading -A ThreadCount

As an alternative, you may also use jmxterm (needs some scripting):
– download:
http://wiki.cyclopsgroup.org/jmxterm:download
– embedding in script:
http://wiki.cyclopsgroup.org/jmxterm:scripting
– extra details:
http://wiki.cyclopsgroup.org/jmxterm:manual

At this stage you may be asking, what else can I monitor over JDK? This is where “jconsole” comes into play. To use jconsole:

- download JDK
– open jconsole.exe (in windows case)
– enter the ip and port of the tomcat server to monitor.

This will give you a couple of useful graphs:

jconsole1

And a summary of the java machine:

jconsole2

But, most importantly in our case, it gives you a whole list of monitor able attributes on your tomcat server:

jconsole3

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 162 other followers

%d bloggers like this: