com.codahale.metrics.Snapshot Java Examples

The following examples show how to use com.codahale.metrics.Snapshot. 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: GraphiteReporter.java    From styx with Apache License 2.0 6 votes vote down vote up
private void reportTimer(String name, Timer timer, long timestamp) {
    final Snapshot snapshot = timer.getSnapshot();

    TimerPrefixes timerPrefixes = this.timerPrefixes.getUnchecked(name);

    doSend(timerPrefixes.max, convertDuration(snapshot.getMax()), timestamp);
    doSend(timerPrefixes.mean, convertDuration(snapshot.getMean()), timestamp);
    doSend(timerPrefixes.min, convertDuration(snapshot.getMin()), timestamp);
    doSend(timerPrefixes.stddev, convertDuration(snapshot.getStdDev()), timestamp);
    doSend(timerPrefixes.p50, convertDuration(snapshot.getMedian()), timestamp);
    doSend(timerPrefixes.p75, convertDuration(snapshot.get75thPercentile()), timestamp);
    doSend(timerPrefixes.p95, convertDuration(snapshot.get95thPercentile()), timestamp);
    doSend(timerPrefixes.p98, convertDuration(snapshot.get98thPercentile()), timestamp);
    doSend(timerPrefixes.p99, convertDuration(snapshot.get99thPercentile()), timestamp);
    doSend(timerPrefixes.p999, convertDuration(snapshot.get999thPercentile()), timestamp);

    reportMetered(name, timer, timestamp);
}
 
Example #2
Source File: MqMetricReporter.java    From pmq with Apache License 2.0 6 votes vote down vote up
private Set<Metric> buildHistograms(String name, Histogram histogram, long timestamp, Map<String, String> tags) {
    final MetricsCollector collector = MetricsCollector.createNew(name, tags, timestamp);
    final Snapshot snapshot = histogram.getSnapshot();
    if (getChangeCount(name, histogram.getCount()) == 0) {
        return Collections.emptySet();
    }
    return collector.addMetric("count", histogram.getCount())
            .addMetric("max", snapshot.getMax())
            .addMetric("min", snapshot.getMin())
            .addMetric("mean", snapshot.getMean())
            .addMetric("stddev", snapshot.getStdDev())
            .addMetric("median", snapshot.getMedian())
            .addMetric("p75", snapshot.get75thPercentile())
            .addMetric("p95", snapshot.get95thPercentile())
            .addMetric("p98", snapshot.get98thPercentile())
            .addMetric("p99", snapshot.get99thPercentile())
            .addMetric("p999", snapshot.get999thPercentile())
            .build();
}
 
Example #3
Source File: CloudWatchReporter.java    From metrics-cloudwatch with Apache License 2.0 6 votes vote down vote up
/**
 * @param rescale the submitted sum by this multiplier. 1.0 is the identity (no rescale).
 */
void reportSampling(Map.Entry<String, ? extends Sampling> entry, String typeDimValue, double rescale, List<MetricDatum> data) {
    Sampling metric = entry.getValue();
    Snapshot snapshot = metric.getSnapshot();
    double scaledSum = sum(snapshot.getValues()) * rescale;
    final StatisticSet statisticSet = new StatisticSet()
            .withSum(scaledSum)
            .withSampleCount((double) snapshot.size())
            .withMinimum((double) snapshot.getMin() * rescale)
            .withMaximum((double) snapshot.getMax() * rescale);

    DemuxedKey key = new DemuxedKey(appendGlobalDimensions(entry.getKey()));
    Iterables.addAll(data, key.newDatums(typeDimName, typeDimValue, new Function<MetricDatum, MetricDatum>() {
        @Override
        public MetricDatum apply(MetricDatum datum) {
            return datum.withStatisticValues(statisticSet);
        }
    }));
}
 
Example #4
Source File: DropwizardFlinkHistogramWrapperTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
Future<Snapshot> getNextHistogramSnapshot(String name) {
	synchronized (histogramSnapshotFutures) {
		List<CompletableFuture<Snapshot>> futures;
		if (histogramSnapshotFutures.containsKey(name)) {
			futures = histogramSnapshotFutures.get(name);
		} else {
			futures = new ArrayList<>();
			histogramSnapshotFutures.put(name, futures);
		}

		CompletableFuture<Snapshot> future = new CompletableFuture<>();
		futures.add(future);

		return future;
	}
}
 
