Accumulates PeriodSnapshot instances over the specified period of time and produces a single PeriodSnapshot that merges all metrics and instruments accumulated during that period.
Accumulates PeriodSnapshot instances over the specified period of time and produces a single PeriodSnapshot that
merges all metrics and instruments accumulated during that period. This class contains mutable state, is not
thread safe and assumes that all snapshots passed to the accumulate(...)
function are ordered in time.
The typical use of this class would be when writing metric reporters that have to report data at a specific interval and want to protect from users configuring a more frequent metrics tick interval. Example:
class Reporter extends MetricsReporter { val accumulator = PeriodSnapshot.accumulator(Duration.ofSeconds(60), Duration.ofSeconds(1)) def reportPeriodSnapshot(snapshot: PeriodSnapshot): Unit = { accumulator.add(snapshot).foreach(accumulatedSnapshot => { // Process your snapshot here, will only be called when the expected period has passed. } } ... }
The margin time is used to determine how close the current accumulated interval can be to the expected interval and still get reported. In the example above a accumulated period of 59.6 seconds has a margin to 60 seconds of 0.4 seconds, thus, getting reported immediately instead of waiting for the next snapshot.
A detail of what has been accumulated can be obtained by calling the .peek()
ing into the accumulator.
Creates a new PeriodSnapshot accumulator that removes stale instruments and metrics after the provided stale period.
Creates a new PeriodSnapshot accumulator using the default Kamon clock as time source.