/** Get the value for the last completed interval as a rate per second. */ @Override public double pollAsRate() { final double amount = poll(); final double period = step / 1000.0; return amount / period; }
/** Get the AtomicDouble for the current bucket. */ public AtomicDouble getCurrent() { rollCount(clock.wallTime()); return current; }
@Override public Iterable<Measurement> measure() { final double rate = value.pollAsRate(); final Measurement m = new Measurement(stat, value.timestamp(), rate); return Collections.singletonList(m); }
@Override public Iterable<Measurement> measure() { // poll needs to be called before accessing the timestamp to ensure // the counters have been rotated if there was no activity in the // current interval. double v = value.poll(); final Measurement m = new Measurement(stat, value.timestamp(), v); return Collections.singletonList(m); }
@Test public void increment() { StepDouble v = new StepDouble(0.0, clock, 10L); v.getCurrent().addAndGet(1.0); Assertions.assertEquals(1.0, v.getCurrent().get(), 1e-12); Assertions.assertEquals(0.0, v.poll(), 1e-12); }
@Override public void set(double v) { value.getCurrent().max(v); updateLastModTime(); }
/** Create a new instance. */ AtlasCounter(Id id, Clock clock, long ttl, long step) { super(id, clock, ttl); this.value = new StepDouble(0L, clock, step); // Add the statistic for typing. Re-adding the tags from the id is to retain // the statistic from the id if it was already set this.stat = id.withTag(Statistic.count).withTags(id.tags()).withTag(DsType.rate); }
@Override public Gauge maxGauge(Id id) { // Note: micrometer doesn't support this type directly so it uses an arbitrary // window of 1m StepDouble value = new StepDouble(Double.NaN, clock(), 60000L); io.micrometer.core.instrument.Gauge gauge = io.micrometer.core.instrument.Gauge .builder(id.name(), value, StepDouble::poll) .tags(convert(id.tags())) .register(impl); return new MicrometerGauge(id, v -> value.getCurrent().max(v), gauge); }
@Test public void empty() { StepDouble v = new StepDouble(0.0, clock, 10L); Assertions.assertEquals(0.0, v.getCurrent().get(), 1e-12); Assertions.assertEquals(0.0, v.poll(), 1e-12); }
@Override public void record(long amount, TimeUnit unit) { count.getCurrent().incrementAndGet(); if (amount > 0) { final long nanos = unit.toNanos(amount); total.getCurrent().addAndGet(nanos); totalOfSquares.getCurrent().addAndGet((double) nanos * nanos); updateMax(max.getCurrent(), nanos); } }
/** Create a new instance. */ AtlasMaxGauge(Id id, Clock clock, long ttl, long step) { super(id, clock, ttl); this.value = new StepDouble(0.0, clock, step); // Add the statistic for typing. Re-adding the tags from the id is to retain // the statistic from the id if it was already set this.stat = id.withTag(Statistic.max).withTags(id.tags()).withTag(DsType.gauge); }
@Test public void incrementAndCrossStepBoundary() { StepDouble v = new StepDouble(0.0, clock, 10L); v.getCurrent().addAndGet(1.0); clock.setWallTime(10L); Assertions.assertEquals(0.0, v.getCurrent().get(), 1e-12); Assertions.assertEquals(1.0, v.poll(), 1e-12); }
@Override public void record(long amount, TimeUnit unit) { count.getCurrent().incrementAndGet(); if (amount > 0) { final long nanos = unit.toNanos(amount); total.getCurrent().addAndGet(nanos); totalOfSquares.getCurrent().addAndGet((double) nanos * nanos); updateMax(max.getCurrent(), nanos); } updateLastModTime(); }
/** Create a new instance. */ AtlasDistributionSummary(Id id, Clock clock, long ttl, long step) { super(id, clock, ttl); this.count = new StepLong(0L, clock, step); this.total = new StepLong(0L, clock, step); this.totalOfSquares = new StepDouble(0.0, clock, step); this.max = new StepLong(0L, clock, step); this.stats = new Id[] { id.withTags(DsType.rate, Statistic.count), id.withTags(DsType.rate, Statistic.totalAmount), id.withTags(DsType.rate, Statistic.totalOfSquares), id.withTags(DsType.gauge, Statistic.max) }; }
@Override public double actualCount() { return value.poll(); } }
/** Get the AtomicDouble for the current bucket. */ public AtomicDouble getCurrent() { rollCount(clock.wallTime()); return current; }
@Test public void missedRead() { StepDouble v = new StepDouble(0.0, clock, 10L); v.getCurrent().addAndGet(1.0); clock.setWallTime(20L); Assertions.assertEquals(0.0, v.getCurrent().get(), 1e-12); Assertions.assertEquals(0.0, v.poll(), 1e-12); } }
@Override public void add(double amount) { if (Double.isFinite(amount) && amount > 0.0) { value.getCurrent().addAndGet(amount); updateLastModTime(); } }
/** Create a new instance. */ AtlasTimer(Id id, Clock clock, long ttl, long step) { super(id, clock, ttl); this.count = new StepLong(0L, clock, step); this.total = new StepLong(0L, clock, step); this.totalOfSquares = new StepDouble(0.0, clock, step); this.max = new StepLong(0L, clock, step); this.stats = new Id[] { id.withTags(DsType.rate, Statistic.count), id.withTags(DsType.rate, Statistic.totalTime), id.withTags(DsType.rate, Statistic.totalOfSquares), id.withTags(DsType.gauge, Statistic.max) }; }
/** Get the value for the last completed interval as a rate per second. */ @Override public double pollAsRate() { final double amount = poll(); final double period = step / 1000.0; return amount / period; }