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);
}
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");
}
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}");
}
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);
}
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);
}
Aggregations