@Override public void update(int value) { delegate.update(value); }
@Override public long getCount() { return histogram.getCount(); }
@Override public Snapshot getSnapshot() { return histogram.getSnapshot(); }
@Test @InSequence(2) public void updateHistogramField() { assertThat("Histogram is not registered correctly", registry.getHistograms(), hasKey(HISTOGRAM_NAME)); Histogram histogram = registry.getHistograms().get(HISTOGRAM_NAME); // Call the update method and assert the histogram is up-to-date long value = Math.round(Math.random() * Long.MAX_VALUE); bean.update(value); assertThat("Histogram count is incorrect", histogram.getCount(), is(equalTo(1L))); assertThat("Histogram size is incorrect", histogram.getSnapshot().size(), is(equalTo(1))); assertThat("Histogram min value is incorrect", histogram.getSnapshot().getMin(), is(equalTo(value))); assertThat("Histogram max value is incorrect", histogram.getSnapshot().getMax(), is(equalTo(value))); } }
Snapshot snap = executionTimes.getSnapshot(); assertThat("histogram count", executionTimes.getCount(), is(2L)); // Rejected executions not recorded in histogram assertThat("median", snap.getMedian(), approxMillis(1000)); assertThat("mean", snap.getMean(), approxMillis(1000)); snap = executionTimes.getSnapshot(); assertThat("histogram count", executionTimes.getCount(), is(12L)); assertThat("median", snap.getMedian(), approxMillis(0)); assertThat("75th percentile", snap.get75thPercentile(), approxMillis(0));
@Override public void update(long value) { delegate.update(value); }
} else if(metric instanceof Histogram) { Histogram histogram = (Histogram)metric; Snapshot snapshot = histogram.getSnapshot(); json.writeStartObject(); json.writeObjectField("count", histogram.getCount()); json.writeObjectField("min", snapshot.getMin()); json.writeObjectField("max", snapshot.getMax());
@Override public Snapshot getSnapshot() { return delegate.getSnapshot(); }
@Override public long getCount() { return delegate.getCount(); }
private void update(long nanos) { if (nanos >= 0) { histogram.update(nanos); meter.mark(); } }
return new StringBuilder() .append(type(registryKey, keyBase + keyUnit + " summary", entry.metadata)) .append(value(registryKey, keyBase + keyUnit + "_count", histogram.getCount(), entry.metadata)) .append(toPrometheus(registryKey, keyBase, keyUnit, histogram.getSnapshot(), entry.metadata)); default: return new StringBuilder();
@Override @JsonbTransient public Snapshot getSnapshot() { return histogram.getSnapshot(); }
@Override public long getCount() { return histogram.getCount(); }
histogram = getHistogram(method, BULKHEAD_WAITING_DURATION); histogram.update(System.nanoTime() - queuedNanos);
@Test public void testTimeoutHistogram() { MetricGetter m = new MetricGetter(TimeoutMetricBean.class, "histogramTestWorkForMillis"); timeoutBean.histogramTestWorkForMillis(100); timeoutBean.histogramTestWorkForMillis(100); timeoutBean.histogramTestWorkForMillis(100); timeoutBean.histogramTestWorkForMillis(100); timeoutBean.histogramTestWorkForMillis(100); // 50th Percentile timeoutBean.histogramTestWorkForMillis(100); timeoutBean.histogramTestWorkForMillis(1000); timeoutBean.histogramTestWorkForMillis(1000); // 75th Percentile expectTimeout(() -> timeoutBean.histogramTestWorkForMillis(5000)); // Will timeout after 2000 expectTimeout(() -> timeoutBean.histogramTestWorkForMillis(5000)); // Will timeout after 2000 Histogram histogram = m.getTimeoutExecutionDuration().get(); Snapshot snapshot = histogram.getSnapshot(); assertThat("Histogram count", histogram.getCount(), is(10L)); assertThat("Median", snapshot.getMedian(), MetricComparator.approxMillis(100)); assertThat("75th percentile", snapshot.get75thPercentile(), MetricComparator.approxMillis(1000)); assertThat("99th percentile", snapshot.get99thPercentile(), MetricComparator.approxMillis(2000)); assertThat("99.9th percentile", snapshot.get999thPercentile(), MetricComparator.approxMillis(2000)); }
@Test public void testSnapshotValues() throws Exception { Assert.assertArrayEquals( "The histogramInt does not contain the expected values: " + Arrays.toString(SAMPLE_INT_DATA), Arrays.stream(SAMPLE_INT_DATA).asLongStream().toArray(), histogramInt.getSnapshot().getValues()); Assert.assertArrayEquals( "The histogramLong does not contain the expected values: " + Arrays.toString(SAMPLE_LONG_DATA), SAMPLE_LONG_DATA, histogramLong.getSnapshot().getValues()); }
.update(command.getExecutionTime()); getCounter(method, cause instanceof TimeoutException ? TIMEOUT_CALLS_TIMED_OUT_TOTAL boolean bulkheadRejection = (cause instanceof RejectedExecutionException); if (!bulkheadRejection) { getHistogram(method, BULKHEAD_EXECUTION_DURATION).update(command.getExecutionTime());
@Test public void testSnapshotMax() throws Exception { Assert.assertEquals(99, histogramInt.getSnapshot().getMax()); Assert.assertEquals(990, histogramLong.getSnapshot().getMax()); }
public void update(long n) { histogram.update(n); } }