public class HistogramFieldBean { @Inject @Metric(name = "histogramName") private Histogram histogram; public void update(long n) { histogram.update(n); } }
public class CounterFieldBean { @Inject @Metric(name = "counterName") private Counter counter; public void increment(long n) { counter.inc(n); } }
@Produces @Metric(name = "not_registered_metric") Counter not_registered_metric(MetricRegistry registry, InjectionPoint ip) { return registry.counter("not_registered_metric"); } }
public class TimerFieldBean { @Inject Timer timerWithoutAnnotation; @Inject @Metric(absolute = false) Timer timerWithExplicitNonAbsoluteName; @Inject @Metric Timer timerWithNoName; @Inject @Metric(name = "timerName") Timer timerWithName; @Inject @Metric(absolute = true) Timer timerWithAbsoluteDefaultName; @Inject @Metric(name = "timerAbsoluteName", absolute = true) Timer timerWithAbsoluteName; }
@ApplicationScoped public class MetricProducerFieldBean { @Produces @Metric(name = "counter1", absolute = true) private final Counter counter1 = new Counter(); @Produces @Metric(name = "counter2", absolute = true) private final Counter counter2 = new Counter(); @Produces @Metric(name = "ratioGauge", absolute = true) private final Gauge<Double> gauge = () -> Ratio.of(counter1.getCount(), counter2.getCount()).getValue(); // TODO: add assertions in the corresponding test @Produces private final Histogram histogram = new Histogram(new SlidingTimeWindowReservoir(1L, TimeUnit.SECONDS)); @Produces @FooQualifier @Metric(name = "not_registered_metric", absolute = true) private final Counter not_registered_metric = new Counter(); }
@Produces @Metric(name = "cache-hits") Gauge<Double> cacheHitRatioGauge(Meter hits, Timer calls) { return () -> Ratio.of(hits.getCount(), calls.getCount()).getValue(); }