com.yammer.metrics.core
Class TimerMetric

java.lang.Object
  extended by com.yammer.metrics.core.TimerMetric
All Implemented Interfaces:
Metered, Metric, Percentiled, Stoppable, Summarized

public class TimerMetric
extends Object
implements Metered, Stoppable, Percentiled, Summarized

A timer metric which aggregates timing durations and provides duration statistics, plus throughput statistics via MeterMetric.


Constructor Summary
TimerMetric(ScheduledExecutorService tickThread, TimeUnit durationUnit, TimeUnit rateUnit)
          Creates a new TimerMetric.
TimerMetric(ScheduledExecutorService tickThread, TimeUnit durationUnit, TimeUnit rateUnit, Clock clock)
          Creates a new TimerMetric.
TimerMetric(TimeUnit durationUnit, TimeUnit rateUnit)
          Deprecated. either use the other constructor or create via the MetricsRegistry or Metrics
TimerMetric(TimeUnit durationUnit, TimeUnit rateUnit, Clock clock)
          Deprecated. either use the other constructor or create via the MetricsRegistry or Metrics
 
Method Summary
 void clear()
          Clears all recorded durations.
 long count()
          Returns the number of events which have been marked.
 void dump(File output)
          Writes the values of the timer's sample to the given file.
 TimeUnit durationUnit()
          Returns the timer's duration scale unit.
 String eventType()
          Returns the type of events the meter is measuring.
 double fifteenMinuteRate()
          Returns the fifteen-minute exponentially-weighted moving average rate at which events have occurred since the meter was created.
 double fiveMinuteRate()
          Returns the five-minute exponentially-weighted moving average rate at which events have occurred since the meter was created.
 double max()
          Returns the longest recorded duration.
 double mean()
          Returns the arithmetic mean of all recorded durations.
 double meanRate()
          Returns the mean rate at which events have occurred since the meter was created.
 double min()
          Returns the shortest recorded duration.
 double oneMinuteRate()
          Returns the one-minute exponentially-weighted moving average rate at which events have occurred since the meter was created.
 double percentile(double percentile)
          Returns the duration at the given percentile.
 Double[] percentiles(Double... percentiles)
          Returns an array of durations at the given percentiles.
<T> void
processWith(MetricsProcessor<T> processor, MetricName name, T context)
           
 TimeUnit rateUnit()
          Returns the meter's rate unit.
 double stdDev()
          Returns the standard deviation of all recorded durations.
 void stop()
           
 TimerContext time()
          Returns a timing TimerContext, which measures an elapsed time in nanoseconds.
<T> T
time(Callable<T> event)
          Times and records the duration of event.
 void update(long duration, TimeUnit unit)
          Adds a recorded duration.
 List<Double> values()
          Returns a list of all recorded durations in the timer's sample.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimerMetric

public TimerMetric(TimeUnit durationUnit,
                   TimeUnit rateUnit)
Deprecated. either use the other constructor or create via the MetricsRegistry or Metrics

Creates a new TimerMetric.

Parameters:
durationUnit - the scale unit for this timer's duration metrics
rateUnit - the scale unit for this timer's rate metrics

TimerMetric

public TimerMetric(TimeUnit durationUnit,
                   TimeUnit rateUnit,
                   Clock clock)
Deprecated. either use the other constructor or create via the MetricsRegistry or Metrics

Creates a new TimerMetric with the specified clock.

Parameters:
durationUnit - the scale unit for this timer's duration metrics
rateUnit - the scale unit for this timer's rate metrics
clock - the clock used to calculate duration

TimerMetric

public TimerMetric(ScheduledExecutorService tickThread,
                   TimeUnit durationUnit,
                   TimeUnit rateUnit)
Creates a new TimerMetric.

Parameters:
tickThread - background thread for updating the rates
durationUnit - the scale unit for this timer's duration metrics
rateUnit - the scale unit for this timer's rate metrics

TimerMetric

public TimerMetric(ScheduledExecutorService tickThread,
                   TimeUnit durationUnit,
                   TimeUnit rateUnit,
                   Clock clock)
Creates a new TimerMetric.

Parameters:
tickThread - background thread for updating the rates
durationUnit - the scale unit for this timer's duration metrics
rateUnit - the scale unit for this timer's rate metrics
clock - the clock used to calculate duration
Method Detail

durationUnit

public TimeUnit durationUnit()
Returns the timer's duration scale unit.

