Java Code Examples for com.codahale.metrics.Histogram#update()

The following examples show how to use com.codahale.metrics.Histogram#update() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlatformDriverExecutorRegistry.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
private Map<String, Object> queueBacklog() {
   Histogram backlog = new Histogram(new UniformReservoir(64));
   for(DriverExecutor executor: executorCache.asMap().values()) {
      backlog.update(((DefaultDriverExecutor) executor).getQueuedMessageCount());
   }
   Snapshot snap = backlog.getSnapshot();
   return ImmutableMap
         .<String, Object>builder()
         .put("count", backlog.getCount())
         .put("min", snap.getMin())
         .put("max", snap.getMax())
         .put("mean", snap.getMean())
         .put("stddev", snap.getStdDev())
         .put("p50", snap.getMedian())
         .put("p75", snap.get75thPercentile())
         .put("p95", snap.get95thPercentile())
         .put("p98", snap.get98thPercentile())
         .put("p99", snap.get99thPercentile())
         .put("p999", snap.get999thPercentile())
         .build();
}
 
Example 2
Source File: TestStageContext.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private <T> T createMetrics(StageContext context, String metricName, Class<T> metricClass, final Object value) {
  if (metricClass.equals(Meter.class)) {
    Meter m = context.createMeter(metricName);
    m.mark((long)value);
    return (T)m;
  } else if (metricClass.equals(Counter.class)) {
    Counter c = context.createCounter(metricName);
    c.inc((long)value);
    return (T)c;
  } else if (metricClass.equals(Timer.class)) {
    Timer t = context.createTimer(metricName);
    t.update((long)value, TimeUnit.NANOSECONDS);
    return (T)t;
  } else if (metricClass.equals(Histogram.class)) {
    Histogram h = context.createHistogram(metricName);
    h.update((long)value);
    return (T)h;
  } else {
    Gauge<Map<String, Object>> g = context.createGauge(metricName);
    g.getValue().putAll(((Map)value));
    return (T)g;
  }
}
 
Example 3
Source File: TestMetricRuleEvaluator.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Test
public void testHistogramDisabled() {
  //create timer with id "testMetricAlerts" and register with metric registry, bump up value to 4.
  Histogram h = MetricsConfigurator.createHistogram5Min(metrics, "testHistogramDisabled", PIPELINE_NAME, REVISION);
  h.update(1000);

  MetricsRuleDefinition metricsRuleDefinition = new MetricsRuleDefinition("testHistogramDisabled",
    "testHistogramDisabled", "testHistogramDisabled", MetricType.HISTOGRAM,
    MetricElement.HISTOGRAM_COUNT, "${value()==1}", false, false, System.currentTimeMillis());
  MetricRuleEvaluator metricRuleEvaluator = new MetricRuleEvaluator(metricsRuleDefinition, metrics,
    new AlertManager(PIPELINE_NAME, PIPELINE_TITLE, REVISION, null, metrics, runtimeInfo, new EventListenerManager()),
      new RuleDefinitionsConfigBean(), 0);
  metricRuleEvaluator.checkForAlerts();

  //get alert gauge
  Gauge<Object> gauge = MetricsConfigurator.getGauge(metrics,
    AlertsUtil.getAlertGaugeName(metricsRuleDefinition.getId()));
  Assert.assertNull(gauge);
}
 
Example 4
Source File: TestMetricRuleEvaluator.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Test
public void testHistogramNoMatch() {
  //create timer with id "testMetricAlerts" and register with metric registry, bump up value to 4.
  Histogram h = MetricsConfigurator.createHistogram5Min(metrics, "testHistogramNoMatch", PIPELINE_NAME, REVISION);
  h.update(1000);

  MetricsRuleDefinition metricsRuleDefinition = new MetricsRuleDefinition("testHistogramNoMatch",
    "testHistogramNoMatch", "testHistogramNoMatch", MetricType.HISTOGRAM,
    MetricElement.HISTOGRAM_COUNT, "${value()>1}", false, true, System.currentTimeMillis());
  MetricRuleEvaluator metricRuleEvaluator = new MetricRuleEvaluator(metricsRuleDefinition, metrics,
    new AlertManager(PIPELINE_NAME, PIPELINE_TITLE, REVISION, null, metrics, runtimeInfo, new EventListenerManager()),
      new RuleDefinitionsConfigBean(), 0);
  metricRuleEvaluator.checkForAlerts();

  //get alert gauge
  Gauge<Object> gauge = MetricsConfigurator.getGauge(metrics,
    AlertsUtil.getAlertGaugeName(metricsRuleDefinition.getId()));
  Assert.assertNull(gauge);
}
 
