timeseries

package
v0.0.0-...-57c1bf3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2019 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package timeseries implements a time series structure for stats collection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	Time() time.Time
}

A Clock tells the current time.

type Float

type Float float64

Float attaches the methods of Observable to a float64.

func (*Float) Add

func (f *Float) Add(other Observable)

func (*Float) Clear

func (f *Float) Clear()

func (*Float) CopyFrom

func (f *Float) CopyFrom(other Observable)

func (*Float) Multiply

func (f *Float) Multiply(ratio float64)

func (*Float) String

func (f *Float) String() string

String returns the float as a string.

func (*Float) Value

func (f *Float) Value() float64

Value returns the float's value.

type MinuteHourSeries

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

MinuteHourSeries tracks data at granularities of 1 minute and 1 hour.

func NewMinuteHourSeries

func NewMinuteHourSeries(f func() Observable) *MinuteHourSeries

NewMinuteHourSeries creates a new MinuteHourSeries using the function provided for creating new Observable.

func NewMinuteHourSeriesWithClock

func NewMinuteHourSeriesWithClock(f func() Observable, clock Clock) *MinuteHourSeries

NewMinuteHourSeriesWithClock creates a new MinuteHourSeries using the function provided for creating new Observable and the clock for assigning timestamps.

func (*MinuteHourSeries) Add

func (ts *MinuteHourSeries) Add(observation Observable)

Add records an observation at the current time.

func (*MinuteHourSeries) AddWithTime

func (ts *MinuteHourSeries) AddWithTime(observation Observable, t time.Time)

AddWithTime records an observation at the specified time.

func (*MinuteHourSeries) Clear

func (ts *MinuteHourSeries) Clear()

Clear removes all observations from the time series.

func (*MinuteHourSeries) ComputeRange

func (ts *MinuteHourSeries) ComputeRange(start, finish time.Time, num int) []Observable

ComputeRange computes a specified number of values into a slice using the observations recorded over the specified time period. The return values are approximate if the start or finish times don't fall on the bucket boundaries at the same level or if the number of buckets spanning the range is not an integral multiple of num.

func (*MinuteHourSeries) Hour

func (ts *MinuteHourSeries) Hour() Observable

func (*MinuteHourSeries) Latest

func (ts *MinuteHourSeries) Latest(level, num int) Observable

Latest returns the sum of the num latest buckets from the level.

func (*MinuteHourSeries) LatestBuckets

func (ts *MinuteHourSeries) LatestBuckets(level, num int) []Observable

LatestBuckets returns a copy of the num latest buckets from level.

func (*MinuteHourSeries) Minute

func (ts *MinuteHourSeries) Minute() Observable

func (*MinuteHourSeries) Range

func (ts *MinuteHourSeries) Range(start, finish time.Time) Observable

Range returns the sum of observations added over the specified time range. If start or finish times don't fall on bucket boundaries of the same level, then return values are approximate answers.

func (*MinuteHourSeries) Recent

func (ts *MinuteHourSeries) Recent(delta time.Duration) Observable

Recent returns the sum of observations from the last delta.

func (*MinuteHourSeries) RecentList

func (ts *MinuteHourSeries) RecentList(delta time.Duration, num int) []Observable

RecentList returns the specified number of values in slice over the most recent time period of the specified range.

func (*MinuteHourSeries) ScaleBy

func (ts *MinuteHourSeries) ScaleBy(factor float64)

ScaleBy updates observations by scaling by factor.

func (*MinuteHourSeries) Total

func (ts *MinuteHourSeries) Total() Observable

Total returns the total of all observations.

type Observable

type Observable interface {
	Multiply(ratio float64)    // Multiplies the data in self by a given ratio
	Add(other Observable)      // Adds the data from a different observation to self
	Clear()                    // Clears the observation so it can be reused.
	CopyFrom(other Observable) // Copies the contents of a given observation to self
}

An Observable is a kind of data that can be aggregated in a time series.

func NewFloat

func NewFloat() Observable

NewFloat returns a Float.

type TimeSeries

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

TimeSeries tracks data at granularities from 1 second to 16 weeks.

func NewTimeSeries

func NewTimeSeries(f func() Observable) *TimeSeries

NewTimeSeries creates a new TimeSeries using the function provided for creating new Observable.

func NewTimeSeriesWithClock

func NewTimeSeriesWithClock(f func() Observable, clock Clock) *TimeSeries

NewTimeSeriesWithClock creates a new TimeSeries using the function provided for creating new Observable and the clock for assigning timestamps.

func (*TimeSeries) Add

func (ts *TimeSeries) Add(observation Observable)

Add records an observation at the current time.

func (*TimeSeries) AddWithTime

func (ts *TimeSeries) AddWithTime(observation Observable, t time.Time)

AddWithTime records an observation at the specified time.

func (*TimeSeries) Clear

func (ts *TimeSeries) Clear()

Clear removes all observations from the time series.

func (*TimeSeries) ComputeRange

func (ts *TimeSeries) ComputeRange(start, finish time.Time, num int) []Observable

ComputeRange computes a specified number of values into a slice using the observations recorded over the specified time period. The return values are approximate if the start or finish times don't fall on the bucket boundaries at the same level or if the number of buckets spanning the range is not an integral multiple of num.

func (*TimeSeries) Latest

func (ts *TimeSeries) Latest(level, num int) Observable

Latest returns the sum of the num latest buckets from the level.

func (*TimeSeries) LatestBuckets

func (ts *TimeSeries) LatestBuckets(level, num int) []Observable

LatestBuckets returns a copy of the num latest buckets from level.

func (*TimeSeries) Range

func (ts *TimeSeries) Range(start, finish time.Time) Observable

Range returns the sum of observations added over the specified time range. If start or finish times don't fall on bucket boundaries of the same level, then return values are approximate answers.

func (*TimeSeries) Recent

func (ts *TimeSeries) Recent(delta time.Duration) Observable

Recent returns the sum of observations from the last delta.

func (*TimeSeries) RecentList

func (ts *TimeSeries) RecentList(delta time.Duration, num int) []Observable

RecentList returns the specified number of values in slice over the most recent time period of the specified range.

func (*TimeSeries) ScaleBy

func (ts *TimeSeries) ScaleBy(factor float64)

ScaleBy updates observations by scaling by factor.

func (*TimeSeries) Total

func (ts *TimeSeries) Total() Observable

Total returns the total of all observations.

Jump to

Keyboard shortcuts

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