Refine search
public HdrTimer(long highestTrackableValue, TimeUnit unit, int numberOfSignificantValueDigits, Reservoir reservoir, Clock clock) { super(reservoir, clock); hdrHistogram = new HdrHistogram(unit.toNanos(highestTrackableValue), numberOfSignificantValueDigits); }
/** * Starts the reporter polling at the given period. * * @param period the amount of time between polls * @param unit the unit for {@code period} */ public void start(long period, TimeUnit unit) { synchronized (this) { if (started) { throw new IllegalStateException("This reporter has already been started"); } final long periodInMS = unit.toMillis(period); executor.scheduleAtFixedRate(new Runnable() { @Override public void run() { try { report(); } catch (RuntimeException ex) { logger.error("RuntimeException thrown from {}#report. Exception was suppressed.", ScheduledMetrics2Reporter.this.getClass().getSimpleName(), ex); } } }, getOffsetUntilTimestampIsDivisableByPeriod(clock.getTime(), periodInMS), periodInMS, TimeUnit.MILLISECONDS); this.clock = new QuantizedClock(clock, periodInMS); this.started = true; } }
private long getTick() { for ( ;; ) { final long oldTick = lastTick.get(); final long tick = (clock.getTick() - startTick) * COLLISION_BUFFER; // ensure the tick is strictly incrementing even if there are duplicate ticks final long newTick = tick - oldTick > 0L ? tick : oldTick + 1L; if (lastTick.compareAndSet(oldTick, newTick)) { return newTick; } } }
/** * Restores a RestorableMeter from the last seen 15m and 2h rates. * @param lastM15Rate the last-seen 15m rate, in terms of events per second * @param lastM120Rate the last seen 2h rate, in terms of events per second */ public RestorableMeter(double lastM15Rate, double lastM120Rate) { this.m15Rate = new RestorableEWMA(lastM15Rate, TimeUnit.MINUTES.toSeconds(15)); this.m120Rate = new RestorableEWMA(lastM120Rate, TimeUnit.MINUTES.toSeconds(120)); this.startTime = this.clock.getTick(); this.lastTick = new AtomicLong(startTime); }
/** * Creates a new {@link Meter}. * * @param clock the clock to use for the meter ticks */ public Meter(Clock clock) { this.clock = clock; this.startTime = this.clock.getTick(); this.lastTick = new AtomicLong(startTime); }
/** * Creates a new {@link SlidingTimeWindowReservoir} with the given clock and window of time. * * @param window the window of time * @param windowUnit the unit of {@code window} * @param clock the {@link Clock} to use */ public SlidingTimeWindowReservoir(long window, TimeUnit windowUnit, Clock clock) { this.clock = clock; this.measurements = new ConcurrentSkipListMap<>(); this.window = windowUnit.toNanos(window) * COLLISION_BUFFER; this.lastTick = new AtomicLong(clock.getTick() * COLLISION_BUFFER); this.count = new AtomicLong(); }
@Override @SuppressWarnings("rawtypes") public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { final long timestamp = TimeUnit.MILLISECONDS.toSeconds(clock.getTime()); for (Map.Entry<String, Gauge> entry : gauges.entrySet()) { reportGauge(timestamp, entry.getKey(), entry.getValue()); } for (Map.Entry<String, Counter> entry : counters.entrySet()) { reportCounter(timestamp, entry.getKey(), entry.getValue()); } for (Map.Entry<String, Histogram> entry : histograms.entrySet()) { reportHistogram(timestamp, entry.getKey(), entry.getValue()); } for (Map.Entry<String, Meter> entry : meters.entrySet()) { reportMeter(timestamp, entry.getKey(), entry.getValue()); } for (Map.Entry<String, Timer> entry : timers.entrySet()) { reportTimer(timestamp, entry.getKey(), entry.getValue()); } }
SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { final String dateTime = dateFormat.format(new Date(clock.getTime())); printWithBanner(dateTime, '='); output.println(); if (!gauges.isEmpty()) { printWithBanner("-- Gauges", '-'); for (Map.Entry<String, Gauge> entry : gauges.entrySet()) { output.println(entry.getKey()); printGauge(entry.getValue()); if (!counters.isEmpty()) { printWithBanner("-- Counters", '-'); for (Map.Entry<String, Counter> entry : counters.entrySet()) {
public MergeableTimerSource() { this.clock = Clock.defaultClock(); this.count = new AtomicLong(); this.histogram = new AtomicReference<>(new Histogram(new UniformReservoir())); }
/** * Creates a MessageTimerMonitor using a default clock */ public MessageTimerMonitor() { this(Clock.defaultClock()); }
@Override public long getTime() { final long time = delegate.getTime(); return time - (time % periodInMS); } }
@Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { long timestamp = clock.getTime() / 1000; gauges.forEach((key, value) -> sendGauge(key, value, timestamp)); counters.forEach((key, value) -> sendCounter(key, value, timestamp)); histograms.forEach((key, value) -> sendHistogram(key, value, timestamp)); meters.forEach((key, value) -> sendMeter(key, value, timestamp)); timers.forEach((key, value) -> sendTimer(key, value, timestamp)); }
private Context(Timer timer, Clock clock) { this.timer = timer; this.clock = clock; this.startTime = clock.getTick(); }
/** * Creates a new, uninitialized RestorableMeter. */ public RestorableMeter() { this.m15Rate = new RestorableEWMA(TimeUnit.MINUTES.toSeconds(15)); this.m120Rate = new RestorableEWMA(TimeUnit.MINUTES.toSeconds(120)); this.startTime = this.clock.getTick(); this.lastTick = new AtomicLong(startTime); }
/** * Creates a new {@link ExponentiallyDecayingReservoir}. * * @param size the number of samples to keep in the sampling reservoir * @param alpha the exponential decay factor; the higher this is, the more biased the reservoir * will be towards newer values * @param clock the clock used to timestamp samples and track rescaling */ public ExponentiallyDecayingReservoir(int size, double alpha, Clock clock) { this.values = new ConcurrentSkipListMap<>(); this.lock = new ReentrantReadWriteLock(); this.alpha = alpha; this.size = size; this.clock = clock; this.count = new AtomicLong(0); this.startTime = currentTimeInSeconds(); this.nextScaleTime = new AtomicLong(clock.getTick() + RESCALE_THRESHOLD); }
/** * Creates a new {@link SlidingTimeWindowArrayReservoir} with the given clock and window of time. * * @param window the window of time * @param windowUnit the unit of {@code window} * @param clock the {@link Clock} to use */ public SlidingTimeWindowArrayReservoir(long window, TimeUnit windowUnit, Clock clock) { this.startTick = clock.getTick(); this.clock = clock; this.measurements = new ChunkedAssociativeLongArray(); this.window = windowUnit.toNanos(window) * COLLISION_BUFFER; this.lastTick = new AtomicLong((clock.getTick() - startTick) * COLLISION_BUFFER); this.count = new AtomicLong(); }