Example 5
Source File: MetricsHelper.java    From datacollector with Apache License 2.0 6 votes vote down vote up
static Histogram createAndInitHistogram(
    MetricRegistryJson metricRegistryJson,
    MetricRegistry metrics,
    String histogramName,
    String pipelineName,
    String revision
) {
  Histogram histogram5Min = MetricsConfigurator.createHistogram5Min(metrics, histogramName, pipelineName, revision);
  if (metricRegistryJson != null) {
    Map<String, HistogramJson> histograms = metricRegistryJson.getHistograms();
    if (null != histograms && histograms.containsKey(histogramName + MetricsConfigurator.HISTOGRAM_M5_SUFFIX)) {
      HistogramJson histogramJson = histograms.get(histogramName + MetricsConfigurator.HISTOGRAM_M5_SUFFIX);
      if (histogramJson != null) {
        histogram5Min.update(histogramJson.getCount());
      }
    }
  }
  return histogram5Min;
}
 
Example 6
Source File: SignalFxReporterTest.java    From signalfx-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testHistogram() {
    Histogram histogram = sfxMetrics.histogram("histogram", "dimName", "dimValue");
    histogram.update(20);
    histogram.update(30);
    reporter.report();
    assertEquals(3, dbank.addDataPoints.size());
    assertEquals(2, dbank.lastValueFor(SOURCE_NAME, "histogram.count").getIntValue());
    assertEquals(20, dbank.lastValueFor(SOURCE_NAME, "histogram.min").getIntValue());
    assertEquals(30, dbank.lastValueFor(SOURCE_NAME, "histogram.max").getIntValue());
    dbank.addDataPoints.clear();
    histogram.update(25);
    reporter.report();
    assertEquals(3, dbank.addDataPoints.size());
    assertEquals(3, dbank.lastValueFor(SOURCE_NAME, "histogram.count").getIntValue());
    assertEquals(20, dbank.lastValueFor(SOURCE_NAME, "histogram.min").getIntValue());
    assertEquals(30, dbank.lastValueFor(SOURCE_NAME, "histogram.max").getIntValue());
}
 
Example 7
Source File: CustomPercentiles.java    From semantic-metrics with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
    FastForwardReporter f = FastForwardReporter
        .forRegistry(registry)
        .histogramQuantiles(0.62, 0.55, 0.99)
        .schedule(TimeUnit.SECONDS, 10)
        .build();
    f.start();

    Histogram h = registry.histogram(APP_PREFIX.tagged("what", "stuff"));

    for (int i = 0; i < 100; i++) {
        h.update(i);
    }

    System.out.println("Sending custom percentiles for histogram...");
    System.in.read();
    f.stop();
}
 
Example 8
Source File: SignalFxReporterTest.java    From signalfx-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testResettingHistogram() {
    Histogram resettingHistogram = sfxMetrics.resettingHistogram("resettingHistogram");
    resettingHistogram.update(20);
    resettingHistogram.update(30);
    reporter.report();
    assertEquals(3, dbank.addDataPoints.size());
    assertEquals(2, dbank.lastValueFor(SOURCE_NAME, "resettingHistogram.count").getIntValue());
    assertEquals(20, dbank.lastValueFor(SOURCE_NAME, "resettingHistogram.min").getIntValue());
    assertEquals(30, dbank.lastValueFor(SOURCE_NAME, "resettingHistogram.max").getIntValue());
    dbank.addDataPoints.clear();
    resettingHistogram.update(25);
    reporter.report();
    assertEquals(3, dbank.addDataPoints.size());
    assertEquals(3, dbank.lastValueFor(SOURCE_NAME, "resettingHistogram.count").getIntValue());
    assertEquals(25, dbank.lastValueFor(SOURCE_NAME, "resettingHistogram.min").getIntValue());
    assertEquals(25, dbank.lastValueFor(SOURCE_NAME, "resettingHistogram.max").getIntValue());
}
 
