@Override public void jsonData(JsonObjectBuilder builder) { JsonObjectBuilder myBuilder = JSON.createObjectBuilder(); myBuilder.add("count", getCount()); Snapshot snapshot = getSnapshot(); myBuilder.add("min", snapshot.getMin()); myBuilder.add("max", snapshot.getMax()); myBuilder.add("mean", snapshot.getMean()); myBuilder.add("stddev", snapshot.getStdDev()); myBuilder.add("p50", snapshot.getMedian()); myBuilder.add("p75", snapshot.get75thPercentile()); myBuilder.add("p95", snapshot.get95thPercentile()); myBuilder.add("p98", snapshot.get98thPercentile()); myBuilder.add("p99", snapshot.get99thPercentile()); myBuilder.add("p999", snapshot.get999thPercentile()); builder.add(getName(), myBuilder.build()); }
.append(tags) .append(" ") .append(units.convert(snap.getMean())) .append("\n"); .append(tags) .append(" ") .append(units.convert(snap.getMax())) .append("\n"); .append(tags) .append(" ") .append(units.convert(snap.getMin())) .append("\n"); .append(tags) .append(" ") .append(units.convert(snap.getStdDev())) .append("\n");
assertThat("median", snap.getMedian(), approxMillis(1000)); assertThat("mean", snap.getMean(), approxMillis(1000)); assertThat("median", snap.getMedian(), approxMillis(0)); assertThat("75th percentile", snap.get75thPercentile(), approxMillis(0)); assertThat("99th percentile", snap.get99thPercentile(), approxMillis(1000));
@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 @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))); } }
public double getP999() { return getSnapshot().get999thPercentile(); }
public double getP75() { return getSnapshot().get75thPercentile(); }
public double getP99() { return getSnapshot().get99thPercentile(); }
public double getP50() { return getSnapshot().getMedian(); }
public double getMean() { return getSnapshot().getMean(); }
public double getP98() { return getSnapshot().get98thPercentile(); }
public long getMin() { return getSnapshot().getMin(); }
public long getMax() { return getSnapshot().getMax(); }
public double getP95() { return getSnapshot().get95thPercentile(); }
public double getStddev() { return getSnapshot().getStdDev(); }
.append(tags) .append(" ") .append(units.convert(snap.getMean())) .append("\n"); .append(tags) .append(" ") .append(units.convert(snap.getMax())) .append("\n"); .append(tags) .append(" ") .append(units.convert(snap.getMin())) .append("\n"); .append(tags) .append(" ") .append(units.convert(snap.getStdDev())) .append("\n");
public double getP999() { return getSnapshot().get999thPercentile(); }
public double getP75() { return getSnapshot().get75thPercentile(); }
public double getP99() { return getSnapshot().get99thPercentile(); }
public double getP50() { return getSnapshot().getMedian(); }