com.codahale.metrics.Clock类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(234)

本文整理了Java中com.codahale.metrics.Clock类的一些代码示例,展示了Clock类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Clock类的具体详情如下:
包路径:com.codahale.metrics.Clock
类名称:Clock

Clock介绍

[英]An abstraction for how time passes. It is passed to Timer to track timing.
[中]对时间如何流逝的抽象描述。它被传递到计时器以跟踪计时。

代码示例

代码示例来源:origin: Graylog2/graylog2-server

public HdrTimer(long highestTrackableValue,
        TimeUnit unit,
        int numberOfSignificantValueDigits,
        Reservoir reservoir,
        Clock clock) {
  super(reservoir, clock);
  hdrHistogram = new HdrHistogram(unit.toNanos(highestTrackableValue), numberOfSignificantValueDigits);
}

代码示例来源:origin: stagemonitor/stagemonitor

/**
 * 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;
  }
}

代码示例来源:origin: io.dropwizard.metrics/metrics-core

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;
    }
  }
}

代码示例来源:origin: jsevellec/cassandra-unit

/**
 * 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);
}

代码示例来源:origin: io.dropwizard.metrics/metrics-core

private void rescaleIfNeeded() {
  final long now = clock.getTick();
  final long next = nextScaleTime.get();
  if (now >= next) {
    rescale(now, next);
  }
}

代码示例来源:origin: io.dropwizard.metrics/metrics-core

/**
 * 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);
}

代码示例来源:origin: io.dropwizard.metrics/metrics-core

/**
 * 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();
}

代码示例来源:origin: io.dropwizard.metrics/metrics-core

@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());
  }
}

代码示例来源:origin: io.dropwizard.metrics/metrics-core

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()) {

代码示例来源:origin: io.dropwizard.metrics/metrics-core

@Override
public double getMeanRate() {
  if (getCount() == 0) {
    return 0.0;
  } else {
    final double elapsed = clock.getTick() - startTime;
    return getCount() / elapsed * TimeUnit.SECONDS.toNanos(1);
  }
}

代码示例来源:origin: snazy/ohc

public MergeableTimerSource()
{
  this.clock = Clock.defaultClock();
  this.count = new AtomicLong();
  this.histogram = new AtomicReference<>(new Histogram(new UniformReservoir()));
}

代码示例来源:origin: io.dropwizard.metrics/metrics-core

private long currentTimeInSeconds() {
  return TimeUnit.MILLISECONDS.toSeconds(clock.getTime());
}

代码示例来源:origin: AxonFramework/AxonFramework

/**
 * Creates a MessageTimerMonitor using a default clock
 */
public MessageTimerMonitor() {
  this(Clock.defaultClock());
}

代码示例来源:origin: stagemonitor/stagemonitor

@Override
  public long getTime() {
    final long time = delegate.getTime();
    return time - (time % periodInMS);
  }
}

代码示例来源:origin: aseigneurin/kafka-sandbox

@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));
}

代码示例来源:origin: io.dropwizard.metrics/metrics-core

private Context(Timer timer, Clock clock) {
  this.timer = timer;
  this.clock = clock;
  this.startTime = clock.getTick();
}

代码示例来源:origin: org.apache.cassandra/cassandra-all

/**
 * 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);
}

代码示例来源:origin: com.codahale.metrics/metrics-core

private void rescaleIfNeeded() {
  final long now = clock.getTick();
  final long next = nextScaleTime.get();
  if (now >= next) {
    rescale(now, next);
  }
}

代码示例来源:origin: io.dropwizard.metrics/metrics-core

/**
 * 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);
}

代码示例来源:origin: io.dropwizard.metrics/metrics-core

/**
 * 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();
}

相关文章

微信公众号

最新文章

更多