README

rolling

We've moved to https://github.com/asecurityteam/rolling.

This repository is read-only and maintained to support existing users. New development will happen in the new location.

Expand ▾ Collapse ▴

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Avg

func Avg(w Window) float64

Avg the values within the window.

func Count

func Count(w Window) float64

Count returns the number of elements in a window.

func FastPercentile

func FastPercentile(perc float64) func(w Window) float64

FastPercentile implements the pSquare percentile estimation algorithm for calculating percentiles from streams of data using fixed memory allocations.

func Max

func Max(w Window) float64

Max the values within the window.

func Min

func Min(w Window) float64

Min the values within the window.

func Percentile

func Percentile(perc float64) func(w Window) float64

Percentile returns an aggregating function that computes the given percentile calculation for a window.

func Sum

func Sum(w Window) float64

Sum the values within the window.

Types

type PointPolicy

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

PointPolicy is a rolling window policy that tracks the last N values inserted regardless of insertion time.

func NewPointPolicy

func NewPointPolicy(window Window) *PointPolicy

NewPointPolicy generates a Policy that operates on a rolling set of input points. The number of points is determined by the size of the given window. Each bucket will contain, at most, one data point when the window is full.

func (*PointPolicy) Append

func (w *PointPolicy) Append(value float64)

Append a value to the window.

func (*PointPolicy) Reduce

func (w *PointPolicy) Reduce(f func(Window) float64) float64

Reduce the window to a single value using a reduction function.

type TimePolicy

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

TimePolicy is a window Accumulator implementation that uses some duration of time to determine the content of the window.

func NewTimePolicy

func NewTimePolicy(window Window, bucketDuration time.Duration) *TimePolicy

NewTimePolicy manages a window with rolling time duratinos. The given duration will be used to bucket data within the window. If data points are received entire windows aparts then the window will only contain a single data point. If one or more durations of the window are missed then they are zeroed out to keep the window consistent.

func (*TimePolicy) Append

func (w *TimePolicy) Append(value float64)

Append a value to the window using a time bucketing strategy.

func (*TimePolicy) Reduce

func (w *TimePolicy) Reduce(f func(Window) float64) float64

Reduce the window to a single value using a reduction function.

type Window

type Window [][]float64

Window represents a bucketed set of data. It should be used in conjuction with a Policy to populate it with data using some windowing policy.

func NewPreallocatedWindow

func NewPreallocatedWindow(buckets int, bucketSize int) Window

NewPreallocatedWindow creates a Window both with the given number of buckets and with a preallocated bucket size. This constructor may be used when the number of data points per-bucket can be estimated and/or when the desire is to allocate a large slice so that allocations do not happen as the Window is populated by a Policy.

func NewWindow

func NewWindow(buckets int) Window

NewWindow creates a Window with the given number of buckets. The number of buckets is meaningful to each Policy. The Policy implementations will describe their use of buckets.