com.twitter.common.metrics
Class Rate

java.lang.Object
  extended by com.twitter.common.metrics.AbstractGauge<Double>
      extended by com.twitter.common.metrics.Rate
All Implemented Interfaces:
Gauge<Double>

public class Rate
extends AbstractGauge<Double>

Gauge that computes a windowed rate.


Constructor Summary
Rate(String name, Supplier<T> valueAccessor, Amount<Long,Time> windowLength)
          Creates a rate using a supplier to access values.
 
Method Summary
static Rate of(Gauge gauge)
          Creates a rate of a gauge.
static Rate of(String name, Number number)
          Creates a rate of a number.
 Double read()
          Reads the latest value of the metric.
 
Methods inherited from class com.twitter.common.metrics.AbstractGauge
getName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Rate

public Rate(String name,
            Supplier<T> valueAccessor,
            Amount<Long,Time> windowLength)
Creates a rate using a supplier to access values.

Type Parameters:
T - Supplier type.
Parameters:
name - Name of the rate.
valueAccessor - Supplier to access values.
windowLength - Sliding window duration for computing rate.
Method Detail

of

public static Rate of(String name,
                      Number number)
Creates a rate of a number.

Parameters:
name - Name of the rate.
number - Rate input.
Returns:
A rate that computes rate(number).

of

public static Rate of(Gauge gauge)
Creates a rate of a gauge.

Parameters:
gauge - Rate input.
Returns:
A rate that computes rate(gauge).

read

public Double read()
Description copied from interface: Gauge
Reads the latest value of the metric. Must never return null.

Returns:
The metric value.