Returns:
the timer's duration scale unit

rateUnit

public TimeUnit rateUnit()
Description copied from interface: Metered
Returns the meter's rate unit.

Specified by:
rateUnit in interface Metered
Returns:
the meter's rate unit

clear

public void clear()
Clears all recorded durations.


update

public void update(long duration,
                   TimeUnit unit)
Adds a recorded duration.

Parameters:
duration - the length of the duration
unit - the scale unit of duration

time

public <T> T time(Callable<T> event)
       throws Exception
Times and records the duration of event.

Type Parameters:
T - the type of the value returned by event
Parameters:
event - a Callable whose Callable.call() method implements a process whose duration should be timed
Returns:
the value returned by event
Throws:
Exception - if event throws an Exception

time

public TimerContext time()
Returns a timing TimerContext, which measures an elapsed time in nanoseconds.

Returns:
a new TimerContext

count

public long count()
Description copied from interface: Metered
Returns the number of events which have been marked.

Specified by:
count in interface Metered
Returns:
the number of events which have been marked

fifteenMinuteRate

public double fifteenMinuteRate()
Description copied from interface: Metered
Returns the fifteen-minute exponentially-weighted moving average rate at which events have occurred since the meter was created.

This rate has the same exponential decay factor as the fifteen-minute load average in the top Unix command.

Specified by:
fifteenMinuteRate in interface Metered
Returns:
the fifteen-minute exponentially-weighted moving average rate at which events have occurred since the meter was created

fiveMinuteRate

public double fiveMinuteRate()
Description copied from interface: Metered
Returns the five-minute exponentially-weighted moving average rate at which events have occurred since the meter was created.

This rate has the same exponential decay factor as the five-minute load average in the top Unix command.

Specified by:
fiveMinuteRate in interface Metered
Returns:
the five-minute exponentially-weighted moving average rate at which events have occurred since the meter was created

meanRate

public double meanRate()
Description copied from interface: Metered
Returns the mean rate at which events have occurred since the meter was created.

Specified by:
meanRate in interface Metered
Returns:
the mean rate at which events have occurred since the meter was created

oneMinuteRate

public double oneMinuteRate()
Description copied from interface: Metered
Returns the one-minute exponentially-weighted moving average rate at which events have occurred since the meter was created.

This rate has the same exponential decay factor as the one-minute load average in the top Unix command.

Specified by:
oneMinuteRate in interface Metered
Returns:
the one-minute exponentially-weighted moving average rate at which events have occurred since the meter was created

max

public double max()
Returns the longest recorded duration.

Specified by:
max in interface Summarized
Returns:
the longest recorded duration

min

public double min()
Returns the shortest recorded duration.

Specified by:
min in interface Summarized
Returns:
the shortest recorded duration

mean

public double mean()
Returns the arithmetic mean of all recorded durations.

Specified by:
mean in interface Summarized
Returns:
the arithmetic mean of all recorded durations

stdDev

public double stdDev()
Returns the standard deviation of all recorded durations.

Specified by:
stdDev in interface Summarized
Returns:
the standard deviation of all recorded durations

percentile

public double percentile(double percentile)
Description copied from interface: Percentiled
Returns the duration at the given percentile.

Specified by:
percentile in interface Percentiled
Parameters:
percentile - a percentile (0..1)
Returns:
the duration at the given percentile

percentiles

public Double[] percentiles(Double... percentiles)
Description copied from interface: Percentiled
Returns an array of durations at the given percentiles.

Specified by:
percentiles in interface Percentiled
Parameters:
percentiles - one or more percentiles (0..1)
Returns:
an array of durations at the given percentiles

eventType

public String eventType()
Description copied from interface: Metered
Returns the type of events the meter is measuring.

Specified by:
eventType in interface Metered
Returns:
the meter's event type

values

public List<Double> values()
Returns a list of all recorded durations in the timer's sample.

Returns:
a list of all recorded durations in the timer's sample

dump

public void dump(File output)
          throws IOException
Writes the values of the timer's sample to the given file.

Parameters:
output - the file to which the values will be written
Throws:
IOException - if there is an error writing the values

stop

public void stop()
Specified by:
stop in interface Stoppable

processWith

public <T> void processWith(MetricsProcessor<T> processor,
                            MetricName name,
                            T context)
                 throws Exception
Specified by:
processWith in interface Metric
Throws:
Exception


Copyright © 2011. All Rights Reserved.