Monitoring Apache Tomcat With JMX
Monitoring Apache Tomcat With JMX
Christopher Schultz
Chief Technology Officer
Total Child Health, Inc.
Monitoring JVM
Heap status
Garbage collection
GC pause times
Monitoring Tomcat
Status of connector
Request performance
JMX Tools
jconsole (JDK)
Monitoring Tomcat
Request performance
Session information
Monitoring Tomcat
Request performance
Session information
Monitoring Tomcat
Request performance
Session information
Monitoring Tomcat
Request performance
Session information
Monitoring Tomcat
Request performance
Session information
Performance Metrics
On-the-fly re-configuration
Write an MBean
Create an Interface: FooMBean
Create an Implementation: Foo
Create an XML MBean descriptor
Deploy package to Tomcat
Publish the MBean to the MBean server
Query / invoke as necessary
Example MBean
RequestStats MBean
Write an MBean
RequestStats MBean
<mbeans-descriptors>
<operation
<mbean name="RequestStats" ...>
name="resetCounters"
<operation name="getProcessingTime"
description="Resets all
description="Gets the total number of
counters."
milliseconds spent processing requests."
impact="ACTION"
impact="INFO"
returnType="void" />
returnType="long" />
</mbean>
<operation name="getRequestCount"
description="Gets the total number </mbeans-descriptors>
of requests processed."
impact="INFO"
returnType="long" />
RequestStats MBean
Create JAR
Java interface
Java implementation
mbeans-descriptors.xml
RequestStats MBean
Write the Filter
RequestStats MBean
Map the Filter
<filter>
<filter-name>servlet-request-stats</filter-name>
<filter-class>filters.RequestStatsFilter</filter-class>
<init-param>
<param-name>name</param-name>
<param-value>servlets</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>servlet-request-stats</filter-name>
<url-pattern>/servlets/*</url-pattern>
</filter-mapping>
<filter><filter-name>jsp-request-stats</filter-name><filterclass>filters.RequestStatsFilter</filter-class><init-param><param-name>name</paramname><param-value>jsps</param-value></init-param></filter>
<filter-mapping><filter-name>jsp-request-stats</filter-name><url-pattern>/jsp/*</urlpattern></filter-mapping>
RequestStats MBean
RequestStats MBean
Automated Monitoring
Remote Access
Large Scale
Constant
Automated Monitoring
Remote Access
Large Scale
Constant
Automated Monitoring
Nagios
Simple
Flexible
Well-deployed
No-cost community version available
Automated Monitoring
Nagios Monitoring
$ ./check_jmx -U
service:jmx:rmi:///jndi/rmi://localhost:1100/jmxrmi\
-O java.lang:type=Memory -A NonHeapMemoryUsage -K used\
-w 29000000 -c 30000000
JMX WARNING NonHeapMemoryUsage.used=29050880
Nagios Monitoring
Nagios Monitoring
$ ./check_jmxproxy -U 'http://localhost/manager/jmxproxy?
get=java.lang:type=Memory&att=HeapMemoryUsage&key=used' \
-w 29000000 -c 30000000
JMX CRITICAL: OK - Attribute get 'java.lang:type=Memory' HeapMemoryUsage - key 'used' = 100875248
Nagios Monitoring
Session count
Request error count
Session count
Request errors
$ ./check_jmxproxy -U 'http://localhost/manager/jmxproxy?
get=Catalina:type=RequestProcessor,worker="http-nio-127.0.0.18217",name=HttpRequest1&att=errorCount' -w 1 -c 10 --write errors.txt --compare
errors.txt
JMX OK: OK - Attribute get 'Catalina:type=RequestProcessor,worker="http-nio-127.0.0.18217",name=HttpRequest1' - errorCount = 0, delta=0
Detecting OutOfMemory
Heap exhaustion
PermGen exhaustion
Hit thread limit
Hit file descriptor limit
Detecting OutOfMemory
Detect OutOfMemory
Detecting OutOfMemory
$ curl -si \
--data-urlencode 'cmd_typ=30' \
--data-urlencode 'cmd_mod=2' \
--data-urlencode "host=myhost" \
--data-urlencode "service=JVM:Heap:OOME" \
--data-urlencode "plugin_state=2" \
--data-urlencode "plugin_output=OOME CRITICAL" \
'https://monitoring-host/nagios/cgi-bin/cmd.cgi'
Resources
Presentation Slides
http://people.apache.org/~schultz/ApacheCon NA 2014/Tomcat Monitoring/
check_jmxproxy
http://wiki.apache.org/tomcat/tools/check_jmxproxy.pl