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 Continued:  Performance Statistics in JConsole

Step 1:  Enable Statistics MBeans

Once again stop your Tomcat server. Open beet-hello-servlet.xml for editing:

<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:persister-chain>
<bt:xml-persister binary="false" compress="false" file="${catalina.home}/logs/beet-hello-perf.xml"/>
<bt:mbean-persister/>
</bt:persister-chain>
<bt:http-requests parameters="command"/>
</bt:manager>

We've done two things:

  1. <bt:persister-chain> allows us to send behavior events to multiple persister instances.  So we're still writing to the XML log, but we're also sending event data to a new persister type:
  2. <bt:mbean-persister> aggregates event statistics in MBeans so that you can monitor your application from a JMX client. 

Step 2:  Use the application

Start the Tomcat server.  As before, point your browser at http://localhost:8080/beet-hello and create some data in the test application.

Step 3:  Examine Statistics in JConsole

When you navigate to our beet-hello domain in JConsole, you'll see there are some new MBeans available:

Statistics MBeans in JConsole

The attributes of the /beet-hello/ MBean describe aggregate performance statistics for requests against that URI.  But more significantly, we can drill down into Java method calls invoked during request processing, and further into JDBC SQL statements executed during those methods.

You'll notice that /beet-hello is rather coarse-grained; our application has several discrete actions (create, delete, update, clear) but only one URI provides all of them.  We'll refine our event tracking to group events according to key request parameter values.

Step 4:  Refine event groupings

Stop your server and edit beet-hello-servlet.xml:

<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:persister-chain>
<bt:xml-persister binary="false" compress="false" file="${catalina.home}/logs/beet-hello-perf.xml"/>
<bt:mbean-persister/>
</bt:persister-chain>
<bt:http-requests name-parameters="command" uri-pattern="/beet-hello/?" />
</bt:manager>

Now after interacting with your application and viewing the results in JConsole, things are a little different:

Refined Statistics MBeans

The name-parameters attribute allowed us to divide events based on the value of the "command" parameter, an HTTP post parameter identifying the action taken by the user on each request.  For more complicated applications we could add more parameters here, separated by commas.

The uri-pattern attribute is a regular expression identifying which requests interest us.  This filtered out statistics for static resources like png images and CSS files.  You can specify multiple uri-patterns as nested elements, see the User's Guide for more information.