Skip to content

Latest commit

 

History

History
84 lines (73 loc) · 2.57 KB

README.md

File metadata and controls

84 lines (73 loc) · 2.57 KB

metrics-aspectj Build Status

About

Extremely small wrapper library that provides an aspect-oriented method for implanting codahale/metrics based on aspectj. The library surrounds all annotated methods with a lightweight around advice.

Usage

Extend MetricAdvice to provide an aspect scope:

@Aspect
public class MetricAdviceImpl extends MetricAdvice {
    @Pointcut("within(org.mattcarrier.metrics.aspectj..*)")
    public void scope() {
    }
}

Annotate methods to add metrics:

...
@Timed
@Metered
@ExceptionMetered
public void allTheMetrics() {
    throw new RuntimeException("burp");
}
...

Weave the aspects (example is of compile-time weave using maven):

...
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.4</version>
    <configuration>
        <showWeaveInfo>true</showWeaveInfo>
        <source>${compile.version}</source>
        <target>${compile.version}</target>
        <Xlint>ignore</Xlint>
        <complianceLevel>${compile.version}</complianceLevel>
        <encoding>UTF-8</encoding>
        <verbose>false</verbose>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
                <goal>test-compile</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjtools</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
    </dependencies>
</plugin>
...

Set the MetricRegistry during application startup:

...
MetricRegistryStore.getInstance().setRegistry(new MetricRegistry());
...

// if using dropwizard
public void run(Configuration configuration, Environment environment) throws Exception {
    MetricRegistryStore.getInstance().setRegistry(environment.metrics());
    ...
}

License

Apache Software License 2.0
Copyright (c) 2013 Matt Carrier