Example #5
Source File: HistogramSerializer.java    From watcher with Apache License 2.0 6 votes vote down vote up
@Override
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
	Histogram histogram = (Histogram) object;
	SerializeWriter writer = serializer.getWriter();
	final Snapshot snapshot = histogram.getSnapshot();
	writer.writeFieldValue('{', "count", histogram.getCount());
	writer.writeFieldValue(',', "max", snapshot.getMax());
	writer.writeFieldValue(',', "mean", snapshot.getMean());
	writer.writeFieldValue(',', "min", snapshot.getMin());
	writer.writeFieldValue(',', "p50", snapshot.getMedian());
	writer.writeFieldValue(',', "p75", snapshot.get75thPercentile());
	writer.writeFieldValue(',', "p95", snapshot.get95thPercentile());
	writer.writeFieldValue(',', "p98", snapshot.get98thPercentile());
	writer.writeFieldValue(',', "p99", snapshot.get99thPercentile());
	writer.writeFieldValue(',', "p999", snapshot.get999thPercentile());
	writer.writeFieldValue(',', "stddev", snapshot.getStdDev());
	writer.write('}');
}
 
Example #6
Source File: OverflowResolverTest.java    From rolling-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void testSkipBigValues() {
    Reservoir reservoir = new HdrBuilder().withHighestTrackableValue(100, OverflowResolver.SKIP).buildReservoir();

    reservoir.update(101);
    Snapshot snapshot = reservoir.getSnapshot();
    assertEquals(0, snapshot.getMax());

    reservoir.update(100);
    snapshot = reservoir.getSnapshot();
    assertEquals(100, snapshot.getMax());

    reservoir.update(99);
    snapshot = reservoir.getSnapshot();
    assertEquals(99, snapshot.getMin());
}
 
Example #7
Source File: MqMetricReporter.java    From pmq with Apache License 2.0 6 votes vote down vote up
private Set<Metric> buildHistograms(String name, Histogram histogram, long timestamp, Map<String, String> tags) {
    final MetricsCollector collector = MetricsCollector.createNew(name, tags, timestamp);
    final Snapshot snapshot = histogram.getSnapshot();
    if (getChangeCount(name, histogram.getCount()) == 0) {
        return Collections.emptySet();
    }
    return collector.addMetric("count", histogram.getCount())
            .addMetric("max", snapshot.getMax())
            .addMetric("min", snapshot.getMin())
            .addMetric("mean", snapshot.getMean())
            .addMetric("stddev", snapshot.getStdDev())
            .addMetric("median", snapshot.getMedian())
            .addMetric("p75", snapshot.get75thPercentile())
            .addMetric("p95", snapshot.get95thPercentile())
            .addMetric("p98", snapshot.get98thPercentile())
            .addMetric("p99", snapshot.get99thPercentile())
            .addMetric("p999", snapshot.get999thPercentile())
            .build();
}
 
Example #8
Source File: MqMetricReporter.java    From pmq with Apache License 2.0 6 votes vote down vote up
private Set<Metric> buildTimers(String name, Timer timer, long timestamp, Map<String, String> tags) {
	final MetricsCollector collector = MetricsCollector.createNew(name, tags, timestamp);
	final Snapshot snapshot = timer.getSnapshot();
	if (getChangeCount(name, timer.getCount()) == 0) {
		return Collections.emptySet();
	}
	return collector.addMetric("count", timer.getCount())
			// convert rate
			.addMetric("m15", convertRate(timer.getFifteenMinuteRate()))
			.addMetric("m5", convertRate(timer.getFiveMinuteRate()))
			.addMetric("m1", convertRate(timer.getOneMinuteRate()))
			.addMetric("mean_rate", convertRate(timer.getMeanRate()))
			// convert duration
			.addMetric("max", convertDuration(snapshot.getMax()))
			.addMetric("min", convertDuration(snapshot.getMin()))
			.addMetric("mean", convertDuration(snapshot.getMean()))
			.addMetric("stddev", convertDuration(snapshot.getStdDev()))
			.addMetric("median", convertDuration(snapshot.getMedian()))
			.addMetric("p75", convertDuration(snapshot.get75thPercentile()))
			.addMetric("p95", convertDuration(snapshot.get95thPercentile()))
			.addMetric("p98", convertDuration(snapshot.get98thPercentile()))
			.addMetric("p99", convertDuration(snapshot.get99thPercentile()))
			.addMetric("p999", convertDuration(snapshot.get999thPercentile())).build();
}
 
