/** * Check if we have violated our quota for any metric that has a configured quota */ public void checkQuotas() { checkQuotas(time.milliseconds()); }
@Override public Throwable call() { try { assertTrue(latch.await(5, TimeUnit.SECONDS)); for (int j = 0; j != 20; ++j) { sensor.record(j * index, System.currentTimeMillis() + j, false); sensor.checkQuotas(); } return null; } catch (Throwable e) { return e; } } }));
public void record(double value, long timeMs, boolean checkQuotas) { if (shouldRecord()) { this.lastRecordTime = timeMs; synchronized (this) { synchronized (metricLock()) { // increment all the stats for (Stat stat : this.stats) stat.record(config, value, timeMs); } if (checkQuotas) checkQuotas(timeMs); } for (Sensor parent : parents) parent.record(value, timeMs, checkQuotas); } }
/** * Record a value at a known time. This method is slightly faster than {@link #record(double)} since it will reuse * the time stamp. * @param value The value we are recording * @param timeMs The current POSIX time in milliseconds * @throws QuotaViolationException if recording this value moves a metric beyond its configured maximum or minimum * bound */ public void record(double value, long timeMs) { synchronized (this) { // increment all the stats for (int i = 0; i < this.stats.size(); i++) this.stats.get(i).record(config, value, timeMs); checkQuotas(timeMs); } for (int i = 0; i < parents.length; i++) parents[i].record(value, timeMs); }