resttunnel

package
v0.0.0-...-d0d75a4 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Accumulator

type Accumulator struct {
	sync.RWMutex
	Label   string // used to identify the owner of an accumulator
	Samples []*Sample
	// contains filtered or unexported fields
}

Accumulator stores data on an interval and allows you to access it.

func NewAccumulator

func NewAccumulator(ctx context.Context, storedSamples int, interval time.Duration, label string) *Accumulator

NewAccumulator creates an accumulator. This does not automatically call Run.

func (*Accumulator) GetAllSamples

func (ac *Accumulator) GetAllSamples() *SampleGroup

GetAllSamples returns all samples from the accumulator.

func (*Accumulator) GetLastSamples

func (ac *Accumulator) GetLastSamples(n int) *SampleGroup

GetLastSamples returns the last N samples from the accumulator.

func (*Accumulator) GetSamplesSince

func (ac *Accumulator) GetSamplesSince(t time.Time) *SampleGroup

GetSamplesSince returns the last N samples from the accumulator in the specified time.

func (*Accumulator) Increment

func (ac *Accumulator) Increment()

Increment increments the accumulator by 1.

func (*Accumulator) IncrementBy

func (ac *Accumulator) IncrementBy(acc int64)

IncrementBy increments the accumulator by a specified number.

func (*Accumulator) Run

func (ac *Accumulator) Run()

Run starts the accumulator which will process the accumulator and store it appropriately.

func (*Accumulator) RunOnce

func (ac *Accumulator) RunOnce(t time.Time)

RunOnce allows you to manually call the accumulator task in the event you already have a task running every interval.

func (*Accumulator) Sum

func (ac *Accumulator) Sum() int64

Sum returns the total number of increments the Accumulator has ever seen.

type Sample

type Sample struct {
	Value    int64     `json:"value"`
	StoredAt time.Time `json:"stored_at"`
}

Sample contains the time the sample was made and its value.

type SampleGroup

type SampleGroup struct {
	sync.RWMutex
	Label   string
	Samples []*Sample
}

SampleGroup holds a group of samples.

func (*SampleGroup) Avg

func (sg *SampleGroup) Avg() float64

Avg returns the average of all samples in a samplegroup object.

func (*SampleGroup) Since

func (sg *SampleGroup) Since(t time.Time) *SampleGroup

Since returns a samplegroup with all samples after a specified time.

func (*SampleGroup) Sum

func (sg *SampleGroup) Sum() int64

Sum returns the sum of all samples in a samplegroup object.

Jump to

Keyboard shortcuts

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