Example #9
Source File: StatsTracker.java    From raml-module-builder with Apache License 2.0 6 votes vote down vote up
public static JsonObject calculateStatsFor(String type){
  JsonObject j = new JsonObject();
  Snapshot snap = METRICS.histogram(type).getSnapshot();
  if(snap != null){
    j.put("entryCount", snap.size());
    j.put("min", snap.getMin());
    j.put("max", snap.getMax());
    j.put("mean", snap.getMean());
    j.put("median", snap.getMedian());
    j.put("75th", snap.get75thPercentile());
    j.put("95th", snap.get95thPercentile());
    j.put("99th", snap.get99thPercentile());
    j.put("stdDev", snap.getStdDev());
  }
  return j;
}
 
Example #10
Source File: MqMetricReporter.java    From pmq with Apache License 2.0 6 votes vote down vote up
private Set<Metric> buildHistograms(String name, Histogram histogram, long timestamp, Map<String, String> tags) {
    final MetricsCollector collector = MetricsCollector.createNew(name, tags, timestamp);
    final Snapshot snapshot = histogram.getSnapshot();
    if (getChangeCount(name, histogram.getCount()) == 0) {
        return Collections.emptySet();
    }
    return collector.addMetric("count", histogram.getCount())
            .addMetric("max", snapshot.getMax())
            .addMetric("min", snapshot.getMin())
            .addMetric("mean", snapshot.getMean())
            .addMetric("stddev", snapshot.getStdDev())
            .addMetric("median", snapshot.getMedian())
            .addMetric("p75", snapshot.get75thPercentile())
            .addMetric("p95", snapshot.get95thPercentile())
            .addMetric("p98", snapshot.get98thPercentile())
            .addMetric("p99", snapshot.get99thPercentile())
            .addMetric("p999", snapshot.get999thPercentile())
            .build();
}
 
Example #11
Source File: ResetOnSnapshotAccumulatorTest.java    From rolling-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCacheSnapshot() {
    Reservoir reservoir = new HdrBuilder().resetReservoirOnSnapshot().buildReservoir();

    reservoir.update(10);
    reservoir.update(20);
    Snapshot firstSnapshot = reservoir.getSnapshot();

    reservoir.update(30);
    reservoir.update(40);
    Snapshot secondSnapshot = reservoir.getSnapshot();
    assertNotSame(firstSnapshot, secondSnapshot);
    assertEquals(30, secondSnapshot.getMin());
    assertEquals(40, secondSnapshot.getMax());

    reservoir.update(50);
    reservoir.update(60);
    Snapshot thirdSnapshot = reservoir.getSnapshot();
    assertNotSame(secondSnapshot, thirdSnapshot);
    assertEquals(50, thirdSnapshot.getMin());
    assertEquals(60, thirdSnapshot.getMax());
}
 
Example #12
Source File: HistogramConverter.java    From cf-java-logging-support with Apache License 2.0 6 votes vote down vote up
@Override
protected List<Metric> convertMetricEntry(Entry<String, Histogram> metricEntry, long timestamp) {
    List<Metric> result = new ArrayList<>();
    Histogram histogram = metricEntry.getValue();
    Snapshot snapshot = histogram.getSnapshot();
    String key = metricEntry.getKey();
    MetricType type = MetricType.HISTOGRAM;

    result.add(buildCustomMetric(key + ".count", histogram.getCount(), type, timestamp));
    result.add(buildCustomMetric(key + ".max", snapshot.getMax(), type, timestamp));
    result.add(buildCustomMetric(key + ".min", snapshot.getMin(), type, timestamp));
    result.add(buildCustomMetric(key + ".p50", snapshot.getMedian(), type, timestamp));
    result.add(buildCustomMetric(key + ".p95", snapshot.get95thPercentile(), type, timestamp));
    result.add(buildCustomMetric(key + ".p99", snapshot.get99thPercentile(), type, timestamp));

    if (metricQuantiles) {
        result.add(buildCustomMetric(key + ".mean", snapshot.getMean(), type, timestamp));
        result.add(buildCustomMetric(key + ".p75", snapshot.get75thPercentile(), type, timestamp));
        result.add(buildCustomMetric(key + ".p98", snapshot.get98thPercentile(), type, timestamp));
        result.add(buildCustomMetric(key + ".p999", snapshot.get999thPercentile(), type, timestamp));
        result.add(buildCustomMetric(key + ".stddev", snapshot.getStdDev(), type, timestamp));
    }

    return result;
}
 
