javadropwizardmetricsyammer

getting a one minute rate using yammer metrics timer


I'm very new to java and metrics. Can someone help me to understand the problem below and perhaps also clear up the situation between dropwizard and yammer metrics for me (e.g. if I type yammer.metrics into google all the documentation points to dropwizard)?

I'd like to implement a timer using yammer metrics, however, I'm finding the examples online confusing.

For example, using yammer metrics I can do the following:

import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Meter;
import com.yammer.metrics.core.Timer;

...

public static Timer responses = Metrics.defaultRegistry().newTimer(myClass.class, "timer-name");

However, having done that I'm not sure how to use the timer, because all the documents that I can find give the following (dropwizard) example:

final Timer.Context context = responses.time();
    try {
        // intense code;
        return "OK";
    } finally {
        context.stop();
    }

This doesn't work because the Yammer Timer doesn't support Context only the dropwizard Timer does. In order to get the above code to work I need to do the following;

import com.codahale.metrics.*;
import java.util.concurrent.TimeUnit;

private final static MetricRegistry metrics = new MetricRegistry();
private final static Timer responses = metrics.timer(name(myClass.class, "timer-name"));

now I have a Timer that supports Context.

All our code imports com.yammer.metrics and I'd like to keep using it if possible. So how do I record events such that I can get, for example, responses.oneMinuteRate() using yammer.Metrics?


Solution

  • com.yammer.metrics is old library.

    com.yammer.metrics:metrics-core:2.2.0 (up to 2012 year)
    

    They had major move in 2012 to:

    com.codahale.metrics:metrics-core:3.0.* (2013-2014 year)
    

    all packaged were renamed to com.codahale.metrics

    Then they they moved artifacts again to:

    io.dropwizard.metrics:metrics-core:3.1.*
    

    com.yammer.metrics is not supported now and it's not backward compatible with new versions