Example #1
0
 public void reset() {
   snapshot = new CounterMetric();
   counter = new AtomicLong(0);
   totalCount = 0L;
   startTime = clock.getCurrentTime();
   lastReportTime = 0L;
 }
Example #2
0
  public CounterMetric calculateMetric() {
    long lastCount = counter.getAndSet(0);
    long currentTime = clock.getCurrentTime();

    CounterMetric metric = new CounterMetric();

    totalCount += lastCount;
    long totalElapsed = currentTime - startTime;
    metric.meanRate = (totalCount * 1000) / totalElapsed;

    metric.lastCount = lastCount;
    metric.totalCount = totalCount;

    long elapsed = currentTime - lastReportTime;
    if (elapsed > 0) {
      metric.lastRate = (lastCount * 1000) / elapsed;
    }

    lastReportTime = currentTime;

    snapshot = metric;

    return metric;
  }