window

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package window is a library that calculates windows cpu and memory usage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Avg

func Avg(iterator Iterator) float64

Avg the values within the window.

func Count

func Count(iterator Iterator) float64

Count sums the count value within the window.

func Max

func Max(iterator Iterator) float64

Max the values within the window.

func Min

func Min(iterator Iterator) float64

Min the values within the window.

func Sum

func Sum(iterator Iterator) float64

Sum the values within the window.

Types

type Aggregation

type Aggregation interface {
	// Min finds the min value within the window.
	Min() float64
	// Max finds the max value within the window.
	Max() float64
	// Avg computes average value within the window.
	Avg() float64
	// Sum computes sum value within the window.
	Sum() float64
}

Aggregation contains some common aggregation function. Each aggregation can compute summary statistics of window.

type Bucket

type Bucket struct {
	Points []float64
	Count  int64
	// contains filtered or unexported fields
}

Bucket contains multiple float64 points.

func (*Bucket) Add

func (b *Bucket) Add(offset int, val float64)

Add adds the given value to the point.

func (*Bucket) Append

func (b *Bucket) Append(val float64)

Append appends the given value to the bucket.

func (*Bucket) Next

func (b *Bucket) Next() *Bucket

Next returns the next bucket.

func (*Bucket) Reset

func (b *Bucket) Reset()

Reset empties the bucket.

type Iterator

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

Iterator iterates the buckets within the window.

func (*Iterator) Bucket

func (i *Iterator) Bucket() Bucket

Bucket gets current bucket.

func (*Iterator) Next

func (i *Iterator) Next() bool

Next returns true util all of the buckets has been iterated.

type Metric

type Metric interface {
	// Add adds the given value to the counter.
	Add(int64)
	// Value gets the current value.
	// If the metric's type is PointGauge, RollingCounter, RollingGauge,
	// it returns the sum value within the window.
	Value() int64
}

Metric is a sample interface. Implementations of Metrics in metric package are Counter, Gauge, PointGauge, RollingCounter and RollingGauge.

type Options

type Options struct {
	Size int
}

Options contains the arguments for creating Window.

type RollingCounter

type RollingCounter interface {
	Metric
	Aggregation

	Timespan() int
	// Reduce applies the reduction function to all buckets within the window.
	Reduce(func(Iterator) float64) float64
}

RollingCounter represents a ring window based on time duration. e.g. [[1], [3], [5]]

func NewRollingCounter

func NewRollingCounter(opts RollingCounterOpts) RollingCounter

NewRollingCounter creates a new RollingCounter bases on RollingCounterOpts.

type RollingCounterOpts

type RollingCounterOpts struct {
	Size           int
	BucketDuration time.Duration
}

RollingCounterOpts contains the arguments for creating RollingCounter.

type RollingPolicy

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

RollingPolicy is a policy for ring window based on time duration. RollingPolicy moves bucket offset with time duration. e.g. If the last point is appended one bucket duration ago, RollingPolicy will increment current offset.

func NewRollingPolicy

func NewRollingPolicy(window *Window, opts RollingPolicyOpts) *RollingPolicy

NewRollingPolicy creates a new RollingPolicy based on the given window and RollingPolicyOpts.

func (*RollingPolicy) Add

func (r *RollingPolicy) Add(val float64)

Add adds the given value to the latest point within bucket.

func (*RollingPolicy) Append

func (r *RollingPolicy) Append(val float64)

Append appends the given points to the window.

func (*RollingPolicy) Reduce

func (r *RollingPolicy) Reduce(f func(Iterator) float64) (val float64)

Reduce applies the reduction function to all buckets within the window.

type RollingPolicyOpts

type RollingPolicyOpts struct {
	BucketDuration time.Duration
}

RollingPolicyOpts contains the arguments for creating RollingPolicy.

type Window

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

Window contains multiple buckets.

func NewWindow

func NewWindow(opts Options) *Window

NewWindow creates a new Window based on WindowOpts.

func (*Window) Add

func (w *Window) Add(offset int, val float64)

Add adds the given value to the latest point within bucket where index equals the given offset.

func (*Window) Append

func (w *Window) Append(offset int, val float64)

Append appends the given value to the bucket where index equals the given offset.

func (*Window) Bucket

func (w *Window) Bucket(offset int) Bucket

Bucket returns the bucket where index equals the given offset.

func (*Window) Iterator

func (w *Window) Iterator(offset int, count int) Iterator

Iterator returns the count number buckets iterator from offset.

func (*Window) ResetBucket

func (w *Window) ResetBucket(offset int)

ResetBucket empties the bucket based on the given offset.

func (*Window) ResetBuckets

func (w *Window) ResetBuckets(offset int, count int)

ResetBuckets empties the buckets based on the given offsets.

func (*Window) ResetWindow

func (w *Window) ResetWindow()

ResetWindow empties all buckets within the window.

func (*Window) Size

func (w *Window) Size() int

Size returns the size of the window.

Jump to

Keyboard shortcuts

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