Example 9
Source File: CloudWatchReporterTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 5 votes vote down vote up
@Test
public void shouldReportHistogramSubsequentSnapshotValues_SumMaxMinValues() throws Exception {
    CloudWatchReporter reporter = reporterBuilder.withStatisticSet().build();

    final Histogram slidingWindowHistogram = new Histogram(new SlidingWindowReservoir(4));
    metricRegistry.register("SlidingWindowHistogram", slidingWindowHistogram);

    slidingWindowHistogram.update(1);
    slidingWindowHistogram.update(2);
    slidingWindowHistogram.update(30);
    reporter.report();

    final MetricDatum metricData = metricDatumByDimensionFromCapturedRequest(DIMENSION_SNAPSHOT_SUMMARY);

    assertThat(metricData.statisticValues().maximum().intValue()).isEqualTo(30);
    assertThat(metricData.statisticValues().minimum().intValue()).isEqualTo(1);
    assertThat(metricData.statisticValues().sampleCount().intValue()).isEqualTo(3);
    assertThat(metricData.statisticValues().sum().intValue()).isEqualTo(33);
    assertThat(metricData.unit()).isEqualTo(StandardUnit.NONE);

    slidingWindowHistogram.update(4);
    slidingWindowHistogram.update(100);
    slidingWindowHistogram.update(5);
    slidingWindowHistogram.update(6);
    reporter.report();

    final MetricDatum secondMetricData = metricDatumByDimensionFromCapturedRequest(DIMENSION_SNAPSHOT_SUMMARY);

    assertThat(secondMetricData.statisticValues().maximum().intValue()).isEqualTo(100);
    assertThat(secondMetricData.statisticValues().minimum().intValue()).isEqualTo(4);
    assertThat(secondMetricData.statisticValues().sampleCount().intValue()).isEqualTo(4);
    assertThat(secondMetricData.statisticValues().sum().intValue()).isEqualTo(115);
    assertThat(secondMetricData.unit()).isEqualTo(StandardUnit.NONE);
}
 
Example 10
Source File: ResourceSchedulerWrapper.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
  samplerLock.lock();
  try {
    for (Histogram histogram : schedulerHistogramList) {
      Timer timer = histogramTimerMap.get(histogram);
      histogram.update((int) timer.getSnapshot().getMean());
    }
  } finally {
    samplerLock.unlock();
  }
}
 
Example 11
Source File: DatadogMetricFilterTest.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Test
public void testExpansionFilterExclusion() throws Exception {
    String json =
            "{" +
                    "\"type\": \"datadogExpansionFiltered\"," +
                    "\"host\": \"test-host\"," +
                    "\"excludeExpansions\": [\"min\", \"max\", \"p75\", \"p95\", \"p98\", \"p99\", \"p999\"]," +
                    "\"transport\": {" +
                    "\"type\": \"http\"," +
                    "\"apiKey\": \"12345\"" +
                    "}" +
                    "}";


    ScheduledReporter reporter = createReporter(json);

    // Create a representative type.
    Histogram histogram = _metricRegistry.histogram("test.histogram");
    histogram.update(1);
    histogram.update(2);
    histogram.update(3);

    reporter.report();

    // Verify only the desired metrics were sent.  Notably min, max, and the nth percentiles should be absent.
    verify(_request).addGauge(argThat(hasGauge("test.histogram.count", 3)));
    verify(_request).addGauge(argThat(hasGauge("test.histogram.mean", 2)));
    verify(_request).addGauge(argThat(hasGauge("test.histogram.median", 2)));
    verify(_request).addGauge(argThat(hasGauge("test.histogram.stddev", 1.0)));

    // Send was called exactly once
    verify(_request).send();

    verifyNoMoreInteractions(_request);
}
 
