Class SlidingTimeWindowMovingAverages
- java.lang.Object
-
- com.codahale.metrics.SlidingTimeWindowMovingAverages
-
- All Implemented Interfaces:
MovingAverages
public class SlidingTimeWindowMovingAverages extends Object implements MovingAverages
A triple of simple moving average rates (one, five and fifteen minutes rates) as needed byMeter
.The averages are unweighted, i.e. they include strictly only the events in the sliding time window, every event having the same weight. Unlike the the more widely used
ExponentialMovingAverages
implementation, with this class the moving average rate drops immediately to zero if the last marked event is older than the time window.A
Meter
withSlidingTimeWindowMovingAverages
works similarly to aHistogram
with anSlidingTimeWindowArrayReservoir
, but as a Meter needs to keep track only of the count of events (not the events itself), the memory overhead is much smaller. SlidingTimeWindowMovingAverages uses buckets with just one counter to accumulate the number of events (one bucket per seconds, giving 900 buckets for the 15 minutes time window).
-
-
Constructor Summary
Constructors Constructor Description SlidingTimeWindowMovingAverages()
Creates a newSlidingTimeWindowMovingAverages
.SlidingTimeWindowMovingAverages(Clock clock)
Creates a newSlidingTimeWindowMovingAverages
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
getM15Rate()
Returns the fifteen-minute moving average ratedouble
getM1Rate()
Returns the one-minute moving average ratedouble
getM5Rate()
Returns the five-minute moving average ratevoid
tickIfNecessary()
Tick the internal clock of the MovingAverages implementation if needed (according to the internal ticking interval)void
update(long n)
Update all three moving averages with n events having occurred since the last update.
-
-
-
Constructor Detail
-
SlidingTimeWindowMovingAverages
public SlidingTimeWindowMovingAverages()
Creates a newSlidingTimeWindowMovingAverages
.
-
SlidingTimeWindowMovingAverages
public SlidingTimeWindowMovingAverages(Clock clock)
Creates a newSlidingTimeWindowMovingAverages
.- Parameters:
clock
- the clock to use for the meter ticks
-
-
Method Detail
-
update
public void update(long n)
Description copied from interface:MovingAverages
Update all three moving averages with n events having occurred since the last update.- Specified by:
update
in interfaceMovingAverages
-
tickIfNecessary
public void tickIfNecessary()
Description copied from interface:MovingAverages
Tick the internal clock of the MovingAverages implementation if needed (according to the internal ticking interval)- Specified by:
tickIfNecessary
in interfaceMovingAverages
-
getM15Rate
public double getM15Rate()
Description copied from interface:MovingAverages
Returns the fifteen-minute moving average rate- Specified by:
getM15Rate
in interfaceMovingAverages
- Returns:
- the fifteen-minute moving average rate
-
getM5Rate
public double getM5Rate()
Description copied from interface:MovingAverages
Returns the five-minute moving average rate- Specified by:
getM5Rate
in interfaceMovingAverages
- Returns:
- the five-minute moving average rate
-
getM1Rate
public double getM1Rate()
Description copied from interface:MovingAverages
Returns the one-minute moving average rate- Specified by:
getM1Rate
in interfaceMovingAverages
- Returns:
- the one-minute moving average rate
-
-