metrics

fun <S : MVIState, I : MVIIntent, A : MVIAction> metrics(reportingScope: CoroutineScope, offloadContext: CoroutineContext = Dispatchers.Default, windowSeconds: Int = 60, emaAlpha: Double = 0.1, bucketDuration: Duration = 1.seconds, clock: Clock = Clock.System, timeSource: TimeSource = TimeSource.Monotonic): DefaultMetrics<S, I, A>

Create a DefaultMetrics.

The returned Metrics implementation must be used with the metricsDecorator to actually populate the Metrics.snapshot return value.

Parameters

reportingScope

scope used for offloaded metric reporting. This scope MUST outlive the store's scope, because if the store is stopped, the MetricsSnapshot returned will become stale! A more long-lived scope, such as an application, process, or component scope is recommended. When metricsDecorator runs, it only collects metrics when the store is running, so the target store can be safely stopped. But the scope passed here is needed to ensure metrics are drained reliably even after the store's EoL.

offloadContext

dispatcher for computationally-intensive work, a non-main thread dispatcher is recommended.

windowSeconds

length of the sliding window used for rate calculations.

emaAlpha

smoothing factor for EMA calculations.

clock

wall-clock provider for timestamps.

bucketDuration

duration of each bucket in the moving average calculation.

timeSource

monotonic time source for duration retrieval.