Example 12
Source File: ExpectedIntervalBetweenValueSamplesTest.java    From rolling-metrics with Apache License 2.0 5 votes vote down vote up
@Test
public void expectedIntervalBetweenValueSamples() {
    Histogram histogram = new HdrBuilder().withExpectedIntervalBetweenValueSamples(100).buildHistogram();
    for (int i = 1; i <= 100; i++) {
        histogram.update(i);
    }
    assertEquals(75.0, histogram.getSnapshot().get75thPercentile());
    assertEquals(99.0, histogram.getSnapshot().get99thPercentile());

    histogram.update(10000);
    assertEquals(5023.0, histogram.getSnapshot().get75thPercentile());
    assertEquals(9855.0, histogram.getSnapshot().get99thPercentile());
}
 
Example 13
Source File: DynamicMetricsManager.java    From brooklin with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Update the histogram (or creates it if it does not exist) for the specified key/metricName pair by the given value.
 * @param classSimpleName the simple name of the underlying class
 * @param key the key (i.e. topic or partition) for the metric
 * @param metricName the metric name
 * @param value the value to update on the histogram
 */
public void createOrUpdateHistogram(String classSimpleName, String key, String metricName, long value) {
  validateArguments(classSimpleName, metricName);
  // create and register the metric if it does not exist
  Histogram histogram = (Histogram) checkCache(classSimpleName, key, metricName).orElseGet(() -> {
    Histogram newHistogram = _metricRegistry.histogram(MetricRegistry.name(classSimpleName, key, metricName));
    updateCache(classSimpleName, key, metricName, newHistogram);
    return newHistogram;
  });
  histogram.update(value);
}
 
Example 14
Source File: ResourceSchedulerWrapper.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
  samplerLock.lock();
  try {
    for (Histogram histogram : schedulerHistogramList) {
      Timer timer = histogramTimerMap.get(histogram);
      histogram.update((int) timer.getSnapshot().getMean());
    }
  } finally {
    samplerLock.unlock();
  }
}
 
Example 15
Source File: ChannelStatisticsHandler.java    From styx with Apache License 2.0 5 votes vote down vote up
private void updateChannelPerThreadCounters(int amount) {
    Thread thread = Thread.currentThread();
    Counter channelCount = this.metricRegistry.counter(name(counterPrefix(thread), "registered-channel-count"));
    channelCount.inc(amount);

    Histogram histogram = metricRegistry.histogram(name(counterPrefix(thread), "channels"));
    histogram.update(channelCount.getCount());
}
 