Example #13
Source File: DropwizardFlinkHistogramWrapperTest.java    From flink with Apache License 2.0 6 votes vote down vote up
Future<Snapshot> getNextHistogramSnapshot(String name) {
	synchronized (histogramSnapshotFutures) {
		List<CompletableFuture<Snapshot>> futures;
		if (histogramSnapshotFutures.containsKey(name)) {
			futures = histogramSnapshotFutures.get(name);
		} else {
			futures = new ArrayList<>();
			histogramSnapshotFutures.put(name, futures);
		}

		CompletableFuture<Snapshot> future = new CompletableFuture<>();
		futures.add(future);

		return future;
	}
}
 
Example #14
Source File: NewtsReporter.java    From newts with Apache License 2.0 6 votes vote down vote up
private void reportTimer(List<Sample> samples, Timestamp timestamp, String name, Timer timer) {
    final Snapshot snapshot = timer.getSnapshot();
    Map<String, String> rateAttr = Maps.newHashMap();
    rateAttr.put("rate_unit", getRateUnit());
    Map<String, String> durationAttr = Maps.newHashMap();
    durationAttr.put("duration_unit", getDurationUnit());
    reportC(samples, timestamp, name, "count",     timer.getCount());
    reportG(samples, timestamp, name, "max",       convertDuration(snapshot.getMax()), durationAttr);
    reportG(samples, timestamp, name, "mean",      convertDuration(snapshot.getMean()), durationAttr);
    reportG(samples, timestamp, name, "min",       convertDuration(snapshot.getMin()), durationAttr);
    reportG(samples, timestamp, name, "stddev",    convertDuration(snapshot.getStdDev()), durationAttr);
    reportG(samples, timestamp, name, "p50",       convertDuration(snapshot.getMedian()), durationAttr);
    reportG(samples, timestamp, name, "p75",       convertDuration(snapshot.get75thPercentile()), durationAttr);
    reportG(samples, timestamp, name, "p95",       convertDuration(snapshot.get95thPercentile()), durationAttr);
    reportG(samples, timestamp, name, "p98",       convertDuration(snapshot.get98thPercentile()), durationAttr);
    reportG(samples, timestamp, name, "p99",       convertDuration(snapshot.get99thPercentile()), durationAttr);
    reportG(samples, timestamp, name, "p999",      convertDuration(snapshot.get999thPercentile()), durationAttr);
    reportG(samples, timestamp, name, "mean_rate", convertRate(timer.getMeanRate()), rateAttr);
    reportG(samples, timestamp, name, "m1_rate",   convertRate(timer.getOneMinuteRate()), rateAttr);
    reportG(samples, timestamp, name, "m5_rate",   convertRate(timer.getFiveMinuteRate()), rateAttr);
    reportG(samples, timestamp, name, "m15_rate",  convertRate(timer.getFifteenMinuteRate()), rateAttr);
}
 
Example #15
Source File: OverflowResolverTest.java    From rolling-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void testReduceBigValuesToMax() {
    Reservoir reservoir = new HdrBuilder().withHighestTrackableValue(100, OverflowResolver.REDUCE_TO_HIGHEST_TRACKABLE).buildReservoir();

    reservoir.update(101);
    Snapshot snapshot = reservoir.getSnapshot();
    assertEquals(100, snapshot.getMax());

    reservoir.update(100);
    snapshot = reservoir.getSnapshot();
    assertEquals(100, snapshot.getMax());

    reservoir.update(99);
    snapshot = reservoir.getSnapshot();
    assertEquals(99, snapshot.getMin());
}
 
Example #16
Source File: CloudWatchReporter.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 6 votes vote down vote up
/**
 * The {@link Snapshot} values of {@link Histogram} are reported as {@link StatisticSet} raw. In other words, the
 * conversion using the duration factor does NOT apply.
 * <p>
 * Please note, the reported values submitted only if they show some data (greater than zero) in order to:
 * <p>
 * 1. save some money
 * 2. prevent com.amazonaws.services.cloudwatch.model.InvalidParameterValueException if empty {@link Snapshot}
 * is submitted
 * <p>
 * If {@link Builder#withZeroValuesSubmission()} is {@code true}, then all values will be submitted
 *
 * @see Histogram#getSnapshot
 */
