Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.yammer.metrics.core;
  
  
A meter metric which measures mean throughput and one-, five-, and fifteen-minute exponentially-weighted moving average throughputs.

See also:
EMA
 
 public class Meter implements MeteredStoppable {
     private static final long INTERVAL = 5; // seconds
 
     private final EWMA m1Rate = EWMA.oneMinuteEWMA();
     private final EWMA m5Rate = EWMA.fiveMinuteEWMA();
     private final EWMA m15Rate = EWMA.fifteenMinuteEWMA();
 
     private final AtomicLong count = new AtomicLong();
     private final long startTime;
     private final TimeUnit rateUnit;
     private final String eventType;
     private final ScheduledFuture<?> future;
     private final Clock clock;

    
Creates a new Meter.

Parameters:
tickThread background thread for updating the rates
eventType the plural name of the event the meter is measuring (e.g., "requests")
rateUnit the rate unit of the new meter
clock the clock to use for the meter ticks
 
     Meter(ScheduledExecutorService tickThreadString eventTypeTimeUnit rateUnitClock clock) {
         this. = rateUnit;
         this. = eventType;
         this. = tickThread.scheduleAtFixedRate(new Runnable() {
             @Override
             public void run() {
                 tick();
             }
         }, .);
         this. = clock;
         this. = this..tick();
     }
 
     @Override
     public TimeUnit rateUnit() {
         return ;
     }
 
     @Override
     public String eventType() {
         return ;
     }

    
Updates the moving averages.
 
     void tick() {
         .tick();
         .tick();
         .tick();
     }

    
Mark the occurrence of an event.
 
     public void mark() {
         mark(1);
     }

    
Mark the occurrence of a given number of events.

Parameters:
n the number of events
 
     public void mark(long n) {
         .addAndGet(n);
         .update(n);
         .update(n);
         .update(n);
     }
 
     @Override
     public long count() {
         return .get();
     }
 
     @Override
     public double fifteenMinuteRate() {
         return .rate();
     }
 
    @Override
    public double fiveMinuteRate() {
        return .rate();
    }
    @Override
    public double meanRate() {
        if (count() == 0) {
            return 0.0;
        } else {
            final long elapsed = (.tick() - );
            return convertNsRate(count() / (doubleelapsed);
        }
    }
    @Override
    public double oneMinuteRate() {
        return .rate();
    }
    private double convertNsRate(double ratePerNs) {
        return ratePerNs * (double.toNanos(1);
    }
    @Override
    public void stop() {
        .cancel(false);
    }
    @Override
    public <T> void processWith(MetricProcessor<T> processorMetricName name, T contextthrows Exception {
        processor.processMeter(namethiscontext);
    }
New to GrepCode? Check out our FAQ X