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

项目:dropwizard-hk2    文件:GaugeAnnotationActivator.java   
@Override
protected void activate(ActiveDescriptor<?> handle, Object service, Method method, Gauge annotation) {
    if (method.getParameterCount() != 0) {
        log.error("@Gauge placed on method {} which must have zero parameters, but has {}", method, method.getParameterCount());
        return;
    }
    com.codahale.metrics.Gauge<?> gauge = () -> {
        try {
            return method.invoke(service);
        } catch (Exception e) {
            throw new RuntimeException("Failed to read gauge value from " + method, e instanceof InvocationTargetException ? (
                (InvocationTargetException) e
            ).getTargetException() : e);
        }
    };
    String name = metricNameService.getFormattedMetricName(method, com.codahale.metrics.Gauge.class);
    log.debug("Activating gauge {} monitoring {}", name, method);
    metricRegistry.register(name, gauge);
}
项目:metrics-cdi    文件:MetricResolver.java   
private String metricName(Annotation annotation) {
    if (CachedGauge.class.isInstance(annotation))
        return ((CachedGauge) annotation).name();
    else if (Counted.class.isInstance(annotation))
        return ((Counted) annotation).name();
    else if (ExceptionMetered.class.isInstance(annotation))
        return ((ExceptionMetered) annotation).name();
    else if (Gauge.class.isInstance(annotation))
        return ((Gauge) annotation).name();
    else if (Metered.class.isInstance(annotation))
        return ((Metered) annotation).name();
    else if (Timed.class.isInstance(annotation))
        return ((Timed) annotation).name();
    else
        throw new IllegalArgumentException("Unsupported Metrics forMethod [" + annotation.getClass().getName() + "]");
}
项目:metrics-cdi    文件:MetricResolver.java   
private boolean isMetricAbsolute(Annotation annotation) {
    if (extension.getParameters().contains(MetricsParameter.useAbsoluteName))
        return true;

    if (CachedGauge.class.isInstance(annotation))
        return ((CachedGauge) annotation).absolute();
    else if (Counted.class.isInstance(annotation))
        return ((Counted) annotation).absolute();
    else if (ExceptionMetered.class.isInstance(annotation))
        return ((ExceptionMetered) annotation).absolute();
    else if (Gauge.class.isInstance(annotation))
        return ((Gauge) annotation).absolute();
    else if (Metered.class.isInstance(annotation))
        return ((Metered) annotation).absolute();
    else if (Timed.class.isInstance(annotation))
        return ((Timed) annotation).absolute();
    else
        throw new IllegalArgumentException("Unsupported Metrics forMethod [" + annotation.getClass().getName() + "]");
}
项目:metrics-aspectj    文件:MultipleMetricsStaticMethod.java   
@ExceptionMetered(name = "exception")
@Gauge(name = "gauge")
@Metered(name = "meter")
@Timed(name = "timer")
public static String metricsMethod() {
    return "value";
}
项目:metrics-aspectj    文件:MultipleMetricsMethod.java   
@ExceptionMetered(name = "exception")
@Gauge(name = "gauge")
@Metered(name = "meter")
@Timed(name = "timer")
public String metricsMethod() {
    return "value";
}
项目:metrics-aspectj    文件:MultipleMetricsMethodWithRegistryFromBeanProperty.java   
@ExceptionMetered(name = "exception")
@Gauge(name = "gauge")
@Metered(name = "meter")
@Timed(name = "timer")
public String metricsMethod() {
    return "value";
}
项目:stagemonitor    文件:GaugeTransformer.java   
public static void monitorGauges(Object object) {
    for (final Method method : object.getClass().getDeclaredMethods()) {
        final Gauge gaugeAnnotation = method.getAnnotation(Gauge.class);
        // only create gauge, if method takes no parameters and is non-void
        if (gaugeAnnotation != null && methodTakesNoParamsAndIsNonVoid(method)) {
            method.setAccessible(true);
            final String signature = SignatureUtils.getSignature(object.getClass().getName(), method.getName(),
                    gaugeAnnotation.name(), gaugeAnnotation.absolute());

            registerGauge(object, method, signature);
        }
    }
}
项目:stagemonitor    文件:GaugeTransformer.java   
private static void registerGauge(final Object object, final Method method, final String signature) {
    Stagemonitor.getMetric2Registry().registerNewMetrics(name("gauge_" + signature).build(), new com.codahale.metrics.Gauge() {
        @Override
        public Object getValue() {
            try {
                return method.invoke(object);
            } catch (Exception e) {
                logger.warn("Error occurred while invoking gauge {}: {}", signature, e.getMessage());
                return null;
            }
        }
    });
}
项目:metrics-cdi    文件:MultipleMetricsMethodBean.java   
@Counted(name = "counter", monotonic = true)
@ExceptionMetered(name = "exception")
@Gauge(name = "gauge")
@Metered(name = "meter")
@Timed(name = "timer")
public String metricsMethod() {
    return "value";
}
项目:dropwizard-hk2    文件:GaugeAnnotationActivator.java   
@Inject
public GaugeAnnotationActivator(@NonNull MetricRegistry metricRegistry, @NonNull MetricNameService metricNameService) {
    super(Gauge.class);
    this.metricRegistry = metricRegistry;
    this.metricNameService = metricNameService;
}
项目:codenvy    文件:InMemoryTicketManager.java   
/** @return number of access tickets. */
@Gauge(name = "auth.sso.access_ticket_number")
public int size() {
  return accessTickets.size();
}
项目:metrics-aspectj    文件:GaugeStaticMethodWithRegistryFromString.java   
@Gauge(name = "singleGaugeStaticMethod")
public static long getSingleGauge() {
    return singleStaticGauge;
}
项目:metrics-aspectj    文件:GaugeMethodWithRegistryFromString.java   
@Gauge(name = "singleGaugeMethod")
public long getSingleGauge() {
    return singleGauge;
}
项目:metrics-aspectj    文件:GaugeMethodWithVisibilityModifiers.java   
@Gauge(name = "publicGaugeMethod")
public long getPublicGaugeMethod() {
    return publicGauge;
}
项目:metrics-aspectj    文件:GaugeMethodWithVisibilityModifiers.java   
@Gauge(name = "packagePrivateGaugeMethod")
long getPackagePrivateGauge() {
    return packagePrivateGauge;
}
项目:metrics-aspectj    文件:GaugeMethodWithVisibilityModifiers.java   
@Gauge(name = "protectedGaugeMethod")
protected long getProtectedGauge() {
    return protectedGauge;
}
项目:metrics-aspectj    文件:GaugeMethodWithVisibilityModifiers.java   
@Gauge(name = "privateGaugeMethod")
private long getPrivateGauge() {
    return privateGauge;
}
项目:arsnova-backend    文件:UserServiceImpl.java   
@Override
@Gauge
public int loggedInUsers() {
    return user2session.size();
}
项目:stagemonitor    文件:GaugeTestObject.java   
@Gauge
private int gaugeDefault() {
    return 1;
}
项目:stagemonitor    文件:GaugeTestObject.java   
@Gauge
public static int staticGaugeDefault() {
    return 1;
}
项目:stagemonitor    文件:GaugeTestObject.java   
@Gauge(absolute = true)
public void gaugeAbsolute() {
}
项目:stagemonitor    文件:GaugeTestObject.java   
@Gauge(name = "myGaugeName")
public void gaugeName() {
}
项目:stagemonitor    文件:GaugeTestObject.java   
@Gauge(name = "myGaugeNameAbsolute", absolute = true)
public void gaugeNameAbsolute() {
}
项目:metrics-cdi    文件:InheritedGaugeMethodBean.java   
@Gauge(name = "childGaugeMethod")
public long getChildGauge() {
    return childGauge;
}
项目:metrics-cdi    文件:GaugeMethodBean.java   
@Gauge(name = "gaugeMethod")
public long getGauge() {
    return gauge;
}
项目:metrics-cdi    文件:MetricsInterceptor.java   
private CachingGauge(com.codahale.metrics.Gauge<?> gauge, long timeout, TimeUnit timeoutUnit) {
    super(timeout, timeoutUnit);
    this.gauge = gauge;
}
项目:metrics-cdi    文件:MetricResolver.java   
Of<Gauge> gauge(Class<?> topClass, Method method) {
    return resolverOf(topClass, method, Gauge.class);
}
项目:metrics-cdi    文件:MetricsExtension.java   
private <X> void metricsAnnotations(@Observes @WithAnnotations({CachedGauge.class, Counted.class, ExceptionMetered.class, Gauge.class, Metered.class, Timed.class}) ProcessAnnotatedType<X> pat) {
    pat.setAnnotatedType(new AnnotatedTypeDecorator<>(pat.getAnnotatedType(), METRICS_BINDING));
}