private void processHistogram(final String metricName, final Histogram histogram, final List<MetricDatum> metricData) {
    final Snapshot snapshot = histogram.getSnapshot();

    if (builder.withZeroValuesSubmission || snapshot.size() > 0) {
        for (final Percentile percentile : builder.percentiles) {
            final double value = snapshot.getValue(percentile.getQuantile());
            stageMetricDatum(true, metricName, value, StandardUnit.NONE, percentile.getDesc(), metricData);
        }
    }

    // prevent empty snapshot from causing InvalidParameterValueException
    if (snapshot.size() > 0) {
        stageMetricDatum(builder.withArithmeticMean, metricName, snapshot.getMean(), StandardUnit.NONE, DIMENSION_SNAPSHOT_MEAN, metricData);
        stageMetricDatum(builder.withStdDev, metricName, snapshot.getStdDev(), StandardUnit.NONE, DIMENSION_SNAPSHOT_STD_DEV, metricData);
        stageMetricDatumWithRawSnapshot(builder.withStatisticSet, metricName, snapshot, StandardUnit.NONE, metricData);
    }
}
 
Example #17
Source File: IrisMetricsFormat.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
public static JsonObject toJson(String name, long count, Snapshot snap, List<TagValue> tags, double factor) {
   return toJson(
      name,
      count,
      snap.getMin()*factor,
      snap.getMax()*factor,
      snap.getMean()*factor,
      snap.getStdDev()*factor,
      snap.getMedian()*factor,
      snap.get75thPercentile()*factor,
      snap.get95thPercentile()*factor,
      snap.get98thPercentile()*factor,
      snap.get99thPercentile()*factor,
      snap.get999thPercentile()*factor,
      tags
   );
}
 
Example #18
Source File: Helper.java    From vertx-dropwizard-metrics with Apache License 2.0 6 votes vote down vote up
private static JsonObject toJson(Timer timer, TimeUnit rateUnit, TimeUnit durationUnit) {
  Snapshot snapshot = timer.getSnapshot();
  JsonObject json = new JsonObject();

  json.put("type", "timer");

  if (timer instanceof ThroughputTimer) {
    ThroughputTimer throughput = (ThroughputTimer) timer;
    json.put("oneSecondRate", throughput.getValue());
  }

  // Meter
  populateMetered(json, timer, rateUnit);

  // Snapshot
  double factor = 1.0 / durationUnit.toNanos(1);
  populateSnapshot(json, snapshot, factor);

  // Duration rate
  String duration = durationUnit.toString().toLowerCase();
  json.put("durationRate", duration);

  return json;
}
 
Example #19
Source File: DropwizardMetricsExporter.java    From dropwizard-prometheus with Apache License 2.0 6 votes vote down vote up
private void writeSnapshotAndCount(String dropwizardName, Snapshot snapshot, long count, double factor, MetricType type, String helpMessage) throws IOException {
    String name = sanitizeMetricName(dropwizardName);
    writer.writeHelp(name, helpMessage);
    writer.writeType(name, type);
    writer.writeSample(name, mapOf("quantile", "0.5"), snapshot.getMedian() * factor);
    writer.writeSample(name, mapOf("quantile", "0.75"), snapshot.get75thPercentile() * factor);
    writer.writeSample(name, mapOf("quantile", "0.95"), snapshot.get95thPercentile() * factor);
    writer.writeSample(name, mapOf("quantile", "0.98"), snapshot.get98thPercentile() * factor);
    writer.writeSample(name, mapOf("quantile", "0.99"), snapshot.get99thPercentile() * factor);
    writer.writeSample(name, mapOf("quantile", "0.999"), snapshot.get999thPercentile() * factor);
    writer.writeSample(name + "_min", emptyMap(), snapshot.getMin());
    writer.writeSample(name + "_max", emptyMap(), snapshot.getMax());
    writer.writeSample(name + "_median", emptyMap(), snapshot.getMedian());
    writer.writeSample(name + "_mean", emptyMap(), snapshot.getMean());
    writer.writeSample(name + "_stddev", emptyMap(), snapshot.getStdDev());
    writer.writeSample(name + "_count", emptyMap(), count);
}
 
Example #20
Source File: SlidingWindowHistogramReservoirTest.java    From styx with Apache License 2.0 6 votes vote down vote up
@Test
public void invalidatesCachedSnapshotEverySlidingWindowTimeLength() {
    TestClock clock = new TestClock();
    SlidingWindowHistogram histogram = new SlidingWindowHistogram.Builder()
            .numberOfIntervals(12)
            .intervalDuration(10, SECONDS)
            .autoResize(true)
            .build();

    SlidingWindowHistogramReservoir reservoir = new SlidingWindowHistogramReservoir(histogram, clock);
    reservoir.update(5);
    reservoir.update(6);
    reservoir.update(7);

    Snapshot snapshot1 = reservoir.getSnapshot();
    Snapshot snapshot2 = reservoir.getSnapshot();

    clock.forward(120 * 1000);
    assertThat(snapshot1, sameInstance(snapshot2));

    clock.forward(1);
    assertThat(reservoir.getSnapshot(), not(sameInstance(snapshot2)));
}
 
