Search in sources :

Example 11 with Histogram

use of com.codahale.metrics.Histogram in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method RollingWindowTimerBuilder_newMetric_creates_new_timer_with_SlidingTimeWindowReservoir_with_expected_values.

@DataProvider(value = { "42     |   DAYS", "123    |   SECONDS", "999    |   MILLISECONDS", "3      |   HOURS" }, splitBy = "\\|")
@Test
public void RollingWindowTimerBuilder_newMetric_creates_new_timer_with_SlidingTimeWindowReservoir_with_expected_values(long amount, TimeUnit timeUnit) {
    // given
    RollingWindowTimerBuilder rwtb = new RollingWindowTimerBuilder(amount, timeUnit);
    // when
    Timer timer = rwtb.newMetric();
    // then
    Histogram histogram = (Histogram) getInternalState(timer, "histogram");
    Reservoir reservoir = (Reservoir) getInternalState(histogram, "reservoir");
    assertThat(reservoir).isInstanceOf(SlidingTimeWindowReservoir.class);
    // The expected value here comes from logic in the SlidingTimeWindowReservoir constructor.
    assertThat(getInternalState(reservoir, "window")).isEqualTo(timeUnit.toNanos(amount) * 256);
}
Also used : Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) Reservoir(com.codahale.metrics.Reservoir) SlidingTimeWindowReservoir(com.codahale.metrics.SlidingTimeWindowReservoir) RollingWindowTimerBuilder(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowTimerBuilder) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 12 with Histogram

use of com.codahale.metrics.Histogram in project riposte by Nike-Inc.

the class CodahaleMetricsListenerTest method builder_works_as_expected_for_specified_fields.

@DataProvider(value = { "true   |   true", "true   |   false", "false  |   true", "false  |   false" }, splitBy = "\\|")
@Test
public void builder_works_as_expected_for_specified_fields(boolean overrideCodahaleMetricsCollector, boolean includeServerConfigMetrics) {
    // given
    setupMetricRegistryAndCodahaleMetricsCollector();
    CodahaleMetricsCollector alternateCmcMock = mock(CodahaleMetricsCollector.class);
    doReturn(metricRegistryMock).when(alternateCmcMock).getMetricRegistry();
    MetricNamingStrategy<ServerStatisticsMetricNames> statsNamingStrat = new DefaultMetricNamingStrategy<>();
    MetricNamingStrategy<ServerConfigMetricNames> configNamingStrat = new DefaultMetricNamingStrategy<>();
    Supplier<Histogram> histogramSupplier = () -> mock(Histogram.class);
    Builder builder = CodahaleMetricsListener.newBuilder(cmcMock);
    if (overrideCodahaleMetricsCollector)
        builder = builder.withMetricsCollector(alternateCmcMock);
    builder = builder.withEndpointMetricsHandler(endpointMetricsHandlerMock).withIncludeServerConfigMetrics(includeServerConfigMetrics).withServerConfigMetricNamingStrategy(configNamingStrat).withServerStatsMetricNamingStrategy(statsNamingStrat).withRequestAndResponseSizeHistogramSupplier(histogramSupplier);
    // when
    CodahaleMetricsListener result = builder.build();
    // then
    if (overrideCodahaleMetricsCollector)
        assertThat(result.metricsCollector).isSameAs(alternateCmcMock);
    else
        assertThat(result.metricsCollector).isSameAs(cmcMock);
    assertThat(result.endpointMetricsHandler).isSameAs(endpointMetricsHandlerMock);
    assertThat(result.includeServerConfigMetrics).isEqualTo(includeServerConfigMetrics);
    assertThat(result.serverConfigMetricNamingStrategy).isSameAs(configNamingStrat);
    assertThat(result.serverStatsMetricNamingStrategy).isSameAs(statsNamingStrat);
    assertThat(result.requestAndResponseSizeHistogramSupplier).isSameAs(histogramSupplier);
}
Also used : Histogram(com.codahale.metrics.Histogram) DefaultMetricNamingStrategy(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.DefaultMetricNamingStrategy) ServerConfigMetricNames(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.ServerConfigMetricNames) ServerStatisticsMetricNames(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.ServerStatisticsMetricNames) Builder(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.Builder) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 13 with Histogram

use of com.codahale.metrics.Histogram in project riposte by Nike-Inc.

the class CodahaleMetricsListenerTest method setupMetricRegistryAndCodahaleMetricsCollector.

private void setupMetricRegistryAndCodahaleMetricsCollector() {
    metricRegistryMock = mock(MetricRegistry.class);
    cmcMock = mock(CodahaleMetricsCollector.class);
    doReturn(metricRegistryMock).when(cmcMock).getMetricRegistry();
    registeredTimerMocks = new HashMap<>();
    doAnswer(invocation -> {
        String name = invocation.getArgumentAt(0, String.class);
        Timer timerMock = mock(Timer.class);
        registeredTimerMocks.put(name, timerMock);
        return timerMock;
    }).when(metricRegistryMock).timer(anyString());
    registeredMeterMocks = new HashMap<>();
    doAnswer(invocation -> {
        String name = invocation.getArgumentAt(0, String.class);
        Meter meterMock = mock(Meter.class);
        registeredMeterMocks.put(name, meterMock);
        return meterMock;
    }).when(metricRegistryMock).meter(anyString());
    registeredCounterMocks = new HashMap<>();
    doAnswer(invocation -> {
        String name = invocation.getArgumentAt(0, String.class);
        Counter counterMock = mock(Counter.class);
        registeredCounterMocks.put(name, counterMock);
        return counterMock;
    }).when(metricRegistryMock).counter(anyString());
    registeredHistogramMocks = new HashMap<>();
    doAnswer(invocation -> {
        String name = invocation.getArgumentAt(0, String.class);
        Histogram histogramMock = mock(Histogram.class);
        registeredHistogramMocks.put(name, histogramMock);
        return histogramMock;
    }).when(metricRegistryMock).histogram(anyString());
    registeredGauges = new HashMap<>();
    doAnswer(invocation -> {
        String name = invocation.getArgumentAt(0, String.class);
        Metric metric = invocation.getArgumentAt(1, Metric.class);
        if (metric instanceof Gauge)
            registeredGauges.put(name, (Gauge) metric);
        else if (metric instanceof Histogram)
            registeredHistogramMocks.put(name, (Histogram) metric);
        else
            throw new RuntimeException("Expected Gauge or Histogram, but received: " + metric.getClass().getName());
        return metric;
    }).when(metricRegistryMock).register(anyString(), any(Metric.class));
}
Also used : Histogram(com.codahale.metrics.Histogram) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) Meter(com.codahale.metrics.Meter) MetricRegistry(com.codahale.metrics.MetricRegistry) Metric(com.codahale.metrics.Metric) Matchers.anyString(org.mockito.Matchers.anyString) Gauge(com.codahale.metrics.Gauge)

