Search in sources :

Example 76 with Histogram

use of com.codahale.metrics.Histogram in project incubator-gobblin by apache.

the class NewAPIHadoopCounterReporterTest method testReportMetrics.

@Test
public void testReportMetrics() {
    Gauge<Integer> queueSizeGauge = new Gauge<Integer>() {

        @Override
        public Integer getValue() {
            return 1000;
        }
    };
    com.codahale.metrics.Counter recordsProcessedCounter = new com.codahale.metrics.Counter();
    recordsProcessedCounter.inc(10l);
    Histogram recordSizeDistributionHistogram = new Histogram(new ExponentiallyDecayingReservoir());
    recordSizeDistributionHistogram.update(1);
    recordSizeDistributionHistogram.update(2);
    recordSizeDistributionHistogram.update(3);
    Meter recordProcessRateMeter = new Meter();
    recordProcessRateMeter.mark(1l);
    recordProcessRateMeter.mark(2l);
    recordProcessRateMeter.mark(3l);
    Timer totalDurationTimer = new Timer();
    totalDurationTimer.update(1, TimeUnit.SECONDS);
    totalDurationTimer.update(2, TimeUnit.SECONDS);
    totalDurationTimer.update(3, TimeUnit.SECONDS);
    SortedMap<String, com.codahale.metrics.Counter> counters = ImmutableSortedMap.<String, com.codahale.metrics.Counter>naturalOrder().put(RECORDS_PROCESSED, recordsProcessedCounter).build();
    SortedMap<String, Gauge> gauges = ImmutableSortedMap.<String, Gauge>naturalOrder().put(QUEUE_SIZE, queueSizeGauge).build();
    SortedMap<String, Histogram> histograms = ImmutableSortedMap.<String, Histogram>naturalOrder().put(RECORD_SIZE_DISTRIBUTION, recordSizeDistributionHistogram).build();
    SortedMap<String, Meter> meters = ImmutableSortedMap.<String, Meter>naturalOrder().put(RECORD_PROCESS_RATE, recordProcessRateMeter).build();
    SortedMap<String, Timer> timers = ImmutableSortedMap.<String, Timer>naturalOrder().put(TOTAL_DURATION, totalDurationTimer).build();
    this.hadoopCounterReporter.report(gauges, counters, histograms, meters, timers);
    Mockito.verify(this.recordsProcessedCount).increment(10l);
    Mockito.verify(this.recordProcessRateCount).increment(6l);
    Mockito.verify(this.recordSizeDistributionCount).increment(3l);
    Mockito.verify(this.totalDurationCount).increment(3l);
    Mockito.verify(this.queueSize).setValue(1000);
    recordsProcessedCounter.inc(5l);
    recordSizeDistributionHistogram.update(4);
    recordProcessRateMeter.mark(4l);
    totalDurationTimer.update(4, TimeUnit.SECONDS);
    this.hadoopCounterReporter.report(gauges, counters, histograms, meters, timers);
    Mockito.verify(this.recordsProcessedCount).increment(5l);
    Mockito.verify(this.recordProcessRateCount).increment(4l);
    Mockito.verify(this.recordSizeDistributionCount).increment(1l);
    Mockito.verify(this.totalDurationCount).increment(1l);
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) Gauge(com.codahale.metrics.Gauge) ExponentiallyDecayingReservoir(com.codahale.metrics.ExponentiallyDecayingReservoir) Counter(org.apache.hadoop.mapreduce.Counter) Timer(com.codahale.metrics.Timer) Test(org.testng.annotations.Test)

Example 77 with Histogram

use of com.codahale.metrics.Histogram in project helios by spotify.

the class FastForwardReporterTest method testHistogram.

@Test
public void testHistogram() throws Exception {
    final Histogram h = metricRegistry.histogram("histo.gram");
    IntStream.range(1, 10).forEach(h::update);
    reporter.reportOnce();
    verifyHistogramStats("histo.gram", "histogram");
}
Also used : Histogram(com.codahale.metrics.Histogram) Test(org.junit.Test)

Example 78 with Histogram

use of com.codahale.metrics.Histogram in project metrics by dropwizard.