Example #21
Source File: YammerHistogramUtils.java    From hbase with Apache License 2.0 6 votes vote down vote up
/** @return pretty summary of {@code hist}. */
public static String getPrettyHistogramReport(final Histogram h) {
  Snapshot sn = h.getSnapshot();
  return
      "Mean      = " + DOUBLE_FORMAT.format(sn.getMean()) + "\n" +
      "Min       = " + DOUBLE_FORMAT.format(sn.getMin()) + "\n" +
      "Max       = " + DOUBLE_FORMAT.format(sn.getMax()) + "\n" +
      "StdDev    = " + DOUBLE_FORMAT.format(sn.getStdDev()) + "\n" +
      "50th      = " + DOUBLE_FORMAT.format(sn.getMedian()) + "\n" +
      "75th      = " + DOUBLE_FORMAT.format(sn.get75thPercentile()) + "\n" +
      "95th      = " + DOUBLE_FORMAT.format(sn.get95thPercentile()) + "\n" +
      "99th      = " + DOUBLE_FORMAT.format(sn.get99thPercentile()) + "\n" +
      "99.9th    = " + DOUBLE_FORMAT.format(sn.get999thPercentile()) + "\n" +
      "99.99th   = " + DOUBLE_FORMAT.format(sn.getValue(0.9999)) + "\n" +
      "99.999th  = " + DOUBLE_FORMAT.format(sn.getValue(0.99999));
}
 
Example #22
Source File: GraphiteReporter.java    From styx with Apache License 2.0 6 votes vote down vote up
private void reportHistogram(String name, Histogram histogram, long timestamp) {
    final Snapshot snapshot = histogram.getSnapshot();

    HistogramPrefixes histogramPrefixes = this.histogramPrefixes.getUnchecked(name);

    doSend(histogramPrefixes.count, histogram.getCount(), timestamp);
    doSend(histogramPrefixes.max, snapshot.getMax(), timestamp);
    doSend(histogramPrefixes.mean, snapshot.getMean(), timestamp);
    doSend(histogramPrefixes.min, snapshot.getMin(), timestamp);
    doSend(histogramPrefixes.stddev, snapshot.getStdDev(), timestamp);
    doSend(histogramPrefixes.p50, snapshot.getMedian(), timestamp);
    doSend(histogramPrefixes.p75, snapshot.get75thPercentile(), timestamp);
    doSend(histogramPrefixes.p95, snapshot.get95thPercentile(), timestamp);
    doSend(histogramPrefixes.p98, snapshot.get98thPercentile(), timestamp);
    doSend(histogramPrefixes.p99, snapshot.get99thPercentile(), timestamp);
    doSend(histogramPrefixes.p999, snapshot.get999thPercentile(), timestamp);
}
 
Example #23
Source File: MetricUtils.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Convert an instance of {@link Histogram}. NOTE: it's assumed that histogram contains non-time
 * based values that don't require unit conversion.
 * @param name metric name
 * @param histogram an instance of {@link Histogram}
 * @param propertyFilter limit what properties of a metric are returned
 * @param simple use simplified representation for complex metrics - instead of a (name, map)
 *             only the selected (name "." key, value) pairs will be produced.
 * @param consumer consumer that accepts produced objects
 */
static void convertHistogram(String name, Histogram histogram, PropertyFilter propertyFilter,
                                            boolean simple, String separator, BiConsumer<String, Object> consumer) {
  Snapshot snapshot = histogram.getSnapshot();
  if (simple) {
    if (propertyFilter.accept(MEAN)) {
      consumer.accept(name + separator + MEAN, snapshot.getMean());
    }
  } else {
    Map<String, Object> response = new LinkedHashMap<>();
    String prop = "count";
    if (propertyFilter.accept(prop)) {
      response.put(prop, histogram.getCount());
    }
    // non-time based values
    addSnapshot(response, snapshot, propertyFilter, false);
    if (!response.isEmpty()) {
      consumer.accept(name, response);
    }
  }
}
 
