com.netflix.servo.publish
Class CounterToRateMetricTransform

java.lang.Object
  extended by com.netflix.servo.publish.CounterToRateMetricTransform
All Implemented Interfaces:
MetricObserver

public final class CounterToRateMetricTransform
extends java.lang.Object
implements MetricObserver

Converts counter metrics into a rate per second. The rate is calculated by comparing two samples of given metric and looking at the delta. Since two samples are needed to calculate the rate, no value will be sent to the wrapped observer until a second sample arrives. If a given metric is not updated within a given heartbeat interval, the previous cached value for the counter will be dropped such that if a new sample comes in it will be treated as the first sample for that metric.

Counters should be monotonically increasing values. If a counter value decreases from one sample to the next, then we will assume the counter value was reset and send a rate of 0. This is similar to the RRD concept of type DERIVE with a min of 0.

This class is not thread safe and should generally be wrapped by an async observer to prevent issues.


Constructor Summary
CounterToRateMetricTransform(MetricObserver observer, long heartbeat, long estPollingInterval, java.util.concurrent.TimeUnit unit)
          Creates a new instance with the specified heartbeat interval.
CounterToRateMetricTransform(MetricObserver observer, long heartbeat, java.util.concurrent.TimeUnit unit)
          Creates a new instance with the specified heartbeat interval.
 
Method Summary
 java.lang.String getName()
          Name associated with an observer.
 void reset()
          Clear all cached state of previous counter values.
 void update(java.util.List<Metric> metrics)
          Invoked with the most recent values for a set of metrics.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CounterToRateMetricTransform

public CounterToRateMetricTransform(MetricObserver observer,
                                    long heartbeat,
                                    java.util.concurrent.TimeUnit unit)
Creates a new instance with the specified heartbeat interval. The heartbeat should be some multiple of the sampling interval used when collecting the metrics.


CounterToRateMetricTransform

public CounterToRateMetricTransform(MetricObserver observer,
                                    long heartbeat,
                                    long estPollingInterval,
                                    java.util.concurrent.TimeUnit unit)
Creates a new instance with the specified heartbeat interval. The heartbeat should be some multiple of the sampling interval used when collecting the metrics.

Parameters:
observer - downstream observer to forward values to after the rate has been computed.
heartbeat - how long to remember a previous value before dropping it and treating new samples as the first report.
estPollingInterval - estimated polling interval in to use for the first call. If set to zero no values will be forwarded until the second sample for a given counter. The delta for the first interval will be the total value for the counter as it is assumed it started at 0 and was first created since the last polling interval. If this assumption is not true then this setting should be 0 so it waits for the next sample to compute an accurate delta, otherwise spikes will occur in the output.
unit - unit for the heartbeat and estPollingInterval params.
Method Detail

getName

public java.lang.String getName()
Name associated with an observer. Mostly used to make log messages more informative.

Specified by:
getName in interface MetricObserver

update

public void update(java.util.List<Metric> metrics)
Invoked with the most recent values for a set of metrics.

Specified by:
update in interface MetricObserver

reset

public void reset()
Clear all cached state of previous counter values.