metrics

package
v0.0.0-...-4c2d33b Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlphaEWMA

func AlphaEWMA(n float64) float64

AlphaEWMA returns the alpha value for n minutes.

Types

type EWMA

type EWMA interface {
	Snapshot() EWMASnapshot
	Tick()
	Update(int64)
}

EWMAs continuously calculate an exponentially-weighted moving average based on an outside source of clock ticks.

func NewEWMA

func NewEWMA(alpha float64) EWMA

NewEWMA constructs a new EWMA with the given alpha.

func NewEWMA1

func NewEWMA1() EWMA

NewEWMA1 constructs a new EWMA for a one-minute moving average.

func NewEWMA15

func NewEWMA15() EWMA

NewEWMA15 constructs a new EWMA for a fifteen-minute moving average.

func NewEWMA5

func NewEWMA5() EWMA

NewEWMA5 constructs a new EWMA for a five-minute moving average.

func NewNonStandardEWMA

func NewNonStandardEWMA(alpha float64, interval time.Duration) EWMA

type EWMASnapshot

type EWMASnapshot interface {
	Rate() float64
}

type Meter

type Meter interface {
	Mark(int64)
	Snapshot() MeterSnapshot
	Stop()
}

Meters count events to produce exponentially-weighted moving average rates at one-, five-, and fifteen-minutes and a mean rate.

func NewInactiveMeter

func NewInactiveMeter() Meter

NewInactiveMeter returns a meter but does not start any goroutines. This method is mainly intended for testing.

func NewMeter

func NewMeter() Meter

NewMeter constructs a new StandardMeter and launches a goroutine. Be sure to call Stop() once the meter is of no use to allow for garbage collection.

type MeterSnapshot

type MeterSnapshot interface {
	Count() int64
	Rate1() float64
	Rate5() float64
	Rate15() float64
	RateMean() float64
}

type NonStandardEWMA

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

NonStandardEWMA is a non-standard implementation of an EWMA and tracks the number of uncounted events and processes them on each tick. Differentially from StandardEWMA, it provides a method to update the rate based on the interval between ticks.

func (*NonStandardEWMA) SetInterval

func (a *NonStandardEWMA) SetInterval(interval time.Duration) *NonStandardEWMA

func (*NonStandardEWMA) Snapshot

func (a *NonStandardEWMA) Snapshot() EWMASnapshot

Snapshot returns a read-only copy of the EWMA.

func (*NonStandardEWMA) Tick

func (a *NonStandardEWMA) Tick()

Tick ticks the clock to update the moving average. It assumes it is called every five seconds.

func (*NonStandardEWMA) Update

func (a *NonStandardEWMA) Update(n int64)

Update adds n uncounted events.

type StandardEWMA

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

StandardEWMA is the standard implementation of an EWMA and tracks the number of uncounted events and processes them on each tick. It uses the sync/atomic package to manage uncounted events.

func (*StandardEWMA) Snapshot

func (a *StandardEWMA) Snapshot() EWMASnapshot

Snapshot returns a read-only copy of the EWMA.

func (*StandardEWMA) Tick

func (a *StandardEWMA) Tick()

Tick ticks the clock to update the moving average. It assumes it is called every five seconds.

func (*StandardEWMA) Update

func (a *StandardEWMA) Update(n int64)

Update adds n uncounted events.

type StandardMeter

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

StandardMeter is the standard implementation of a Meter.

func (*StandardMeter) Mark

func (m *StandardMeter) Mark(n int64)

Mark records the occurrence of n events.

func (*StandardMeter) Snapshot

func (m *StandardMeter) Snapshot() MeterSnapshot

Snapshot returns a read-only copy of the meter.

func (*StandardMeter) Stop

func (m *StandardMeter) Stop()

Stop stops the meter, Mark() will be a no-op if you use it after being stopped.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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