com.netflix.servo.stats
Class StatsBuffer

java.lang.Object
  extended by com.netflix.servo.stats.StatsBuffer

public class StatsBuffer
extends java.lang.Object

A simple circular buffer that records values, and computes useful stats. This implementation is not thread safe.


Constructor Summary
StatsBuffer(int size, double[] percentiles)
          Create a circular buffer that will be used to record values and compute useful stats
 
Method Summary
 void computeStats()
          Compute stats for the current set of values.
 int getCount()
          Get the number of entries recorded.
 long getMax()
          Get the max of the values currently in our buffer.
 double getMean()
          Get the average of the values recorded.
 long getMin()
          Get the minimum of the values currently in our buffer.
 double[] getPercentiles()
          Return the percentiles we will compute: For example: 95.0, 99.0.
 double[] getPercentileValues()
          Get the computed percentileValues.
 double getStdDev()
          Get the standard deviation for the population of the recorded values present in our buffer.
 long getTotalTime()
          Get the total sum of the values recorded.
 double getVariance()
          Get the variance for the population of the recorded values present in our buffer.
 void record(long n)
          Record a new value for this buffer.
 void reset()
          Reset our local state: All values are set to 0.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StatsBuffer

public StatsBuffer(int size,
                   double[] percentiles)
Create a circular buffer that will be used to record values and compute useful stats

Parameters:
size - The capacity of the buffer
percentiles - Array of percentiles to compute. For example { 95.0, 99.0 }. If no percentileValues are required pass a 0-sized array.
Method Detail

reset

public void reset()
Reset our local state: All values are set to 0.


record

public void record(long n)
Record a new value for this buffer.


computeStats

public void computeStats()
Compute stats for the current set of values.


getCount

public int getCount()
Get the number of entries recorded.


getMean

public double getMean()
Get the average of the values recorded.

Returns:
The average of the values recorded, or 0.0 if no values were recorded.

getVariance

public double getVariance()
Get the variance for the population of the recorded values present in our buffer.

Returns:
The variance.p of the values recorded, or 0.0 if no values were recorded.

getStdDev

public double getStdDev()
Get the standard deviation for the population of the recorded values present in our buffer.

Returns:
The stddev.p of the values recorded, or 0.0 if no values were recorded.

getMin

public long getMin()
Get the minimum of the values currently in our buffer.

Returns:
The min of the values recorded, or 0.0 if no values were recorded.

getMax

public long getMax()
Get the max of the values currently in our buffer.

Returns:
The max of the values recorded, or 0.0 if no values were recorded.

getTotalTime

public long getTotalTime()
Get the total sum of the values recorded.

Returns:
The sum of the values recorded, or 0.0 if no values were recorded.

getPercentileValues

public double[] getPercentileValues()
Get the computed percentileValues. See StatsConfig for how to request different percentileValues. Note that for efficiency reasons we return the actual array of computed values. Users must NOT modify this array.

Returns:
An array of computed percentileValues.

getPercentiles

public double[] getPercentiles()
Return the percentiles we will compute: For example: 95.0, 99.0.