Last night, I setup Tomcat monitoring for a Railo application deployed on Tomcat 6. Of course, Tomcat is just a servlet container so these instructions will work for any web-app deployed on Tomcat including Adobe ColdFusion, Spring, Groovy or your custom Web application.
This brief tutorial guides you on setting up JavaMelody which monitors a wealth of data–I've summarized a list at the end of this post.
Setup JavaMelody on your Tomcat Server: Step One
Download the JavaMelody zip file (v. 1.25.0 as of this writing) and copy the "jira-javamelody.jar" and "jrobin-1.5.9.1.jar" files to your web application's /WEB-INF/lib directory.
Setup JavaMelody on your Tomcat Server: Step Two
Edit your /WEB-INF/web.xml file and add the highlighted lines (10 through 21) directly below your title and description.
<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>Your Application</display-name> <description>Your Application</description> <!-- Monitor --> <filter> <filter-name>monitoring</filter-name> <filter-class>net.bull.javamelody.MonitoringFilter</filter-class> </filter> <filter-mapping> <filter-name>monitoring</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>net.bull.javamelody.SessionListener</listener-class> </listener> <!-- URL Rewrite --> <filter> <filter-name>UrlRewriteFilter</filter-name> <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class> </filter> <filter-mapping> <filter-name>UrlRewriteFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
Setup JavaMelody on your Tomcat Server: Step Three (Optional)
This step is optional and only needed if you are using Tuckey for URL Rewriting. Edit your /WEB-INF/urlrewrite.xml file to exclude the /monitoring directory for rewriting.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN" "http://tuckey.org/res/dtds/urlrewrite3.2.dtd">
<!--
Configuration file for UrlRewriteFilter
http://tuckey.org/urlrewrite/
-->
<urlrewrite>
<rule>
<note>
Enable TomCat to have SES links.
</note>
<condition type="request-uri" operator="notequal">\.(bmp|gif|jpe?g|png|css|js|txt|pdf|doc|xls|xml|cfc|ico|php|asp)$</condition>
<!-- Notice the last entry of "monitoring" -->
<from>^/(?!cdn|src|railo-context|test|mxunit|remote|monitoring)(.*)$</from>
<to>/index.cfm/$1</to>
</rule>
</urlrewrite>Setup JavaMelody on your Tomcat Server: Last Step
Restart your tomcat instance and visit http://yoursite/monitoring–which, for my development machine is http://localhost:8888/monitoring
Some features of JavaMelody
- Used Memory
- CPU Usage as a percent
- HTTP Sessions
- Active Threads
- Active JDBC Connections
- Used JDBC Connections
- HTTP hits per minuite
- HTTP mean response times
- % of requests that resulted in an HTTP error
- SQL hits per minuite
- SQL mean response time
- % of SQL requests resulting in an error
- % Garbade Collector Time
- Threads Count
- Loaded classes count (in kilobytes)
- Used non-heap memory
- Used physical memory for the machine
- Used swap space on the machine
- Mean age of http sessions in minutes
- Tomcat busy ghreads
- Bytes received per minute
- Bytes sent per minute
- JSP/CFM hits per minute
- JSP mean response time
- % of JSP errors