Example #24
Source File: InfluxDbReporterTest.java    From dropwizard-metrics-influxdb with Apache License 2.0 5 votes vote down vote up
@Test
public void reportsHistograms() 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(histogram.getSnapshot()).thenReturn(snapshot);

    reporter.report(this.<Gauge>map(), this.<Counter>map(), this.map("histogram", histogram), this.<Meter>map(), this.<Timer>map());

    final ArgumentCaptor<InfluxDbPoint> influxDbPointCaptor = ArgumentCaptor.forClass(InfluxDbPoint.class);
    verify(influxDb, atLeastOnce()).appendPoints(influxDbPointCaptor.capture());
    InfluxDbPoint point = influxDbPointCaptor.getValue();

    assertThat(point.getMeasurement()).isEqualTo("histogram");
    assertThat(point.getFields()).isNotEmpty();
    assertThat(point.getFields()).hasSize(11);
    assertThat(point.getFields()).contains(entry("max", 2L));
    assertThat(point.getFields()).contains(entry("mean", 3.0));
    assertThat(point.getFields()).contains(entry("min", 4L));
    assertThat(point.getFields()).contains(entry("stddev", 5.0));
    assertThat(point.getFields()).contains(entry("p50", 6.0));
    assertThat(point.getFields()).contains(entry("p75", 7.0));
    assertThat(point.getFields()).contains(entry("p95", 8.0));
    assertThat(point.getFields()).contains(entry("p98", 9.0));
    assertThat(point.getFields()).contains(entry("p99", 10.0));
    assertThat(point.getFields()).contains(entry("p999", 11.0));
    assertThat(point.getTags()).containsEntry("metricName", "histogram");
}
 
Example #25
Source File: GraphiteReporterTest.java    From styx with Apache License 2.0 5 votes vote down vote up
@Test
public void reportsHistograms() throws Exception {
    Histogram histogram = mock(Histogram.class);
    when(histogram.getCount()).thenReturn(1L);

    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(histogram.getSnapshot()).thenReturn(snapshot);

    reporter.report(emptyMap(), emptyMap(), map("histogram", histogram), emptyMap(), emptyMap());

    InOrder inOrder = inOrder(graphite);
    inOrder.verify(graphite).connect();
    inOrder.verify(graphite).send("prefix.histogram.count", "1", TIMESTAMP);
    inOrder.verify(graphite).send("prefix.histogram.max", "2", TIMESTAMP);
    inOrder.verify(graphite).send("prefix.histogram.mean", "3.00", TIMESTAMP);
    inOrder.verify(graphite).send("prefix.histogram.min", "4", TIMESTAMP);
    inOrder.verify(graphite).send("prefix.histogram.stddev", "5.00", TIMESTAMP);
    inOrder.verify(graphite).send("prefix.histogram.p50", "6.00", TIMESTAMP);
    inOrder.verify(graphite).send("prefix.histogram.p75", "7.00", TIMESTAMP);
    inOrder.verify(graphite).send("prefix.histogram.p95", "8.00", TIMESTAMP);
    inOrder.verify(graphite).send("prefix.histogram.p98", "9.00", TIMESTAMP);
    inOrder.verify(graphite).send("prefix.histogram.p99", "10.00", TIMESTAMP);
    inOrder.verify(graphite).send("prefix.histogram.p999", "11.00", TIMESTAMP);
    inOrder.verify(graphite).flush();
    inOrder.verify(graphite).close();

    verifyNoMoreInteractions(graphite);
}
 
Example #26
Source File: ZabbixReporter.java    From metrics-zabbix with Apache License 2.0 5 votes vote down vote up
/**
 * for histograms.
 * 
 * @param key
 * @param snapshot
 * @param dataObjectList
 */
private void addSnapshotDataObject(String key, Snapshot snapshot, long clock, List<DataObject> dataObjectList) {
	dataObjectList.add(toDataObject(key, ".min", snapshot.getMin(), clock));
	dataObjectList.add(toDataObject(key, ".max", snapshot.getMax(), clock));
	dataObjectList.add(toDataObject(key, ".mean", snapshot.getMean(), clock));
	dataObjectList.add(toDataObject(key, ".stddev", snapshot.getStdDev(), clock));
	dataObjectList.add(toDataObject(key, ".median", snapshot.getMedian(), clock));
	dataObjectList.add(toDataObject(key, ".75th", snapshot.get75thPercentile(), clock));
	dataObjectList.add(toDataObject(key, ".95th", snapshot.get95thPercentile(), clock));
	dataObjectList.add(toDataObject(key, ".98th", snapshot.get98thPercentile(), clock));
	dataObjectList.add(toDataObject(key, ".99th", snapshot.get99thPercentile(), clock));
	dataObjectList.add(toDataObject(key, ".99.9th", snapshot.get999thPercentile(), clock));
}
 
