Class SlidingWindow<T>

java.lang.Object
io.prometheus.metrics.core.metrics.SlidingWindow<T>

public class SlidingWindow<T> extends Object
Maintains a ring buffer of T to implement a sliding time window.

This is used to maintain a sliding window of CKMSQuantiles for Summary metrics.

It is implemented in a generic way so that 3rd party libraries can use it for implementing sliding windows.

TODO: The current implementation is synchronized. There is likely room for optimization.

  • Constructor Summary

    Constructors
    Constructor
    Description
    SlidingWindow(Class<T> clazz, Supplier<T> constructor, ObjDoubleConsumer<T> observeFunction, long maxAgeSeconds, int ageBuckets)
    Example: If the maxAgeSeconds is 60 and ageBuckets is 3, then 3 instances of T are maintained and the sliding window moves to the next instance of T every 20 seconds.
  • Method Summary

    Modifier and Type
    Method
    Description
    Get the currently active instance of T.
    void
    observe(double value)
    Observe a value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SlidingWindow

      public SlidingWindow(Class<T> clazz, Supplier<T> constructor, ObjDoubleConsumer<T> observeFunction, long maxAgeSeconds, int ageBuckets)
      Example: If the maxAgeSeconds is 60 and ageBuckets is 3, then 3 instances of T are maintained and the sliding window moves to the next instance of T every 20 seconds.
      Parameters:
      clazz - type of T
      constructor - for creating a new instance of T as the old one gets evicted
      observeFunction - for observing a value (e.g. calling t.observe(value)
      maxAgeSeconds - after this amount of time an instance of T gets evicted.
      ageBuckets - number of age buckets.
  • Method Details

    • current

      public T current()
      Get the currently active instance of T.
    • observe

      public void observe(double value)
      Observe a value.