public TimedMetricsFilter(MetricRegistry metricRegistry, ResourceInfo resourceInfo) { final Timed annotation = resourceInfo.getResourceMethod().getAnnotation(Timed.class); timer = metricRegistry.timer(chooseName(annotation.name(), annotation.absolute(), resourceInfo.getResourceMethod())); }
final String name = chooseName(annotation.name(), annotation.absolute(), task);
@Override protected NamingParameters getNamingParameters(MethodDescription instrumentedMethod) { if (instrumentedMethod.getDeclaredAnnotations().isAnnotationPresent(Timed.class)) { final Timed timed = instrumentedMethod.getDeclaredAnnotations().ofType(Timed.class).loadSilent(); return new NamingParameters(timed.name(), timed.absolute()); } else { return new NamingParameters("", false); } }
static String forTimedMethod(Class<?> klass, Member member, Timed annotation) { return chooseName(annotation.name(), annotation.absolute(), klass, member); }
@Override public String getName(Timed annotation) { return annotation.name(); }
@Nonnull @Override public String getNameForTimed(@Nonnull Method method, @Nonnull Timed timed) { if (timed.absolute()) { return timed.name(); } if (timed.name().isEmpty()) { return name(method.getDeclaringClass(), method.getName(), TIMED_SUFFIX); } return name(method.getDeclaringClass(), timed.name()); } }
@Nonnull @Override public String getNameForTimed(@Nonnull Method method, @Nonnull Timed timed) { if (timed.absolute()) { return timed.name(); } if (timed.name().isEmpty()) { return name(method.getDeclaringClass(), method.getName(), TIMED_SUFFIX); } return name(method.getDeclaringClass(), timed.name()); } }
@AroundInvoke Object timeMethod(InvocationContext context) throws Exception { String name = context.getMethod().getAnnotation(Timed.class).name(); Timer timer = registry.timer(name); Timer.Context time = timer.time(); try { return context.proceed(); } finally { time.stop(); } } }
/** * Factory method for TimedInvoker. */ private Invoker timed(Invoker invoker, List<Method> timedMethods) { ImmutableMap.Builder<String, Timer> timers = new ImmutableMap.Builder<>(); for (Method m : timedMethods) { Timed annotation = m.getAnnotation(Timed.class); final String name = chooseName(annotation.name(), annotation.absolute(), m); Timer timer = metricRegistry.timer(name); timers.put(m.getName(), timer); } return new InstrumentedInvokers.TimedInvoker(invoker, timers.build()); }
public EventDriverMetrics(final Class<?> endpointClass, MetricRegistry metrics) { final Class<?> klass = endpointClass; Metered metered = klass.getAnnotation(Metered.class); Timed timed = klass.getAnnotation(Timed.class); ExceptionMetered em = klass.getAnnotation(ExceptionMetered.class); this.onTextMeter = metered != null ? Optional.of(metrics.meter(MetricRegistry.name(metered.name(), klass.getName(), OnMessage.class.getSimpleName()))) : Optional.empty(); this.countOpened = metered != null ? Optional.of(metrics.counter(MetricRegistry.name(metered.name(), klass.getName(), OPEN_CONNECTIONS))) : Optional.empty(); this.timer = timed != null ? Optional.of(metrics.timer(MetricRegistry.name(timed.name(), klass.getName()))) : Optional.empty(); this.exceptionMetered = em != null ? Optional.of(metrics.meter(MetricRegistry.name(em.name(), klass.getName(), OnError.class.getSimpleName()))) : Optional.empty(); } public static final String OPEN_CONNECTIONS = "openConnections";
public EventDriverMetrics(final Class<?> endpointClass, MetricRegistry metrics) { final Class<?> klass = endpointClass; Metered metered = klass.getAnnotation(Metered.class); Timed timed = klass.getAnnotation(Timed.class); ExceptionMetered em = klass.getAnnotation(ExceptionMetered.class); this.onTextMeter = metered != null ? Optional.of(metrics.meter(MetricRegistry.name(metered.name(), klass.getName(), OnMessage.class.getSimpleName()))) : Optional.empty(); this.countOpened = metered != null ? Optional.of(metrics.counter(MetricRegistry.name(metered.name(), klass.getName(), OPEN_CONNECTIONS))) : Optional.empty(); this.timer = timed != null ? Optional.of(metrics.timer(MetricRegistry.name(timed.name(), klass.getName()))) : Optional.empty(); this.exceptionMetered = em != null ? Optional.of(metrics.meter(MetricRegistry.name(em.name(), klass.getName(), OnError.class.getSimpleName()))) : Optional.empty(); } public static final String OPEN_CONNECTIONS = "openConnections";
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() + "]"); }
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() + "]"); }
public TimedMetricsFilter(MetricRegistry metricRegistry, ResourceInfo resourceInfo) { final Timed annotation = resourceInfo.getResourceMethod().getAnnotation(Timed.class); timer = metricRegistry.timer(chooseName(annotation.name(), annotation.absolute(), resourceInfo.getResourceMethod())); }
public TimedMetricsFilter(MetricRegistry metricRegistry, ResourceInfo resourceInfo) { final Timed annotation = resourceInfo.getResourceMethod().getAnnotation(Timed.class); timer = metricRegistry.timer(chooseName(annotation.name(), annotation.absolute(), resourceInfo.getResourceMethod())); }
private Timer timerMetric(final MetricRegistry registry, final ResourceMethod method, final Timed timed, final String... suffixes) { final String name = chooseName(timed.name(), timed.absolute(), method, suffixes); return registry.timer(name, () -> new Timer(new ExponentiallyDecayingReservoir(), clock)); }
final String name = chooseName(annotation.name(), annotation.absolute(), task);
@Test public void throwExceptionOnInitialization() throws NoSuchMethodException { exception.expect(UnsupportedOperationException.class); String name = TimedMethodWithNameFromElExpression.class.getMethod("expressionTimedMethod").getAnnotation(Timed.class).name(); exception.expectMessage("Unsupported EL expression [" + name + "] evaluation as no EL implementation is available"); TimedMethodWithNameFromElExpression instance = new TimedMethodWithNameFromElExpression("timer"); } }
final String name = chooseName(annotation.name(), annotation.absolute(), method); final Timer timer = registry.timer(name); dispatcher = new TimedRequestDispatcher(dispatcher, timer);