com.netflix.servo.monitor
Class StatsTimer

java.lang.Object
  extended by com.netflix.servo.monitor.AbstractMonitor<java.lang.Long>
      extended by com.netflix.servo.monitor.StatsMonitor
          extended by com.netflix.servo.monitor.StatsTimer
All Implemented Interfaces:
CompositeMonitor<java.lang.Long>, Monitor<java.lang.Long>, NumericMonitor<java.lang.Long>, Timer

public class StatsTimer
extends StatsMonitor
implements Timer

A Timer that provides statistics.

The statistics are collected periodically and are published according to the configuration specified by the user using a StatsConfig object. Please make sure that the sampleSize corresponds to roughly the number of samples expected in a reporting interval. While the statistics collected are accurate for this machine they will not be correct if they are aggregated across groups of machines. If that is an expected use-case a better approach is to use buckets that correspond to different times. For example you might have a counter that tracks how many calls took < 20ms, one for [ 20ms, 500ms ], and one for > 500ms. This bucketing approach can be easily aggregated.


Field Summary
 
Fields inherited from class com.netflix.servo.monitor.StatsMonitor
count, defaultExecutor, totalMeasurement
 
Fields inherited from class com.netflix.servo.monitor.AbstractMonitor
config
 
Constructor Summary
StatsTimer(MonitorConfig baseConfig, StatsConfig statsConfig)
          Creates a new instance of the timer with a unit of milliseconds, using the default executor.
StatsTimer(MonitorConfig baseConfig, StatsConfig statsConfig, java.util.concurrent.TimeUnit unit)
          Creates a new instance of the timer with a given unit, using the default executor.
StatsTimer(MonitorConfig config, StatsConfig statsConfig, java.util.concurrent.TimeUnit unit, java.util.concurrent.ScheduledExecutorService executor)
          Creates a new instance of the timer with a unit of milliseconds, using the ScheduledExecutorService provided by the user.
 
Method Summary
 boolean equals(java.lang.Object obj)
          
 long getCount()
          Get the number of times this timer has been updated
 java.util.concurrent.TimeUnit getTimeUnit()
          The time unit reported by this timer.
 long getTotalTime()
          Get the total time recorded for this timer
 int hashCode()
          
 void record(long duration, java.util.concurrent.TimeUnit timeUnit)
          Record a new value that was collected with the given TimeUnit.
 Stopwatch start()
          Returns a stopwatch that has been started and will automatically record its result to this timer when stopped.
 java.lang.String toString()
          
 
Methods inherited from class com.netflix.servo.monitor.StatsMonitor
getMonitors, getTotalMeasurement, getValue, handleException, record, startComputingStats
 
Methods inherited from class com.netflix.servo.monitor.AbstractMonitor
getConfig
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.netflix.servo.monitor.Timer
record
 
Methods inherited from interface com.netflix.servo.monitor.Monitor
getConfig, getValue
 

Constructor Detail

StatsTimer

public StatsTimer(MonitorConfig baseConfig,
                  StatsConfig statsConfig)
Creates a new instance of the timer with a unit of milliseconds, using the default executor.


StatsTimer

public StatsTimer(MonitorConfig baseConfig,
                  StatsConfig statsConfig,
                  java.util.concurrent.TimeUnit unit)
Creates a new instance of the timer with a given unit, using the default executor.


StatsTimer

public StatsTimer(MonitorConfig config,
                  StatsConfig statsConfig,
                  java.util.concurrent.TimeUnit unit,
                  java.util.concurrent.ScheduledExecutorService executor)
Creates a new instance of the timer with a unit of milliseconds, using the ScheduledExecutorService provided by the user.

Method Detail

start

public Stopwatch start()
Returns a stopwatch that has been started and will automatically record its result to this timer when stopped.

Specified by:
start in interface Timer

getTimeUnit

public java.util.concurrent.TimeUnit getTimeUnit()
The time unit reported by this timer.

Specified by:
getTimeUnit in interface Timer

record

public void record(long duration,
                   java.util.concurrent.TimeUnit timeUnit)
Record a new value that was collected with the given TimeUnit.

Specified by:
record in interface Timer

toString

public java.lang.String toString()

Overrides:
toString in class StatsMonitor

equals

public boolean equals(java.lang.Object obj)

Overrides:
equals in class StatsMonitor

hashCode

public int hashCode()

Overrides:
hashCode in class StatsMonitor

getCount

public long getCount()
Get the number of times this timer has been updated

Overrides:
getCount in class StatsMonitor

getTotalTime

public long getTotalTime()
Get the total time recorded for this timer