Class RateWindow
- java.lang.Object
-
- org.forgerock.openam.shared.monitoring.RateWindow
-
public class RateWindow extends Object
This class maintains the rate of an event for a sample rate over a window of a particular size.
The window is constructed with a given size and sample rate and the window will move continuously at interval defined by the sample rate. The min, max and average will always be of the current window position, ie as the window moves and sample are not covered by the window the sample will not be included in the min, max and average calculations.- Since:
- 12.0.0
-
-
Constructor Summary
Constructors Constructor Description RateWindow(RateTimer timer, int size, long sampleRate)Constructs a new instance of the RateWindow.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doublegetAverageRate()Gets the average rate for the sample rate averaged across the whole window.longgetMaxRate()Gets the maximum rate.longgetMinRate()Gets the minimum rate.voidincrementForTimestamp(long timestamp)Re-calculates the rate.
-
-
-
Constructor Detail
-
RateWindow
public RateWindow(RateTimer timer, int size, long sampleRate)
Constructs a new instance of the RateWindow.- Parameters:
timer- An instance of a Timer.size- The size of the window.sampleRate- The sample rate for the window.
-
-
Method Detail
-
incrementForTimestamp
public void incrementForTimestamp(long timestamp)
Re-calculates the rate.- Parameters:
timestamp- The millisecond timestamp of the event.
-
getAverageRate
public double getAverageRate()
Gets the average rate for the sample rate averaged across the whole window.
Does not include the latest window slot if time has not passed beyond it yet as otherwise could skew the average as that time slot has not yet completed and may get more events made in it.- Returns:
- The average event rate.
-
getMinRate
public long getMinRate()
Gets the minimum rate.- Returns:
- The minimum event rate.
-
getMaxRate
public long getMaxRate()
Gets the maximum rate.- Returns:
- The maximum event rate.
-
-