Class TimeSeriesCounter

java.lang.Object
org.elasticsearch.script.TimeSeriesCounter

public class TimeSeriesCounter extends Object
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.
  • Field Details

  • Constructor Details

  • 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

      public TimeSeries 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.