Skip to content

mattcarrier/metrics-aspectj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Aspect-oriented metrics based on codahale/metrics and aspectj.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages