java.lang.Object
org.elasticsearch.script.TimeSeriesCounter
Provides a counter with a history of 5m/15m/24h.
Callers increment the counter and query the current state of the TimeSeries.
inc()
increments the counter to indicate an event happens "now", with metadata about "now"
from the given timeProvider
.
timeSeries()
provides a snapshot of the counters at the current time, given by
timeProvider
. The snapshot includes the number of events in the last five minutes, the last fifteen
minutes, the last twenty-four hours and an all-time count.
Caveats:
* If the timeProvider produces a time stamp value, t[j]
that occurs _before_ an earlier invocation t[j]
(where j is an
invocation that *happens-before*, in the java memory model sense), the time stamp is treated as occurring at the latest time seen,
t[latest]
, EXCEPT if t[latest] - t[j]
is earlier than any time covered by the twenty-four counter. If that occurs,
time goes backwards more than 24 hours (between 24:00 and 23:45 depending on the circumstance) the history is reset but total is
retained.
* All counters have a resolution:
- 5m resolution is 15s
- 15m resolution is 90s
- 24h resolution is 15m
The counter will drop events between one second and the resolution minus one second during a bucket rollover.-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected LongAdder
protected TimeSeriesCounter.Counter
protected TimeSeriesCounter.Counter
static final int
protected ReadWriteLock
static final int
static final int
protected final LongSupplier
protected TimeSeriesCounter.Counter
-
Constructor Summary
ConstructorDescriptionTimeSeriesCounter
(LongSupplier timeProvider) Create a TimeSeriesCounter with the giventimeProvider
. -
Method Summary
Modifier and TypeMethodDescriptionlong
count()
The total number of events for all time covered by the counters.void
inc()
Increment counters at timestamp t, any increment more than 24hours before the current time series resets all historical counters, but the total counter is still increments.protected long
now()
Get the value of the counters for the last 5 minutes, last 15 minutes and the last 24 hours from t.
-
Field Details
-
SECOND
public static final int SECOND- See Also:
-
MINUTE
public static final int MINUTE- See Also:
-
HOUR
public static final int HOUR- See Also:
-
adder
-
lock
-
fiveMinutes
-
fifteenMinutes
-
twentyFourHours
-
timeProvider
-
-
Constructor Details
-
TimeSeriesCounter
Create a TimeSeriesCounter with the giventimeProvider
. ThetimeProvider
must return positive values, in milliseconds. In live code, this is expected to beSystem.currentTimeMillis()
or a proxy such asThreadPool.absoluteTimeInMillis()
.
-
-
Method Details
-
inc
public void inc()Increment counters at timestamp t, any increment more than 24hours before the current time series resets all historical counters, but the total counter is still increments. -
timeSeries
Get the value of the counters for the last 5 minutes, last 15 minutes and the last 24 hours from t. May include events up to resolution before those durations due to counter granularity. -
now
protected long now() -
count
public long count()The total number of events for all time covered by the counters.
-