Package com.codahale.metrics

Examples of com.codahale.metrics.Meter


    assertEquals(0, quadruple_Counted.getCount());
  }

  @Test
  public void varargsMeteredMethod() {
    Meter varargs = metricRegistry.getMeters().get(MetricRegistry.name(MeteredClass.class.getCanonicalName(), "varargs-metered"));

    assertNotNull("Meter was not created for varargs method", varargs);

    assertEquals(0, varargs.getCount());

    meteredClass.varargsMeteredMethod();

    assertEquals(1, varargs.getCount());
  }
View Full Code Here


    assertEquals(2, overloaded_param.getCount());
  }

  @Test
  public void overloadedMeteredMethod() {
    Meter overloaded = metricRegistry.getMeters().get(MetricRegistry.name(MeteredClass.class.getCanonicalName(), "overloaded-metered"));
    Meter overloaded_param = metricRegistry.getMeters().get(MetricRegistry.name(MeteredClass.class.getCanonicalName(), "overloaded-metered-param"));

    assertEquals(0, overloaded.getCount());
    assertEquals(0, overloaded_param.getCount());

    meteredClass.overloadedMeteredMethod();

    assertEquals(1, overloaded.getCount());
    assertEquals(0, overloaded_param.getCount());

    meteredClass.overloadedMeteredMethod(1);

    assertEquals(1, overloaded.getCount());
    assertEquals(1, overloaded_param.getCount());

    meteredClass.overloadedMeteredMethod(1);

    assertEquals(1, overloaded.getCount());
    assertEquals(2, overloaded_param.getCount());
  }
View Full Code Here

    assertEquals(0, overloaded_param.getCount());
  }

  @Test
  public void overloadedExceptionMeteredMethod() throws Throwable {
    Meter overloaded = metricRegistry.getMeters().get(MetricRegistry.name(MeteredClass.class.getCanonicalName(), "overloaded-exception-metered"));
    Meter overloaded_param = metricRegistry.getMeters().get(
        MetricRegistry.name(MeteredClass.class.getCanonicalName(), "overloaded-exception-metered-param"));

    assertEquals(0, overloaded.getCount());
    assertEquals(0, overloaded_param.getCount());

    // doesn't throw an exception
    meteredClass.overloadedExceptionMeteredMethod(null);
    assertEquals(0, overloaded.getCount());
    assertEquals(0, overloaded_param.getCount());

    // throws the wrong exception
    try {
      meteredClass.overloadedExceptionMeteredMethod(RuntimeException.class);
      fail();
    }
    catch (Throwable t) {
      assertTrue(t instanceof RuntimeException);
    }
    assertEquals(0, overloaded.getCount());
    assertEquals(0, overloaded_param.getCount());

    // throws the right exception
    try {
      meteredClass.overloadedExceptionMeteredMethod(BogusException.class);
      fail();
    }
    catch (Throwable t) {
      assertTrue(t instanceof BogusException);
    }
    assertEquals(1, overloaded.getCount());
    assertEquals(0, overloaded_param.getCount());

    // doesn't throw an exception
    meteredClass.overloadedExceptionMeteredMethod(null, 1);
    assertEquals(1, overloaded.getCount());
    assertEquals(0, overloaded_param.getCount());

    // throws the wrong exception
    try {
      meteredClass.overloadedExceptionMeteredMethod(RuntimeException.class, 1);
      fail();
    }
    catch (Throwable t) {
      assertTrue(t instanceof RuntimeException);
    }
    assertEquals(1, overloaded.getCount());
    assertEquals(0, overloaded_param.getCount());

    // throws the right exception
    try {
      meteredClass.overloadedExceptionMeteredMethod(BogusException.class, 1);
      fail();
    }
    catch (Throwable t) {
      assertTrue(t instanceof BogusException);
    }
    assertEquals(1, overloaded.getCount());
    assertEquals(1, overloaded_param.getCount());
  }
View Full Code Here

  private void notifyAllCacheMisses() {
    registry.meter(allCacheMissesMetricName).mark();
  }

  public Ratio getHitRatio1Min() {
    final Meter hitRate = registry.meter(allCacheHitsMetricName);
    final Meter missRate = registry.meter(allCacheMissesMetricName);
    final double oneMinuteHitRate = hitRate.getOneMinuteRate();
    return Ratio.of(oneMinuteHitRate, oneMinuteHitRate + missRate.getOneMinuteRate());
  }
View Full Code Here

        String timerName = invocation.getMethod().getAnnotation(Metered.class).value();
        if (timerName.isEmpty()) {
            timerName = MetricRegistry.name(invocation.getThis().getClass().getSuperclass(), invocation.getMethod().getName());
        }

        Meter meter
            = metricsServiceProvider
                .get()
                .getMetricRegistry()
                .meter(timerName);
        meter.mark();

        try {
            return invocation.proceed();
        } finally {
View Full Code Here

        }

        if (method.getMethod().isAnnotationPresent(Metered.class)) {
            final Metered annotation = method.getMethod().getAnnotation(Metered.class);
            final String name = chooseName(annotation.name(), annotation.absolute(), method);
            final Meter meter = registry.meter(name);
            dispatcher = new MeteredRequestDispatcher(dispatcher, meter);
        }

        if (method.getMethod().isAnnotationPresent(ExceptionMetered.class)) {
            final ExceptionMetered annotation = method.getMethod()
                                                      .getAnnotation(ExceptionMetered.class);
            final String name = chooseName(annotation.name(),
                                           annotation.absolute(),
                                           method,
                                           ExceptionMetered.DEFAULT_NAME_SUFFIX);
            final Meter meter = registry.meter(name);
            dispatcher = new ExceptionMeteredRequestDispatcher(dispatcher,
                                                               meter,
                                                               annotation.cause());
        }
View Full Code Here

  @Override
  public void increment(Delta<?> delta) {
    String name = delta.getName();
    long value = delta.getValue().longValue();
    if (name.startsWith("meter")) {
      Meter meter = this.registry.meter(name);
      meter.mark(value);
    }
    else {
      Counter counter = this.registry.counter(name);
      counter.inc(value);
    }
View Full Code Here

            markMeterForStatusCode(wrappedResponse.getStatus());
        }
    }

    private void markMeterForStatusCode(int status) {
        final Meter metric = metersByStatusCode.get(status);
        if (metric != null) {
            metric.mark();
        } else {
            otherMeter.mark();
        }
    }
View Full Code Here

            markMeterForStatusCode(wrappedResponse.getStatus());
        }
    }

    private void markMeterForStatusCode(int status) {
        final Meter metric = metersByStatusCode.get(status);
        if (metric != null) {
            metric.mark();
        } else {
            otherMeter.mark();
        }
    }
View Full Code Here

    assertEquals("ok", view.assertStringResponse());
    assertEquals(Collections.singleton("examples.metrics"), SharedMetricRegistries.names());    //<4>
    MetricRegistry registry = SharedMetricRegistries.getOrCreate("examples.metrics");
    Timer timer = registry.getTimers().get("juzu.responses");                                   //<5>
    assertEquals(1, timer.getCount());
    Meter meter = registry.getMeters().get("custom");                                           //<6>
    assertNotNull(meter);
  }
View Full Code Here

TOP

Related Classes of com.codahale.metrics.Meter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.