...

Package timeseries

import "golang.org/x/net/internal/timeseries"
Overview
Index

Overview ▾

Package timeseries implements a time series structure for stats collection.

Index ▾

type Clock
type Float
    func (f *Float) Add(other Observable)
    func (f *Float) Clear()
    func (f *Float) CopyFrom(other Observable)
    func (f *Float) Multiply(ratio float64)
    func (f *Float) String() string
    func (f *Float) Value() float64
type MinuteHourSeries
    func NewMinuteHourSeries(f func() Observable) *MinuteHourSeries
    func NewMinuteHourSeriesWithClock(f func() Observable, clock Clock) *MinuteHourSeries
    func (ts *MinuteHourSeries) Add(observation Observable)
    func (ts *MinuteHourSeries) AddWithTime(observation Observable, t time.Time)
    func (ts *MinuteHourSeries) Clear()
    func (ts *MinuteHourSeries) ComputeRange(start, finish time.Time, num int) []Observable
    func (ts *MinuteHourSeries) Hour() Observable
    func (ts *MinuteHourSeries) Latest(level, num int) Observable
    func (ts *MinuteHourSeries) LatestBuckets(level, num int) []Observable
    func (ts *MinuteHourSeries) Minute() Observable
    func (ts *MinuteHourSeries) Range(start, finish time.Time) Observable
    func (ts *MinuteHourSeries) Recent(delta time.Duration) Observable
    func (ts *MinuteHourSeries) RecentList(delta time.Duration, num int) []Observable
    func (ts *MinuteHourSeries) ScaleBy(factor float64)
    func (ts *MinuteHourSeries) Total() Observable
type Observable
    func NewFloat() Observable
type TimeSeries
    func NewTimeSeries(f func() Observable) *TimeSeries
    func NewTimeSeriesWithClock(f func() Observable, clock Clock) *TimeSeries
    func (ts *TimeSeries) Add(observation Observable)
    func (ts *TimeSeries) AddWithTime(observation Observable, t time.Time)
    func (ts *TimeSeries) Clear()
    func (ts *TimeSeries) ComputeRange(start, finish time.Time, num int) []Observable
    func (ts *TimeSeries) Latest(level, num int) Observable
    func (ts *TimeSeries) LatestBuckets(level, num int) []Observable
    func (ts *TimeSeries) Range(start, finish time.Time) Observable
    func (ts *TimeSeries) Recent(delta time.Duration) Observable
    func (ts *TimeSeries) RecentList(delta time.Duration, num int) []Observable
    func (ts *TimeSeries) ScaleBy(factor float64)
    func (ts *TimeSeries) Total() Observable

Package files

timeseries.go

type Clock

A Clock tells the current time.

type Clock interface {
    Time() time.Time
}

type Float

Float attaches the methods of Observable to a float64.

type Float 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

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

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

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

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

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
}

func NewFloat

func NewFloat() Observable

NewFloat returns a Float.

type TimeSeries

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

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

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.