Example 14 with Histogram

use of com.codahale.metrics.Histogram in project opennms by OpenNMS.

the class StressCommand method doExecute.

@Override
protected Object doExecute() throws Exception {
    // Create the client
    final RpcClient<EchoRequest, EchoResponse> client = rpcClientFactory.getClient(EchoRpcModule.INSTANCE);
    // Create metrics to capture the results
    final MetricRegistry metrics = new MetricRegistry();
    final Histogram responseTimes = metrics.histogram("response-times");
    final Counter successes = metrics.counter("successes");
    final Counter failures = metrics.counter("failures");
    // Build and issue the requests
    System.out.printf("Executing %d requests.\n", count);
    final String message = Strings.repeat("*", messageSize);
    final CountDownLatch doneSignal = new CountDownLatch(count);
    long beforeExec = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
        client.execute(buildRequest(message)).whenComplete((r, e) -> {
            if (e != null) {
                failures.inc();
            } else {
                responseTimes.update(System.currentTimeMillis() - r.getId());
                successes.inc();
            }
            doneSignal.countDown();
        });
    }
    long afterExec = System.currentTimeMillis();
    // Wait for the responses...
    System.out.printf("Waiting for responses.\n");
    while (true) {
        try {
            if (doneSignal.await(1, TimeUnit.SECONDS)) {
                // Done!
                System.out.printf("\nDone!\n");
                break;
            }
        } catch (InterruptedException e) {
            System.out.println("\nInterrupted!");
            break;
        }
        System.out.print(".");
        System.out.flush();
    }
    long afterResponse = System.currentTimeMillis();
    System.out.println();
    ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.MILLISECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
    reporter.report();
    reporter.close();
    System.out.printf("Total miliseconds elapsed: %d\n", afterResponse - beforeExec);
    System.out.printf("Miliseconds spent generating requests: %d\n", afterExec - beforeExec);
    System.out.printf("Miliseconds spent waiting for responses: %d\n", afterResponse - afterExec);
    return null;
}
Also used : EchoResponse(org.opennms.core.rpc.echo.EchoResponse) Histogram(com.codahale.metrics.Histogram) Counter(com.codahale.metrics.Counter) ConsoleReporter(com.codahale.metrics.ConsoleReporter) MetricRegistry(com.codahale.metrics.MetricRegistry) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 15 with Histogram

use of com.codahale.metrics.Histogram in project graylog2-server by Graylog2.

the class SearchesTest method fieldHistogramRecordsMetrics.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void fieldHistogramRecordsMetrics() throws Exception {
    final AbsoluteRange range = AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC));
    HistogramResult h = searches.fieldHistogram("*", "n", Searches.DateHistogramInterval.MINUTE, null, range, false);
    assertThat(metricRegistry.getTimers()).containsKey(REQUEST_TIMER_NAME);
    assertThat(metricRegistry.getHistograms()).containsKey(RANGES_HISTOGRAM_NAME);
    Timer timer = metricRegistry.timer(REQUEST_TIMER_NAME);
    assertThat(timer.getCount()).isEqualTo(1L);
    Histogram histogram = metricRegistry.histogram(RANGES_HISTOGRAM_NAME);
    assertThat(histogram.getCount()).isEqualTo(1L);
    assertThat(histogram.getSnapshot().getValues()).containsExactly(86400L);
}
Also used : HistogramResult(org.graylog2.indexer.results.HistogramResult) Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Aggregations

Histogram (com.codahale.metrics.Histogram)40 Test (org.junit.Test)18 Timer (com.codahale.metrics.Timer)17 Meter (com.codahale.metrics.Meter)13 Counter (com.codahale.metrics.Counter)11 Snapshot (com.codahale.metrics.Snapshot)8 Gauge (com.codahale.metrics.Gauge)7 MetricRegistry (com.codahale.metrics.MetricRegistry)7 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)5 ZonedDateTime (java.time.ZonedDateTime)5 Map (java.util.Map)5 DateTime (org.joda.time.DateTime)5 Metric (com.codahale.metrics.Metric)4 UniformReservoir (com.codahale.metrics.UniformReservoir)3 SortedMap (java.util.SortedMap)3 AggregateMetric (org.apache.solr.metrics.AggregateMetric)3 MetricSnapshot (backtype.storm.generated.MetricSnapshot)2 JAverageSnapshot (com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot)2 MetricFilter (com.codahale.metrics.MetricFilter)2 Reservoir (com.codahale.metrics.Reservoir)2