Example 16
Source File: GraphiteReporterTest.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
@Test
public void testWithoutTags() throws IOException {
  try (
      MetricContext metricContext =
          MetricContext.builder(this.getClass().getCanonicalName() + ".testGraphiteReporter").build();

      GraphiteReporter graphiteReporter =
          GraphiteReporter.Factory.newBuilder()
              .withGraphitePusher(graphitePusher)
              .withMetricContextName(CONTEXT_NAME)
              .build(new Properties());) {

    ContextAwareGauge<Long> contextAwareGauge =
        metricContext.newContextAwareGauge("com.linkedin.example.gauge", new Gauge<Long>() {
          @Override
          public Long getValue() {
            return 1000l;
          }
        });

    metricContext.register(MetricRegistry.name(METRIC_PREFIX, GAUGE), contextAwareGauge);
    Counter counter = metricContext.counter(MetricRegistry.name(METRIC_PREFIX, COUNTER));
    Meter meter = metricContext.meter(MetricRegistry.name(METRIC_PREFIX, METER));
    Histogram histogram = metricContext.histogram(MetricRegistry.name(METRIC_PREFIX, HISTOGRAM));
    Timer timer = metricContext.timer(MetricRegistry.name(METRIC_PREFIX, TIMER));

    counter.inc(3l);
    meter.mark(1l);
    meter.mark(2l);
    meter.mark(3l);
    histogram.update(1);
    histogram.update(1);
    histogram.update(2);
    timer.update(1, TimeUnit.SECONDS);
    timer.update(2, TimeUnit.SECONDS);
    timer.update(3, TimeUnit.SECONDS);

    graphiteReporter.report(metricContext.getGauges(), metricContext.getCounters(), metricContext.getHistograms(),
        metricContext.getMeters(), metricContext.getTimers(), metricContext.getTagMap());

    Assert.assertEquals(getMetricValue(COUNTER, Measurements.COUNT), Long.toString(3l));

    Assert.assertEquals(getMetricValue(GAUGE, null), Long.toString(1000l));
    Assert.assertTrue(getMetricTimestamp(GAUGE, null) <= System.currentTimeMillis() / 1000l);

    Assert.assertEquals(getMetricValue(HISTOGRAM, Measurements.PERCENTILE_75TH), Double.toString(2d));
    Assert.assertEquals(getMetricValue(HISTOGRAM, Measurements.PERCENTILE_98TH), Double.toString(2d));
    Assert.assertEquals(getMetricValue(HISTOGRAM, Measurements.PERCENTILE_99TH), Double.toString(2d));
    Assert.assertEquals(getMetricValue(HISTOGRAM, Measurements.PERCENTILE_999TH), Double.toString(2d));

    Assert.assertEquals(getMetricValue(HISTOGRAM, Measurements.COUNT), Long.toString(3l));
    Assert.assertEquals(getMetricValue(HISTOGRAM, Measurements.MIN), Long.toString(1l));
    Assert.assertEquals(getMetricValue(HISTOGRAM, Measurements.MAX), Long.toString(2l));
    Assert.assertEquals(getMetricValue(HISTOGRAM, Measurements.MEDIAN), Double.toString(1d));
    Assert.assertTrue(Double.valueOf(getMetricValue(HISTOGRAM, Measurements.MEAN)) > 1d);
    Assert.assertTrue(Double.valueOf(getMetricValue(HISTOGRAM, Measurements.STDDEV)) < 0.5d);

    Assert.assertEquals(getMetricValue(METER, Measurements.RATE_1MIN), Double.toString(0d));
    Assert.assertEquals(getMetricValue(METER, Measurements.RATE_5MIN), Double.toString(0d));
    Assert.assertEquals(getMetricValue(METER, Measurements.COUNT), Long.toString(6l));
    Assert.assertTrue(Double.valueOf(getMetricValue(METER, Measurements.MEAN_RATE)) > 0d);

    Assert.assertEquals(getMetricValue(TIMER, Measurements.RATE_1MIN), Double.toString(0d));
    Assert.assertEquals(getMetricValue(TIMER, Measurements.RATE_5MIN), Double.toString(0d));
    Assert.assertEquals(getMetricValue(TIMER, Measurements.PERCENTILE_75TH), Double.toString(3000d));
    Assert.assertEquals(getMetricValue(TIMER, Measurements.PERCENTILE_98TH), Double.toString(3000d));
    Assert.assertEquals(getMetricValue(TIMER, Measurements.PERCENTILE_99TH), Double.toString(3000d));
    Assert.assertEquals(getMetricValue(TIMER, Measurements.PERCENTILE_999TH), Double.toString(3000d));

    Assert.assertEquals(getMetricValue(TIMER, Measurements.COUNT), Long.toString(3l));
    Assert.assertEquals(getMetricValue(TIMER, Measurements.MIN), Double.toString(1000d));
    Assert.assertEquals(getMetricValue(TIMER, Measurements.MAX), Double.toString(3000d));
    Assert.assertEquals(getMetricValue(TIMER, Measurements.MEAN), Double.toString(2000d));
    Assert.assertEquals(getMetricValue(TIMER, Measurements.MEDIAN), Double.toString(2000d));
    Assert.assertTrue(Double.valueOf(getMetricValue(TIMER, Measurements.MEAN_RATE)) > 0d);
    Assert.assertTrue(Double.valueOf(getMetricValue(TIMER, Measurements.STDDEV)) > 0d);

  }
}
 
