@Override public void mark(long n) { delegate.mark(n); }
@Override public void mark() { delegate.mark(); }
@Override protected Object prepareAndInvoke(Meter meter, Metered annotation, InvocationContext context) throws Exception { meter.mark(); return context.proceed(); } }
private void update(long nanos) { if (nanos >= 0) { histogram.update(nanos); meter.mark(); } }
@Override public void update(Routing.Rules rules) { // register the metric registry and factory to be available to all rules.any((req, res) -> { req.context().register(app); req.context().register(rf); totalCount.inc(); totalMeter.mark(); req.next(); }); rules.anyOf(CollectionsHelper.listOf(Http.Method.GET, Http.Method.OPTIONS), JsonSupport.create()); // routing to root of metrics rules.get(context, (req, res) -> getMultiple(req, res, base, app, vendor)) .options(context, (req, res) -> optionsMultiple(req, res, base, app, vendor)); // routing to each scope Stream.of(app, base, vendor) .forEach(registry -> { String type = registry.type(); rules.get(context + "/" + type, (req, res) -> getAll(req, res, registry)) .get(context + "/" + type + "/{metric}", (req, res) -> getOne(req, res, registry)) .options(context + "/" + type, (req, res) -> optionsAll(req, res, registry)) .options(context + "/" + type + "/{metric}", (req, res) -> optionsOne(req, res, registry)); }); }
@Override protected Object prepareAndInvoke(Meter meter, Metered annotation, InvocationContext context) throws Exception { meter.mark(); return context.proceed(); } }
@Timed(name = "calls") public void cachedMethod(boolean hit) { if (hit) { hits.mark(); } }
@Override public void update(final long duration, final TimeUnit unit) { if (duration >= 0) { histogram.update(unit.toNanos(duration)); meter.mark(); } }
public void meterMe() { Meter meter = metrics.meter("metricTest.test1.meter"); meter.mark(); }
@AroundInvoke public Object onMethod(final InvocationContext context) throws Exception { findMeter(context.getMethod()).mark(); return context.proceed(); }
@Override public void onTimeout(AsyncEvent event) throws IOException { context.stop(); activeRequests.dec(); timeoutsMeter.mark(); done = true; }
@Override public void onError(AsyncEvent event) throws IOException { context.stop(); activeRequests.dec(); errorsMeter.mark(); done = true; }
@AroundConstruct public Object onConstructor(final InvocationContext context) throws Exception { findMeter(context.getConstructor()).mark(); return context.proceed(); }
private <E extends Member & AnnotatedElement> Object applyInterceptor(InvocationContext context, E member) throws Exception { Metadata metadata = AnnotationMetadata.buildMetadata(bean.getBeanClass(), member, Metered.class); Meter meter = applicationRegistry.getMeters().get(metadata.getName()); if (meter == null) { throw new IllegalStateException("No meter with name [" + metadata.getName() + "] found in registry [" + applicationRegistry + "]"); } meter.mark(); return context.proceed(); } }
@Test public void testCount() throws Exception { // test mark() long countBefore = injectedMeter.getCount(); injectedMeter.mark(); long countAfter = injectedMeter.getCount(); Assert.assertEquals(countBefore + 1, countAfter); // test mark(2) countBefore = injectedMeter.getCount(); injectedMeter.mark(2); countAfter = injectedMeter.getCount(); Assert.assertEquals(countBefore + 2, countAfter); // test mark(-3) countBefore = injectedMeter.getCount(); injectedMeter.mark(-3); countAfter = injectedMeter.getCount(); Assert.assertEquals(countBefore - 3, countAfter); }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final StatusExposingServletResponse wrappedResponse = new StatusExposingServletResponse((HttpServletResponse) response); activeRequests.inc(); final Timer.Context context = requestTimer.time(); boolean error = false; try { chain.doFilter(request, wrappedResponse); } catch (IOException | RuntimeException | ServletException e) { error = true; throw e; } finally { if (!error && request.isAsyncStarted()) { request.getAsyncContext().addListener(new AsyncResultListener(context)); } else { context.stop(); activeRequests.dec(); if (error) { errorsMeter.mark(); } else { markMeterForStatusCode(wrappedResponse.getStatus()); } } } }
meter.mark(count); Thread.sleep(1000);