@Test public void testDoubleMaxGauge() { DoubleGauge c = new DoubleGauge(CONFIG); register(c); c.set(42.0); assertEquals(42.0, registry.maxGauge(ID).value(), 1e-12); }
@Test public void testUnregisteredBasicTimerIncrement() { BasicTimer t = new BasicTimer(CONFIG); t.record(42, TimeUnit.MILLISECONDS); Id id = registry.createId("test") .withTag("unit", "MILLISECONDS"); assertEquals(3, registry.counters().count()); assertEquals(0, registry.timers().count()); assertEquals(1, registry.gauges().count()); assertEquals(0, registry.distributionSummaries().count()); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42, registry.counter(id.withTag(Statistic.totalTime)).count()); assertEquals(42 * 42, registry.counter(id.withTag(Statistic.totalOfSquares)).count()); assertEquals(42.0, registry.maxGauge(id.withTag(Statistic.max)).value()); }
@Test public void testBasicDistributionSummaryRecord() { BasicDistributionSummary d = new BasicDistributionSummary(CONFIG); register(d); d.record(42); assertEquals(1, registry.counter(ID.withTag(Statistic.count)).count()); assertEquals(42, registry.counter(ID.withTag(Statistic.totalAmount)).count()); assertEquals(42.0, registry.maxGauge(ID.withTag(Statistic.max)).value(), 1e-12); }
@Test public void testDynamicTimerRecordSeconds() { DynamicTimer.record(CONFIG, 42); Id id = ID.withTag("unit", "MILLISECONDS"); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42 * 42, registry.counter(id.withTag(Statistic.totalOfSquares)).actualCount(), 1e-12); assertEquals(42, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); }
@Test public void testBasicTimerRecordMillis() { BasicTimer d = new BasicTimer(CONFIG); register(d); d.record(42, TimeUnit.NANOSECONDS); Id id = ID.withTag("unit", "MILLISECONDS"); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42e-6, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42e-6 * 42e-6, registry.counter(id.withTag(Statistic.totalOfSquares)).actualCount(), 1e-12); assertEquals(42e-6, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); }
@Test public void testBasicTimerRecordSeconds() { BasicTimer d = new BasicTimer(CONFIG, TimeUnit.SECONDS); register(d); d.record(42, TimeUnit.NANOSECONDS); Id id = ID.withTag("unit", "SECONDS"); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42e-9, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42e-9 * 42e-9, registry.counter(id.withTag(Statistic.totalOfSquares)).actualCount(), 1e-12); assertEquals(42e-9, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); }
@Test public void testContextualTimerRecordMillis() { TagList context = BasicTagList.of("a", "1"); ContextualTimer d = new ContextualTimer(CONFIG, () -> context, BasicTimer::new); d.record(42, TimeUnit.NANOSECONDS); Id id = ID.withTag("unit", "MILLISECONDS").withTag("a", "1"); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42e-6, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42e-6 * 42e-6, registry.counter(id.withTag(Statistic.totalOfSquares)).actualCount(), 1e-12); assertEquals(42e-6, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); }
@Test public void testBucketTimerRecordMillis() { BucketConfig bc = new BucketConfig.Builder() .withBuckets(new long[] {10L, 50L}) .withTimeUnit(TimeUnit.MILLISECONDS) .build(); BucketTimer d = new BucketTimer(CONFIG, bc); register(d); d.record(42, TimeUnit.MILLISECONDS); Id id = ID.withTag("unit", "MILLISECONDS"); assertEquals(1, registry.counter(id.withTag(Statistic.count).withTag("servo.bucket", "bucket=50ms")).count()); assertEquals(42.0, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42.0, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); }
@Test public void testStatsTimerRecordMillis() { StatsConfig sc = new StatsConfig.Builder() .withPercentiles(new double[] {50.0, 95.0}) .withPublishCount(true) .withPublishMax(true) .withPublishMean(true) .withSampleSize(10) .build(); StatsTimer d = new StatsTimer(CONFIG, sc); register(d); d.record(42, TimeUnit.MILLISECONDS); d.computeStats(); Id id = ID.withTag("unit", "MILLISECONDS"); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42.0, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42.0, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); assertEquals(42.0, registry.gauge(id.withTag("statistic", "percentile_50")).value(), 1e-12); assertEquals(42.0, registry.gauge(id.withTag("statistic", "percentile_95")).value(), 1e-12); assertEquals(42.0, registry.gauge(id.withTag("statistic", "avg")).value(), 1e-12); }
@Override public Gauge lookup() { return registry.maxGauge(id); }
@Override public Gauge maxGauge(Id id) { return impl.maxGauge(id); }
@Override public Gauge maxGauge(Id id) { return impl.maxGauge(id); }
@Override public Gauge lookup() { return registry.maxGauge(id); }
/** * Measures the maximum value recorded since the last reset. * * @param name * Description of the measurement that is being collected. * @return * Gauge instance with the corresponding id. */ default Gauge maxGauge(String name) { return maxGauge(createId(name)); }
/** * Measures the maximum value recorded since the last reset. * * @param name * Description of the measurement that is being collected. * @return * Gauge instance with the corresponding id. */ default Gauge maxGauge(String name) { return maxGauge(createId(name)); }
/** * Measures the maximum value recorded since the last reset. * * @param name * Description of the measurement that is being collected. * @param tags * Other dimensions that can be used to classify the measurement. * @return * Gauge instance with the corresponding id. */ default Gauge maxGauge(String name, Iterable<Tag> tags) { return maxGauge(createId(name, tags)); }
/** * Measures the maximum value recorded since the last reset. * * @param name * Description of the measurement that is being collected. * @param tags * Other dimensions that can be used to classify the measurement. * @return * Gauge instance with the corresponding id. */ default Gauge maxGauge(String name, Iterable<Tag> tags) { return maxGauge(createId(name, tags)); }
/** * Measures the maximum value recorded since the last reset. * * @param name * Description of the measurement that is being collected. * @param tags * Other dimensions that can be used to classify the measurement. * @return * Gauge instance with the corresponding id. */ default Gauge maxGauge(String name, String... tags) { return maxGauge(createId(name, Utils.toIterable(tags))); }
/** * Measures the maximum value recorded since the last reset. * * @param name * Description of the measurement that is being collected. * @param tags * Other dimensions that can be used to classify the measurement. * @return * Gauge instance with the corresponding id. */ default Gauge maxGauge(String name, String... tags) { return maxGauge(createId(name, Utils.toIterable(tags))); }
@Test public void maxGauge() { Registry r = newRegistry(true, 10000); r.maxGauge("foo").set(1.0); r.maxGauge("foo").set(3.0); r.maxGauge("foo").set(2.0); final DoubleSummaryStatistics valueSummary = r.gauges() .filter(Functions.nameEquals("foo")) .collect(Collectors.summarizingDouble(Gauge::value)); Assertions.assertEquals(1, valueSummary.getCount()); Assertions.assertEquals(3.0, valueSummary.getSum(), 1e-12); }