Example 17
Source File: DatadogMetricFilterTest.java    From emodb with Apache License 2.0 4 votes vote down vote up
@Test
public void testExpansionFilterInclusion() throws Exception {
    String json =
            "{" +
                    "\"type\": \"datadogExpansionFiltered\"," +
                    "\"host\": \"test-host\"," +
                    "\"includeExpansions\": [\"count\", \"min\", \"max\", \"p95\"]," +
                    "\"transport\": {" +
                            "\"type\": \"http\"," +
                            "\"apiKey\": \"12345\"" +
                    "}" +
            "}";


    ScheduledReporter reporter = createReporter(json);

    // Create some metrics for each major type
    Counter counter = _metricRegistry.counter("test.counter");
    counter.inc(10);

    Histogram histogram = _metricRegistry.histogram("test.histogram");
    histogram.update(1);
    histogram.update(2);
    histogram.update(3);

    Meter meter = _metricRegistry.meter("test.meter");
    meter.mark(100);

    Timer timer = _metricRegistry.timer("test.timer");
    timer.update(1, TimeUnit.SECONDS);
    timer.update(2, TimeUnit.SECONDS);
    timer.update(3, TimeUnit.SECONDS);

    _metricRegistry.register("test.gauge", new Gauge<Integer>() {
        @Override
        public Integer getValue() {
            return 50;
        }
    });

    reporter.report();

    // Verify only the desired metrics were sent
    verify(_request).addGauge(argThat(hasGauge("test.counter", 10)));
    verify(_request).addGauge(argThat(hasGauge("test.histogram.count", 3)));
    verify(_request).addGauge(argThat(hasGauge("test.histogram.min", 1)));
    verify(_request).addGauge(argThat(hasGauge("test.histogram.max", 3)));
    verify(_request).addGauge(argThat(hasGauge("test.histogram.p95", 3.0)));
    verify(_request).addGauge(argThat(hasGauge("test.timer.count", 3)));
    verify(_request).addGauge(argThat(hasGauge("test.timer.min", 1000f)));
    verify(_request).addGauge(argThat(hasGauge("test.timer.max", 3000f)));
    verify(_request).addGauge(argThat(hasGauge("test.timer.p95", 3000f)));
    verify(_request).addGauge(argThat(hasGauge("test.meter.count", 100)));
    verify(_request).addGauge(argThat(hasGauge("test.gauge", 50)));

    // Send was called exactly once
    verify(_request).send();

    verifyNoMoreInteractions(_request);
}
 
Example 18
Source File: ReporterExampleBase.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
  Counter totalRecordsCounter = this.context.contextAwareCounter(TOTAL_RECORDS);
  Meter recordProcessRateMeter = this.context.contextAwareMeter(RECORD_PROCESS_RATE);
  Timer recordProcessTimeTimer = this.context.contextAwareTimer(RECORD_PROCESS_TIME);
  Histogram recordSizesHistogram = this.context.contextAwareHistogram(RECORD_SIZES);

  try {

    for (int i = 0; i < this.totalRecords; i++) {
      totalRecordsCounter.inc();
      recordProcessRateMeter.mark();
      recordSizesHistogram.update((this.rand.nextLong() & Long.MAX_VALUE) % 5000l);

      if (i % 100 == 0) {
        LOGGER.info(String.format("Task %d has processed %d records so far", this.taskIndex, i));
      }

      long processTime = (this.rand.nextLong() & Long.MAX_VALUE) % 10;
      // Simulate record processing by sleeping for a random amount of time
      try {
        Thread.sleep(processTime);
      } catch (InterruptedException ie) {
        LOGGER.warn(String.format("Task %d has been interrupted", this.taskIndex));
        Thread.currentThread().interrupt();
        return;
      }

      recordProcessTimeTimer.update(processTime, TimeUnit.MILLISECONDS);
    }

    LOGGER.info(String.format("Task %d has processed all %d records", this.taskIndex, this.totalRecords));
  } finally{
    try {
      this.context.close();
    } catch (IOException ioe) {
      LOGGER.error("Failed to close context: " + this.context.getName(), ioe);
    } finally {
      this.countDownLatch.countDown();
    }
  }
}
 
Example 19
Source File: NewAPIHadoopCounterReporterTest.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 20
Source File: GraphiteReporterTest.java    From styx with Apache License 2.0 4 votes vote down vote up
private static Histogram histogram(int update) {
    Histogram okHistogram = new Histogram(new SlidingWindowReservoir(50));
    okHistogram.update(update);
    return okHistogram;
}