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.