@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()); }
@Override public void jsonData(JsonObjectBuilder builder) { JsonObjectBuilder myBuilder = JSON.createObjectBuilder(); myBuilder.add("count", getCount()); myBuilder.add("meanRate", getMeanRate()); myBuilder.add("oneMinRate", getOneMinuteRate()); myBuilder.add("fiveMinRate", getFiveMinuteRate()); myBuilder.add("fifteenMinRate", getFifteenMinuteRate()); 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()); }
public double getP999() { return getSnapshot().get999thPercentile(); }
public double getP999() { return getSnapshot().get999thPercentile(); }
@Test public void testSnapshot999thPercentile() throws Exception { TestUtils.assertEqualsWithTolerance(99, histogramInt.getSnapshot().get999thPercentile()); TestUtils.assertEqualsWithTolerance(990, histogramLong.getSnapshot().get999thPercentile()); }
@Test public void testSnapshot999thPercentile() throws Exception { TestUtils.assertEqualsWithTolerance(990, globalTimer.getSnapshot().get999thPercentile()); }
private StringBuilder toPrometheus(final String registryKey, final String keyBase, final String keyUnit, final Snapshot snapshot, final Metadata metadata) { final Function<Map<String, String>, Metadata> metaFactory = tag -> new Metadata(metadata.getName(), metadata.getDisplayName(), metadata.getDescription(), metadata.getTypeRaw(), metadata.getUnit(), Stream.concat(metadata.getTags().entrySet().stream(), tag.entrySet().stream()) .map(e -> e.getKey() + '=' + e.getValue()) .collect(joining(","))); final String completeKey = keyBase + keyUnit; return new StringBuilder() .append(value(registryKey, keyBase + "_min" + keyUnit, snapshot.getMin(), metadata)) .append(value(registryKey, keyBase + "_max" + keyUnit, snapshot.getMax(), metadata)) .append(value(registryKey, keyBase + "_mean" + keyUnit, snapshot.getMean(), metadata)) .append(value(registryKey, keyBase + "_stddev" + keyUnit, snapshot.getStdDev(), metadata)) .append(value(registryKey, completeKey, snapshot.getMedian(), metaFactory.apply(singletonMap("quantile", "0.5")))) .append(value(registryKey, completeKey, snapshot.get75thPercentile(), metaFactory.apply(singletonMap("quantile", "0.75")))) .append(value(registryKey, completeKey, snapshot.get95thPercentile(), metaFactory.apply(singletonMap("quantile", "0.95")))) .append(value(registryKey, completeKey, snapshot.get98thPercentile(), metaFactory.apply(singletonMap("quantile", "0.98")))) .append(value(registryKey, completeKey, snapshot.get99thPercentile(), metaFactory.apply(singletonMap("quantile", "0.99")))) .append(value(registryKey, completeKey, snapshot.get999thPercentile(), metaFactory.apply(singletonMap("quantile", "0.999")))); }
json.writeObjectField("p98", snapshot.get98thPercentile()); json.writeObjectField("p99", snapshot.get99thPercentile()); json.writeObjectField("p999", snapshot.get999thPercentile()); json.writeEndObject(); } else if(metric instanceof Timer) { json.writeObjectField("p98", snapshot.get98thPercentile()); json.writeObjectField("p99", snapshot.get99thPercentile()); json.writeObjectField("p999", snapshot.get999thPercentile()); json.writeEndObject();
@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)); }
double percentile98th = sampling.getSnapshot().get98thPercentile(); double percentile99th = sampling.getSnapshot().get99thPercentile(); double percentile999th = sampling.getSnapshot().get999thPercentile(); percentile98th = sampling.getSnapshot().get98thPercentile() * conversionFactor; percentile99th = sampling.getSnapshot().get99thPercentile() * conversionFactor; percentile999th = sampling.getSnapshot().get999thPercentile() * conversionFactor;