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 2:  Install Beet

Installation is basically two steps:  dropping in the libraries, and minor edits to the Spring configuration.  We'll break the latter part down into very small steps for clarity.

Step 1:  Add beet and dependencies to the application's lib directory

Download a beet release package from SourceForge.  This tutorial requires 1.4 RC1 or higher.  Unpack the archive.  This will create a package directory called beet-[version]/.

From the beet package directory, copy the file beet-core.jar and all of the jars from lib/ into the [TOMCAT]/webapps/beet-hello/WEB-INF/lib.

Step 2:  Activate HTTP request behavior tracking

Open the file [TOMCAT]/webapps/beet-hello/WEB-INF/beet-hello-servlet.xml in your favorite text or XML document editor.  You should see something that starts like this:

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<!-- BEGIN APPLICATION LAYER BEANS -->
<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"></bean>

<!-- dao layer -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
... snip ...

Add the highlighted code as below:

<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">

<bt:manager application="beet-hello">
<bt:http-requests parameters="command"/>
</bt:manager>

... snip ...

We've now configured HTTP request tracking.  This wouldn't be terribly useful in itself (you already get access logging with Tomcat), so

Step 2:  Activate Java Method call tracking

For this we just have to add the track-method-expression 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">

<bt:manager application="beet-hello"
track-method-expression="execution(* com.mtgi.analytics.example.service..*(..))">
<bt:http-requests parameters="command"/>
</bt:manager>

This expression identifies "all methods of all classes in the com.mtgi.analytics.example.service package".  So now for each HTTP request, we'll know how much processing time was used executing methods in this package.  To get more detail, 

Step 3:  Activate JDBC Statement tracking

We add the bt:tracking-manager attribute to any data source we want to track:

<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">

<bt:manager application="beet-hello"
track-method-expression="execution(* com.mtgi.analytics.example.service..*(..))">
<bt:http-requests parameters="command"/>
</bt:manager>

<!-- BEGIN APPLICATION LAYER BEANS -->
<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>

<!-- dao layer -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
bt:tracking-manager="defaultTrackingManager">
<property name="dataSourceName" value="helloData"/>
<property name="driverClass" value="org.hsqldb.jdbcDriver"/>
<property name="jdbcUrl" value="jdbc:hsqldb:mem:helloData"/>
<property name="maxPoolSize" value="2"/>
<property name="maxIdleTime" value="30"/>
</bean>

In our application we are using a c3p0 connection-pooling DataSource, but any implementation of javax.sql.DataSource can use the bt:tracking-manager attribute.

At this point we've added the monitoring we want (HTTP, methods, SQL), but we'll make a few final adjustments so that the log output is easy to read:

Step 4: Plain text logging in the [TOMCAT]/logs directory

The default binary log format is good for production, but for our tutorial we'll switch to plain text XML logging, and put the log in a sensible location relative to the Tomcat install.

<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" 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>

The Spring utility class PropertyPlaceHolderConfigurer lets us use system properties like ${catalina.home} to locate the Tomcat root directory.

The flush-schedule attribute is a cron expression that schedules beet log flushes every 30 seconds; the default of 5 minutes is good for production but a little inconvenient for our tutorial. 

Finally, bt:xml-persister switches off binary XML and compression, so our log will be plain old UTF8 XML, and specifies an easy-to-locate log file location of [TOMCAT]/logs/beet-hello-perf.xml.