Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Purpose

The purpose of this aspect is to report arbitrary method execution response time to a JMX server.
It is easily configurable to gather the metrics on a per class, package, application, etc basis and thus report averages metrics as well.

This aspect has been demonstrated during JavaOne 2004 in the "AOP in J2EE environments with AspectWerkz" session.
Download the JavaOne 2004 slides.

Usage

In order to be able to use this aspect, you need to declare it in your META-INF/aop.xml file and bind the advice named "monitor" of type "around" to any method execution pointcuts (actually it can work for any pointcut type if you want to).

One JMX mbean will be created per target method/constructor/field signature by default. See the next section for more configuration.

The mbeans will be registered lazyly in the default (local) JMX server. For use with BEA WebLogic Server 6, 7 and 8 and for other schemes, see the next section.

Here is a sample META-INF/aop.xml file:

Code Block
xml
xml

<!DOCTYPE aspectwerkz PUBLIC
    "-//AspectWerkz//DTD//EN"
    "http://aspectwerkz.codehaus.org/dtd/aspectwerkz.dtd">
<aspectwerkz>
    <system id="aware-jmx">
        <!-- make use of defaults granularity and server -->
        <aspect class="org.codehaus.aware.jmx.ResponseTimeAspect">
            <advice name="monitor" type="around"
                    bind-to="execution(!static * test.jmx.ResponseTimeObject.*(..)) AND !execution(* *..*.freeze(..))"/>
        </aspect>
  </system>
</aspectwerkz>

Reporting response time averages

To change the granularity of the reported metrics, which defaults to one mbean per target method/constructor/field signature you need to use the aspect parameter "granularity".

This parameter will specify a class that implements the org.codehaus.aware.jmx.ResponseTimeAspect.IGranularity interface below:

Code Block
java
java

public class ResponseTimeAspect {
    /**
     * Granularity interface to determine which mbean to update given a specific joinpoint signature.
     *
     */
    public static interface IGranularity {
        /**
         * Compute a suitable key given a signature. The mbeans will be register on a per key basis, and it is thus
         * advised to have suitable hashcode(), equals() and toString() implementation for it.
         *
         * @param signature
         * @return
         */
        public Object getKeyFor(Signature signature);
    }
}

AWare provides an implementation which is able to compute a global average. Here is how it has been written. You can refer to AspectWerkz documentation about the org.codehaus.aspectwerkz.joinpoint.Signature interface to write your own:

Code Block
java
java

public class AverageGranularity implements IGranularity {
    public Object getKeyFor(Signature signature) {
        // to compute a global average, just always return the same value
        return "Average";
    }
}

This class is provided in AWare as org.codehaus.aware.jmx.ResponseTimeAspect.AverageGranularity. Since it is a static inner class, we will have to use it under the name "org.codehaus.aware.jmx.ResponseTimeAspect$AverageGranularity" (with a $ sign) :

To use your custom granularity the META-INF/aop.xml file will look like the following. Note that we are using the ResponseTimeAspect twice, once with default granularity and once with average granularity, and thus we specify an aspect "name".

Code Block
xml
xml

<!DOCTYPE aspectwerkz PUBLIC
"-//AspectWerkz//DTD//EN"
"http://aspectwerkz.codehaus.org/dtd/aspectwerkz.dtd">
<aspectwerkz>
<system id="aware-jmx">
<!-- make use of defaults granularity and server -->
<aspect class="org.codehaus.aware.jmx.ResponseTimeAspect">
<advice name="monitor" type="around"
bind-to="execution(!static * test.jmx.ResponseTimeObject.(..)) AND !execution( ...freeze(..))"/>
</aspect>
<!-- make use of custom granularity -->
<aspect class="org.codehaus.aware.jmx.ResponseTimeAspect" name="MyAverageResponseTimeAspect">
<param name="granularity" value="org.codehaus.aware.jmx.ResponseTimeAspect$AverageGranularity"/>
<advice name="monitor" type="around"
bind-to="execution(!static * test.jmx.ResponseTimeObject.(..)) AND !execution( ...freeze(..))"/>
</aspect>
</system>
</aspectwerkz>