Article Index
Tutorial
Part 1: Tutorial Setup
Part 2: Install Beet
Part 3: Examine the data
Part 4: JMX Administration
Part 4 Continued: Performance Statistics
Part 5: Log analysis with beet-util
Following Up
All Pages

Part 4:  JMX Administration

Beet provides some basic diagnostic information to any JMX console.  For this tutorial we'll be using jconsole, which comes standard with any Java 6 SDK installation.

Step 1:  Enable JMX on your Tomcat server

We will configure your Tomcat server for unauthenticated JMX access.  Never do this on a production system!  For obvious reasons it is a huge security risk.  When you want to enable JMX on your production server, read both the Tomcat monitoring instructions and Sun's administration guide to protect against unauthorized access.  On to business:

Stop your server if it is running.  Open your [TOMCAT]/bin/startup script in a text editor, and insert the following text near the top:

Windows users:

set JAVA_OPTS=-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false 

*nix users:

JAVA_OPTS=-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false 

Step 2:  Activate Beet's JMX support

Once again open our spring configuration file beet-hello-servlet.xml in a text editor, and add the register-mbeans attribute to <bt:manager>:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bt="http://beet.sourceforge.net/schema/bt/1.1"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://beet.sourceforge.net/schema/bt/1.1 http://beet.sourceforge.net/schema/bt/mtgi-bt-1.1.xsd">

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>

<bt:manager application="beet-hello" register-mbeans="true" flush-schedule="0/30 * * * * ?"
track-method-expression="execution(* com.mtgi.analytics.example.service..*(..))">
<bt:xml-persister binary="false" compress="false" file="${catalina.home}/logs/beet-hello-perf.xml"/>
<bt:http-requests parameters="command"/>
</bt:manager>
This is a shorthand way to export Beet's MBeans using Spring's powerful JMX support.  You can alternatively use standard Spring JMX MBean detection if you want more control over how the MBeans are registered.  See the Spring User Guide for more detailed information about how this works.

Step 3:  Connect with jconsole

Start your Tomcat server.  Once it is up and running, fire up a jconsole process.  jconsole is usually located in [JAVA SDK HOME]/bin/jconsole.  You should see something that looks like this:

jconsole login screen

Select the Remote Process radio button.  Enter localhost:12345 in the first text field.  Do not enter anything for username or password; click Connect.  Once connected to your server, select the MBeans tab.  Expand the tree nodes for beet-hello, com.mtgi.analytics, and then defaultTrackingManager.  You should see something like this:

jconsole mbeans tree

The BeetManager bean can be used to

  • resume or suspend beet monitoring (via the resume and suspend operations),
  • see how many unlogged events are in memory (via the EventsPendingFlush attribute), and optionally
  • flush these events to the log via the flush operation.

The BeetLog bean can be used to

  • View the size of the current log file via the FileSize attribute
  • View and change the log compression and format settings via the Binary and Compress attributes
  • Force an ahead-of-schedule log rotation view that rotateLog operation.

Part 5 of the tutorial will use some of these controls to change the logging format.  Before that, we'll explore monitoring your application's performance from a JMX console.