the class MetricsModuleTest method serializesHistograms.

@Test
public void serializesHistograms() throws Exception {
    final Histogram histogram = mock(Histogram.class);
    when(histogram.getCount()).thenReturn(1L);
    final Snapshot snapshot = mock(Snapshot.class);
    when(snapshot.getMax()).thenReturn(2L);
    when(snapshot.getMean()).thenReturn(3.0);
    when(snapshot.getMin()).thenReturn(4L);
    when(snapshot.getStdDev()).thenReturn(5.0);
    when(snapshot.getMedian()).thenReturn(6.0);
    when(snapshot.get75thPercentile()).thenReturn(7.0);
    when(snapshot.get95thPercentile()).thenReturn(8.0);
    when(snapshot.get98thPercentile()).thenReturn(9.0);
    when(snapshot.get99thPercentile()).thenReturn(10.0);
    when(snapshot.get999thPercentile()).thenReturn(11.0);
    when(snapshot.getValues()).thenReturn(new long[] { 1, 2, 3 });
    when(histogram.getSnapshot()).thenReturn(snapshot);
    assertThat(mapper.writeValueAsString(histogram)).isEqualTo("{" + "\"count\":1," + "\"max\":2," + "\"mean\":3.0," + "\"min\":4," + "\"p50\":6.0," + "\"p75\":7.0," + "\"p95\":8.0," + "\"p98\":9.0," + "\"p99\":10.0," + "\"p999\":11.0," + "\"stddev\":5.0}");
    final ObjectMapper fullMapper = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.MILLISECONDS, true, MetricFilter.ALL));
    assertThat(fullMapper.writeValueAsString(histogram)).isEqualTo("{" + "\"count\":1," + "\"max\":2," + "\"mean\":3.0," + "\"min\":4," + "\"p50\":6.0," + "\"p75\":7.0," + "\"p95\":8.0," + "\"p98\":9.0," + "\"p99\":10.0," + "\"p999\":11.0," + "\"values\":[1,2,3]," + "\"stddev\":5.0}");
}
Also used : Snapshot(com.codahale.metrics.Snapshot) Histogram(com.codahale.metrics.Histogram) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 79 with Histogram

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

the class SignalFxEndpointMetricsHandlerTest method RollingWindowHistogramBuilder_newMetric_creates_a_new_histogram_with_each_call.

@Test
public void RollingWindowHistogramBuilder_newMetric_creates_a_new_histogram_with_each_call() {
    // given
    RollingWindowHistogramBuilder rwhb = new RollingWindowHistogramBuilder(42, TimeUnit.DAYS);
    // when
    Histogram firstCallHistogram = rwhb.newMetric();
    Histogram secondCallHistogram = rwhb.newMetric();
    // then
    assertThat(firstCallHistogram).isNotSameAs(secondCallHistogram);
}
Also used : Histogram(com.codahale.metrics.Histogram) RollingWindowHistogramBuilder(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowHistogramBuilder) Test(org.junit.Test)

Example 80 with Histogram

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

the class SignalFxEndpointMetricsHandlerTest method RollingWindowHistogramBuilder_newMetric_creates_new_histogram_with_SlidingTimeWindowArrayReservoir_with_expected_values.

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

Aggregations

Histogram (com.codahale.metrics.Histogram)97 Test (org.junit.Test)39 Timer (com.codahale.metrics.Timer)34 Counter (com.codahale.metrics.Counter)30 Meter (com.codahale.metrics.Meter)29 Gauge (com.codahale.metrics.Gauge)17 Snapshot (com.codahale.metrics.Snapshot)12 Map (java.util.Map)11 Test (org.testng.annotations.Test)11 MetricRegistry (com.codahale.metrics.MetricRegistry)9 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 Metric (com.codahale.metrics.Metric)6 Reservoir (com.codahale.metrics.Reservoir)6 ZonedDateTime (java.time.ZonedDateTime)6 Properties (java.util.Properties)6 SortedMap (java.util.SortedMap)6 DateTime (org.joda.time.DateTime)6 UniformReservoir (com.codahale.metrics.UniformReservoir)5