/** * Creates a new instance of the timer. */ BasicTimer(MonitorConfig config, TimeUnit unit, Clock clock) { super(config); final Tag unitTag = Tags.newTag(UNIT, unit.name()); final MonitorConfig unitConfig = config.withAdditionalTag(unitTag); timeUnit = unit; timeUnitNanosFactor = 1.0 / timeUnit.toNanos(1); totalTime = new DoubleCounter(unitConfig.withAdditionalTag(STAT_TOTAL), clock); count = new StepCounter(unitConfig.withAdditionalTag(STAT_COUNT), clock); totalOfSquares = new DoubleCounter(unitConfig.withAdditionalTag(STAT_TOTAL_SQ), clock); max = new DoubleMaxGauge(unitConfig.withAdditionalTag(STAT_MAX), clock); monitors = UnmodifiableList.<Monitor<?>>of(totalTime, count, totalOfSquares, max); }
public DoubleCounter newInstance(String name) { return new DoubleCounter(MonitorConfig.builder(name).build(), clock); }
@Test public void testDoubleCounterAdd() { DoubleCounter c = new DoubleCounter(CONFIG, Clock.WALL); register(c); c.increment(0.2); assertEquals(0.2, registry.counter(ID).actualCount()); }
@Test public void testGetValueTwice() { ManualClock manualClock = new ManualClock(0L); DoubleCounter c = new DoubleCounter(MonitorConfig.builder("test").build(), manualClock); c.increment(1); for (int i = 1; i < 10; ++i) { manualClock.set(i * 60000L); c.increment(1); c.getValue(0); assertEquals(c.getValue(0).doubleValue(), 1 / 60.0); } } }
/** * Creates a new instance of the timer. */ BasicTimer(MonitorConfig config, TimeUnit unit, Clock clock) { super(config); final Tag unitTag = Tags.newTag(UNIT, unit.name()); final MonitorConfig unitConfig = config.withAdditionalTag(unitTag); timeUnit = unit; timeUnitNanosFactor = 1.0 / timeUnit.toNanos(1); totalTime = new DoubleCounter(unitConfig.withAdditionalTag(STAT_TOTAL), clock); count = new StepCounter(unitConfig.withAdditionalTag(STAT_COUNT), clock); totalOfSquares = new DoubleCounter(unitConfig.withAdditionalTag(STAT_TOTAL_SQ), clock); max = new DoubleMaxGauge(unitConfig.withAdditionalTag(STAT_MAX), clock); monitors = UnmodifiableList.<Monitor<?>>of(totalTime, count, totalOfSquares, max); }