I think I got this working.
The first thing I noticed was that the URI in the schemaLocation attribute of the sample spring context file: http://www.yammer.com/schema/metrics/metrics.xsd returns a 404 error.
I googled the issue to see if anyone had complained about the schema being unreachable and found this thread, github.com/codahale/metrics/issues/322, wherein a user comments that the metrics-spring module has been removed from the core metrics repository and moved to: github.com/ryantenney/metrics-spring.
Following the example on that website, I stripped out the old metrics-spring dependency from my pom and added the following:
<dependency>
<groupId>com.ryantenney.metrics</groupId>
<artifactId>metrics-spring</artifactId>
<version>2.1.4</version>
</dependency>
I then updated the xmlns declaration in my spring-context.xml file:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:metrics="http://www.ryantenney.com/schema/metrics"
xsi:schemaLocation="
http://www.ryantenney.com/schema/metrics
http://www.ryantenney.com/schema/metrics/metrics.xsd
...other schemas...">
Added the annotation-driven element:
<metrics:annotation-driven proxy-target-class="true" />
I enabled proxy-target-class to get class based autowiring working.
And in the bean I wanted to Time added the @Timed annotation and a @PostConstruct method to enable a ConsoleReporter to dump stats every 10 secs:
@PostConstruct
public void init() {
ConsoleReporter.enable(10, TimeUnit.SECONDS);
}
@Timed
public void doService(...) {
.... do stuff ....
}
I then started up my webapp .... and got a nasty error from the sax parser parsing the spring context.xml file.
It seems that www.ryantenney.com/schema/metrics/metrics.xsd 404s as well!
The workaround for this was simple, however, I downloaded the xsd from the github repository: https://github.com/ryantenney/metrics-spring/blob/master/src/main/resources/com/ryantenney/metrics/spring/config/metrics-3.0.xsd
and then in the src/main/resources/META-INF directory of my maven project added the following files:
META-INF/
- spring.schemas
- xsd/
- metrics.xsd
where metrics.xsd is the xsd file downloaded from github, and spring.schemas is a text file containing:
http\://www.ryantenney.com/schema/metrics/metrics.xsd=META-INF/xsd/metrics.xsd
The spring.schemas file is read by spring at startup and tells it to pull down the xsd from the local file.
With the above in place I was able to successfully fire up my app and hit the endpoint that used the service method.
Watching the console I did indeed see the following dumped every 10 seconds:
com.sample.service.MyServiceClass:
doService:
count = 8
mean rate = 0.27 calls/s
1-minute rate = 0.23 calls/s
5-minute rate = 0.21 calls/s
15-minute rate = 0.20 calls/s
min = 0.13ms
max = 19.59ms
mean = 2.59ms
stddev = 6.87ms
median = 0.18ms