ewma

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alpha

func Alpha(target float64, duration time.Duration) float64

Alpha the alpha needed to decay 1 to negligible (less than target) over a given duration.

(1 - alpha) ^ duration = target ==> alpha = 1 - target ^ (1 / duration).

func NewEWMA

func NewEWMA(alpha float64) gometrics.EWMA

NewEWMA constructs a new EWMA with the given alpha.

Types

type EWMA

type EWMA struct {
	// contains filtered or unexported fields
}

EWMA is the standard EWMA implementation, it updates in real time and when queried it always returns the decayed value. See: https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average

func (*EWMA) Rate

func (e *EWMA) Rate() float64

Rate returns the moving average mean of events per second.

func (*EWMA) Snapshot

func (e *EWMA) Snapshot() gometrics.EWMA

Snapshot returns a read-only copy of the EWMA.

func (*EWMA) Tick

func (e *EWMA) Tick()

Tick ticks the clock to update the moving average. There is no need to use an additional timer to Tick in this implementation, because Rate also calculates the latest value when it is updated or queried.

func (*EWMA) Update

func (e *EWMA) Update(i int64)

Update adds an uncounted event with value `i`, and tries to flush.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL