Skip to content

Instantly share code, notes, and snippets.

@kohsuke
Created March 25, 2014 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kohsuke/9753189 to your computer and use it in GitHub Desktop.
Save kohsuke/9753189 to your computer and use it in GitHub Desktop.

Adding Custom Metric subtype

To implement a new metric subtype, implement ExtensionMetric marker interface and put @MetricExtension on it

@NamedMetric("dac.mansion.foo.bar") @Singleton
public class MyGauge extends Gauge<Integer> implements ExtensionMetric {
     @Override
     public Integer getValue() {
         return queue.size();
     }
 }

To define metrics that does not need any custom subtypes, define an extension module and list metrics:

@Extension
public class MyModule extends MetricModule {
    protected void configure() {
        counter("dac.mansion.foo");
        counter("dac.mansion.bar");
        histogram("dac.mansion.zot");
    }
}

In either case, you can then inject them where you need them:

@Inject @NamedMetric("dac.mansion.foo")
Counter foo;

@Inject @NamedMetric("dac.mansion.foo.bar")
MyGauge my;

You can also inject MetricRegistry and do whatever you want to do with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment