Java 类com.codahale.metrics.annotation.Metric 实例源码

项目:metrics-cdi    文件:MetricProducerFieldBeanTest.java   
@Test
@InSequence(3)
public void incrementCountersFromInjection(@Metric(name = "ratioGauge", absolute = true) Gauge<Double> gauge,
                                           @Metric(name = "counter1", absolute = true) Counter counter1,
                                           @Metric(name = "counter2", absolute = true) Counter counter2) {
    counter1.inc(Math.round(Math.random() * Integer.MAX_VALUE));
    counter2.inc(Math.round(Math.random() * Integer.MAX_VALUE));

    assertThat("Gauge value is incorrect", gauge.getValue(), is(equalTo(((double) counter1.getCount()) / ((double) counter2.getCount()))));

    assertThat("Gauge is not registered correctly", registry.getGauges(), hasKey("ratioGauge"));
    @SuppressWarnings("unchecked")
    Gauge<Double> gaugeFromRegistry = (Gauge<Double>) registry.getGauges().get("ratioGauge");

    assertThat("Gauge values from registry and injection do not match", gauge.getValue(), is(equalTo(gaugeFromRegistry.getValue())));
}
项目:dropwizard-hk2    文件:MeterFactoryTest.java   
@Inject
public MeterResource(
    Meter unnamedMeter,
    @Metric(name = "com.metric") Meter metricMeter,
    @Metric(name = "com.absoluteMetric", absolute = true) Meter absoluteMetricMeter
) {
    unnamedMeter.mark(123);
    metricMeter.mark(456);
    absoluteMetricMeter.mark(789);
}
项目:dropwizard-hk2    文件:HistogramFactoryTest.java   
@Inject
public HistogramResource(
    Histogram unnamedHistogram,
    @Metric(name = "com.metric") Histogram metricHistogram,
    @Metric(name = "com.absoluteMetric", absolute = true) Histogram absoluteMetricHistogram
) {
    unnamedHistogram.update(123);
    metricHistogram.update(456);
    absoluteMetricHistogram.update(789);
}
项目:dropwizard-hk2    文件:TimerFactoryTest.java   
@Inject
@Timed
public TimerResource(
    Timer unnamedTimer,
    @Metric(name = "com.metric") Timer metricTimer,
    @Metric(name = "com.absoluteMetric", absolute = true) Timer absoluteMetricTimer
) {
    unnamedTimer.update(123, TimeUnit.DAYS);
    metricTimer.update(123, TimeUnit.MICROSECONDS);
    absoluteMetricTimer.update(123, TimeUnit.MILLISECONDS);
}
项目:dropwizard-hk2    文件:CounterFactoryTest.java   
@Inject
public CounterResource(
    Counter unnamedCounter,
    @Metric(name = "com.metric") Counter metricCounter,
    @Metric(name = "com.absoluteMetric", absolute = true) Counter absoluteMetricCounter
) {
    unnamedCounter.inc();
    metricCounter.inc(2);
    absoluteMetricCounter.inc(3);
}
项目:metrics-cdi    文件:MetricProducerMethodBean.java   
@Produces
@Metric(name = "cache-hits")
Gauge<Double> cacheHitRatioGauge(final @Metric(name = "hits") Meter hits,
                                 final @Metric(name = "calls") Timer calls) {
    return new RatioGauge() {
        @Override
        protected Ratio getRatio() {
            return Ratio.of(hits.getCount(), calls.getCount());
        }
    };
}
项目:metrics-cdi    文件:MonotonicCountedMethodBeanTest.java   
@Test
@InSequence(2)
public void countedMethodNotCalledYet(@Metric(name = "monotonicCountedMethod", absolute = true) Counter instance) {
    assertThat("Counter is not registered correctly", registry.getCounters(), hasKey(COUNTER_NAME));
    Counter counter = registry.getCounters().get(COUNTER_NAME);

    // Make sure that the counter registered and the bean instance are the same
    assertThat("Counter and bean instance are not equal", instance, is(equalTo(counter)));
}
项目:metrics-cdi    文件:GaugeInjectionBeanTest.java   
@Test
@InSequence(2)
public void callGaugeAfterSetterCall(@Metric(absolute = true, name = "io.astefanutti.metrics.cdi.se.GaugeMethodBean.gaugeMethod") Gauge<Long> gauge) {
    // Call the setter method and assert the gauge is up-to-date
    long value = 1L + Math.round(Math.random() * (Long.MAX_VALUE - 1L));
    bean.setGauge(value);

    assertThat("Gauge value is incorrect", gauge.getValue(), is(equalTo(value)));
}
项目:metrics-cdi    文件:CountedMethodBeanTest.java   
@Test
@InSequence(2)
public void countedMethodNotCalledYet(@Metric(name = "countedMethod", absolute = true) Counter instance) {
    assertThat("Counter is not registered correctly", registry.getCounters(), hasKey(COUNTER_NAME));
    Counter counter = registry.getCounters().get(COUNTER_NAME);

    // Make sure that the counter registered and the bean instance are the same
    assertThat("Counter and bean instance are not equal", instance, is(equalTo(counter)));
}
项目:metrics-cdi    文件:SeMetricName.java   
@Override
public String of(AnnotatedMember<?> member) {
    if (member.isAnnotationPresent(Metric.class)) {
        Metric metric = member.getAnnotation(Metric.class);
        String name = (metric.name().isEmpty()) ? member.getJavaMember().getName() : of(metric.name());
        return metric.absolute() | parameters.contains(useAbsoluteName) ? name : MetricRegistry.name(member.getJavaMember().getDeclaringClass(), name);
    } else {
        return parameters.contains(useAbsoluteName) ? member.getJavaMember().getName() : MetricRegistry.name(member.getJavaMember().getDeclaringClass(), member.getJavaMember().getName());
    }
}
项目:metrics-cdi    文件:SeMetricName.java   
private String of(AnnotatedParameter<?> parameter) {
    if (parameter.isAnnotationPresent(Metric.class)) {
        Metric metric = parameter.getAnnotation(Metric.class);
        String name = (metric.name().isEmpty()) ? getParameterName(parameter) : of(metric.name());
        return metric.absolute() | parameters.contains(useAbsoluteName) ? name : MetricRegistry.name(parameter.getDeclaringCallable().getJavaMember().getDeclaringClass(), name);
    } else {
        return parameters.contains(useAbsoluteName) ? getParameterName(parameter) : MetricRegistry.name(parameter.getDeclaringCallable().getJavaMember().getDeclaringClass(), getParameterName(parameter));
    }
}
项目:Camel    文件:Application.java   
@Produces
@Metric(name = "success-ratio")
// Register a custom gauge that's the ratio of the 'success' meter on the 'generated' meter
Gauge<Double> successRatio(Meter success, Meter generated) {
    return () -> Ratio.of(success.getOneMinuteRate(), generated.getOneMinuteRate()).getValue();
}
项目:camel-cdi    文件:Application.java   
@Produces
@Metric(name = "success-ratio")
Gauge<Double> successRatio(Meter generated, Meter success) {
    return () -> Ratio.of(success.getOneMinuteRate(), generated.getOneMinuteRate()).getValue();
}
项目:metrics-cdi    文件:MetricProducerMethodBeanJava8.java   
@Produces
@Metric(name = "cache-hits")
Gauge<Double> cacheHitRatioGauge(Meter hits, Timer calls) {
    return () -> Ratio.of(hits.getCount(), calls.getCount()).getValue();
}
项目:metrics-cdi    文件:MetricProducerMethodBean.java   
@Produces
@Metric(name = "not_registered_metric")
Counter not_registered_metric(MetricRegistry registry, InjectionPoint ip) {
    return registry.counter("not_registered_metric");
}