Chapter 3. Configuration Reference

Table of Contents

Configuration Examples
The Behavior Tracking Servlet Filter
XML Schema Documentation for http://beet.sourceforge.net/schema/bt/1.1
<bt:config>
<bt:manager>
<bt:advice>
<bt:persister-chain>
<bt:xml-persister>
<bt:jdbc-persister>
<bt:mbean-persister>
<bt:custom-persister>
<bt:session-context>
Attribute bt:tracking-manager

Most configuration is accomplished by importing the custom config namespace into your Spring bean definition file, and then using it to define the appropriate elements. You can find probably find an example in the section called “Configuration Examples” and then customize it to suit your needs using the schema reference in the section called “XML Schema Documentation for http://beet.sourceforge.net/schema/bt/1.1”.

Unless otherwise specified, all schema elements support the "id" attribute for injection into other Spring beans, in addition to those listed here.

Configuration Examples

The simplest example in Chapter 1, Quick Start should suit most applications. Here are some common (and less common) customizations:

Example 3.1. Store performance logs in the Tomcat logs directory

<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.0.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"/>1
   
   <bt:manager application="myapp">
      <bt:xml-persister file="${catalina.home}/logs/myapp-beet.xml"/>2
   </bt:manager>

1

This spring utility class is required to use system properties like catalina.home in your Spring configuration.

2

Tomcat defines the catalina.home system property, which is useful for specifying server-relative paths in the configuration. The file extension listed here will be replaced at runtime with one appropriate to the log settings; for example, ".gz" is appended if log compression is enabled (which is the default).


Example 3.2. Monitor application performance from a JMX console

<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.0.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"/>1
   
   <bt:manager application="myapp">
      <bt:persister-chain>
         <bt:xml-persister/>2
         <bt:mbean-persister/>3
      </bt:persister-chain>
   </bt:manager>

2

You can use mbean-persister by itself, but we recommend using it in combination with another persister that actually stores the data for later analysis.

3

<bt:mbean-persister> enables export of basic statistics mbeans to a JMX server.


Example 3.3. Use a custom SessionContext implementation to specify user IDs

<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.0.xsd
          http://beet.sourceforge.net/schema/bt/1.1        http://beet.sourceforge.net/schema/bt/mtgi-bt-1.1.xsd">
		
   <bt:manager application="myapp">
      <bt:session-context class="com.me.MySessionContextImpl1"/>
   </bt:manager>

1

This class must implement com.mtgi.analytics.SessionContext. The <bt:session-context> element is otherwise a normal Spring bean definition, and may include nested property elements and so on.


Example 3.4. Send tracking data for different packages to different log files

<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.0.xsd
          http://beet.sourceforge.net/schema/bt/1.1        http://beet.sourceforge.net/schema/bt/mtgi-bt-1.1.xsd">
		
   <bt:config>
      <bt:manager id="loggerA1" application="myapp"
                  track-method-expression="execution(* com.mtgi.package_a..*Tracked(..))">
         <bt:xml-persister file="log-a.xml"/>
      </bt:manager>
      <bt:manager id="loggerB" application="myapp"
                  track-method-expression="execution(* com.mtgi.package_b..*Tracked(..))">
         <bt:xml-persister file="log-b.xml"/>2
      </bt:manager>
   </bt:config>

1

When specifying multiple <bt:manager> instances in a single application, you must provide unique IDs for each.

2

An important consequence of having multiple managers in a single application is that each will define a private thread pool for persistence operations. If you want to have them all share a thread pool (which is not a bad idea), use the <bt:manager> attribute "task-executor".


Example 3.5. Integrate beet with other AOP advice

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:bt="http://beet.sourceforge.net/schema/bt/1.1"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
          http://www.springframework.org/schema/tx    http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
          http://beet.sourceforge.net/schema/bt/1.1        http://beet.sourceforge.net/schema/bt/mtgi-bt-1.1.xsd
          http://www.springframework.org/schema/aop   http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
		
   <bt:manager/>1
        
   <bt:advice id="btAdvice"/>2
   <tx:advice id="txAdvice"/>
                
   <aop:config>
      <aop:pointcut id="trackedOperations" expression="execution(* com.mtgi..*Service(..))" />
      <aop:advisor id="behaviorTrackingAdvisor" advice-ref="btAdvice" pointcut-ref="trackedOperations" order="1"/>
      <aop:advisor id="transactionAdvisor" advice-ref="txAdvice" pointcut-ref="trackedOperations" order="2"/>3
   </aop:config>

1

We have intentionally not specified a pointcut expression here, since we're going to be including that with the rest of our AOP config below.

2

If you want to associate behavior tracking advice with a manager other than the default instance, you can use the "tracking-manager" attribute to do so.

3

By specifying a lower order for the behavior tracking advice, we've ensured that behavior tracking metrics include time spent on transaction synchronization.


Example 3.6. Register Beet JMX MBeans

<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.0.xsd
          http://beet.sourceforge.net/schema/bt/1.1        http://beet.sourceforge.net/schema/bt/mtgi-bt-1.1.xsd">
		
   <bt:manager application="myapp" register-mbeans="true"1/>
		

1

This attribute exposes MBeans for both the Beet manager bean and the Beet logging bean. Both of these MBeans are contained in a domain with the application name; in this case, "myapp".

If you want more fine-grained control over which beans are registered, which MBean server registers them, or how they are named, you can use Spring's standard JMX support classes to accomplish this.