Example #27
Source File: PercentileCalculationTest.java    From rolling-metrics with Apache License 2.0 5 votes vote down vote up
@Test
public void testFullSnapshotCalculation() {
    Reservoir reservoir = new HdrBuilder().withoutSnapshotOptimization().buildReservoir();
    Snapshot snapshot = snapshotTaker.apply(reservoir);

    Histogram hdrHistogram = createEquivalentHistogram();
    assertEquals(hdrHistogram.getStdDeviation(), snapshot.getStdDev());
    assertEquals(hdrHistogram.getMinValue(), snapshot.getMin());
    assertEquals(hdrHistogram.getMean(), snapshot.getMean());
    assertEquals(hdrHistogram.getValueAtPercentile(50.0), (long) snapshot.getMedian());
    assertEquals(hdrHistogram.getMaxValue(), snapshot.getMax());
    assertEquals(hdrHistogram.getValueAtPercentile(60.0), (long) snapshot.getValue(0.6));
    assertEquals(hdrHistogram.getValueAtPercentile(75.0), (long) snapshot.get75thPercentile());
    assertEquals(hdrHistogram.getValueAtPercentile(80.0), (long) snapshot.getValue(0.8));
    assertEquals(hdrHistogram.getValueAtPercentile(90.0), (long) snapshot.getValue(0.9));
    assertEquals(hdrHistogram.getValueAtPercentile(94.0), (long) snapshot.getValue(0.94));
    assertEquals(hdrHistogram.getValueAtPercentile(95.0), (long) snapshot.get95thPercentile());
    assertEquals(hdrHistogram.getValueAtPercentile(98.0), (long) snapshot.get98thPercentile());
    assertEquals(hdrHistogram.getValueAtPercentile(99.0), (long) snapshot.get99thPercentile());
    assertEquals(hdrHistogram.getValueAtPercentile(99.9), (long) snapshot.get999thPercentile());

    assertEquals(hdrHistogram.getTotalCount(), snapshot.size());

    int i = 0;
    long[] values = snapshot.getValues();
    for (HistogramIterationValue value : hdrHistogram.recordedValues()) {
        assertEquals(value.getValueIteratedTo(), values[i++]);
    }
}
 
Example #28
Source File: ReservoirWithTtl.java    From semantic-metrics with Apache License 2.0 5 votes vote down vote up
@Override
public Snapshot getSnapshot() {
    if (useInternalBuffer()) {
        return getInternalSnapshot(filteredValues());
    }
    return delegate.getSnapshot();
}
 
Example #29
Source File: ZabbixReporter.java    From metrics-zabbix with Apache License 2.0 5 votes vote down vote up
/**
 * for timer.
 * 
 * @param key
 * @param snapshot
 * @param dataObjectList
 */
private void addSnapshotDataObjectWithConvertDuration(String key, Snapshot snapshot, long clock,
		List<DataObject> dataObjectList) {
	dataObjectList.add(toDataObject(key, ".min", convertDuration(snapshot.getMin()), clock));
	dataObjectList.add(toDataObject(key, ".max", convertDuration(snapshot.getMax()), clock));
	dataObjectList.add(toDataObject(key, ".mean", convertDuration(snapshot.getMean()), clock));
	dataObjectList.add(toDataObject(key, ".stddev", convertDuration(snapshot.getStdDev()), clock));
	dataObjectList.add(toDataObject(key, ".median", convertDuration(snapshot.getMedian()), clock));
	dataObjectList.add(toDataObject(key, ".75th", convertDuration(snapshot.get75thPercentile()), clock));
	dataObjectList.add(toDataObject(key, ".95th", convertDuration(snapshot.get95thPercentile()), clock));
	dataObjectList.add(toDataObject(key, ".98th", convertDuration(snapshot.get98thPercentile()), clock));
	dataObjectList.add(toDataObject(key, ".99th", convertDuration(snapshot.get99thPercentile()), clock));
	dataObjectList.add(toDataObject(key, ".99.9th", convertDuration(snapshot.get999thPercentile()), clock));
}
 
Example #30
Source File: ReservoirWithTtl.java    From semantic-metrics with Apache License 2.0 5 votes vote down vote up
private Snapshot getInternalSnapshot(final List<Long> filteredValues) {
    try {
        // See comment at static initializer why we need to use constructor reference
        return (Snapshot) snapshotConstructor.newInstance(filteredValues);
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}