ewma

package
v3.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package ewma provides an implementation of an exponentially weighted moving average (EWMA) that can be reported as a Prometheus metric.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EWMA

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

EWMA provides an exponentially weighted moving average (EWMA). EWMA implements prometheus.Collector.

func MustNew

func MustNew(opts Options, source Source) *EWMA

MustNew calls New and panics on error.

func New

func New(opts Options, source Source) (*EWMA, error)

New creates a new EWMA with the given options and source. The returned EWMA must be started by calling EWMA.Monitor.

func (*EWMA) Collect

func (ewma *EWMA) Collect(ch chan<- prometheus.Metric)

Collect writes the EWMA metrics to the given channel. Metrics are only written when the EWMA is running via EWMA.Monitor.

func (*EWMA) Describe

func (ewma *EWMA) Describe(ch chan<- *prometheus.Desc)

Describe describes the metrics emitted by EWMA.

func (*EWMA) Monitor

func (ewma *EWMA) Monitor(ctx context.Context) error

Monitor starts the EWMA, polling values from the source at the configured update frequency.

Monitor runs until the provided context is canceled. Monitor returns an error if a Monitor is already running.

type Options

type Options struct {
	// Name of the EWMA metric.
	Name string

	// Help text for the EWMA metric.
	Help string

	// UpdateFrequency is the frequency at which the EWMA is updated from the
	// Source. A typical value is 5s.
	UpdateFrequency time.Duration

	// Windows is a list of time windows for which averages will be calculated;
	// such as 1m, 5m, and 15m averages.
	Windows []time.Duration
}

Options provides configuration options for an EWMA.

type Source

type Source interface {
	// Get returns the current value for the EWMA calculation.
	Get() float64
}

Source is an interface that provides a value for an EWMA calculation.

type SourceFunc

type SourceFunc func() float64

SourceFunc is a Source that provides its value from a function.

func (SourceFunc) Get

func (sf SourceFunc) Get() float64

Get returns the value provided by the SourceFunc.

Jump to

Keyboard shortcuts

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