public class StatsRollingNumber
extends java.lang.Object
It is "rolling" in the sense that a 'timeInMilliseconds' is given that you want to track (such as 10 seconds) and then that is broken into buckets (defaults to 10) so that the 10 second window doesn't empty out and restart every 10 seconds, but instead every 1 second you have a new bucket added and one dropped so that 9 of the buckets remain and only the newest starts from scratch.
This is done so that the statistics are gathered over a rolling 10 second window with data being added/dropped in 1 seconds intervals (or whatever granularity is defined by the arguments) rather than each 10 second window starting at 0 again.
See inner-class UnitTest for usage and expected behavior examples.
| Modifier and Type | Class and Description |
|---|---|
static class |
StatsRollingNumber.Type |
static class |
StatsRollingNumber.UnitTest |
| Constructor and Description |
|---|
StatsRollingNumber(com.netflix.config.DynamicIntProperty timeInMilliseconds) |
StatsRollingNumber(com.netflix.config.DynamicIntProperty timeInMilliseconds,
com.netflix.config.DynamicIntProperty numberOfBuckets) |
StatsRollingNumber(int timeInMilliseconds,
int numberOfBuckets) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
compareAndSet(StatsRollingNumber.Type type,
int expected,
int value)
A compareAndSet counterpart to
set to allow atomically safe updates of an existing value. |
int |
getCount(StatsRollingNumber.Type type)
Get the sum of all buckets in the rolling counter for the given CounterType.
|
int |
getMaxValue(StatsRollingNumber.Type type)
Get the max value of values in all buckets for the given CounterType.
|
int |
getMinValue(StatsRollingNumber.Type type)
Get the min value of values in all buckets for the given CounterType.
|
int[] |
getModifiedValues(StatsRollingNumber.Type type) |
int |
getNumberOfBuckets() |
int |
getRollingTimeInMilliseconds() |
int |
getSum(StatsRollingNumber.Type type)
Get the sum of all buckets in the rolling counter for the given CounterType.
|
int |
getValueOfLatestBucket(StatsRollingNumber.Type type)
Get the sum of all buckets in the rolling counter for the given CounterType.
|
int[] |
getValues(StatsRollingNumber.Type type)
Get an array of values for all buckets in the rolling counter for the given CounterType.
|
void |
increment(StatsRollingNumber.Type type) |
void |
increment(StatsRollingNumber.Type type,
int delta) |
void |
reset()
Force a reset of all counters (clear all buckets) so that statistics start being gathered from scratch.
|
void |
set(StatsRollingNumber.Type type,
int value)
A number in a rolling bucket that you can set.
|
public StatsRollingNumber(com.netflix.config.DynamicIntProperty timeInMilliseconds)
public StatsRollingNumber(int timeInMilliseconds,
int numberOfBuckets)
public StatsRollingNumber(com.netflix.config.DynamicIntProperty timeInMilliseconds,
com.netflix.config.DynamicIntProperty numberOfBuckets)
public int getNumberOfBuckets()
public int getRollingTimeInMilliseconds()
public void increment(StatsRollingNumber.Type type)
public void increment(StatsRollingNumber.Type type, int delta)
public void set(StatsRollingNumber.Type type, int value)
type - value - public boolean compareAndSet(StatsRollingNumber.Type type, int expected, int value)
set to allow atomically safe updates of an existing value.
Will set value to 'value' if 'current value' == 'expected'
type - expected - value - public void reset()
public int getCount(StatsRollingNumber.Type type)
type - public int getSum(StatsRollingNumber.Type type)
type - public int getValueOfLatestBucket(StatsRollingNumber.Type type)
type - public int[] getValues(StatsRollingNumber.Type type)
Index 0 is the oldest bucket.
type - public int[] getModifiedValues(StatsRollingNumber.Type type)
public int getMaxValue(StatsRollingNumber.Type type)
type - public int getMinValue(StatsRollingNumber.Type type)
type -