A Clock tells the current time.
type Clock interface { Time() time.Time }
Float attaches the methods of Observable to a float64.
type Float float64
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
String returns the float as a string.
func (f *Float) Value() float64
Value returns the float's value.
MinuteHourSeries tracks data at granularities of 1 minute and 1 hour.
type MinuteHourSeries struct {
// contains filtered or unexported fields
}
func NewMinuteHourSeries(f func() Observable) *MinuteHourSeries
NewMinuteHourSeries creates a new MinuteHourSeries using the function provided for creating new Observable.
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 (ts *MinuteHourSeries) Add(observation Observable)
Add records an observation at the current time.
func (ts *MinuteHourSeries) AddWithTime(observation Observable, t time.Time)
AddWithTime records an observation at the specified time.
func (ts *MinuteHourSeries) Clear()
Clear removes all observations from the time series.
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 (ts *MinuteHourSeries) Hour() Observable
func (ts *MinuteHourSeries) Latest(level, num int) Observable
Latest returns the sum of the num latest buckets from the level.
func (ts *MinuteHourSeries) LatestBuckets(level, num int) []Observable
LatestBuckets returns a copy of the num latest buckets from level.
func (ts *MinuteHourSeries) Minute() Observable
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 (ts *MinuteHourSeries) Recent(delta time.Duration) Observable
Recent returns the sum of observations from the last delta.
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 (ts *MinuteHourSeries) ScaleBy(factor float64)
ScaleBy updates observations by scaling by factor.
func (ts *MinuteHourSeries) Total() Observable
Total returns the total of all observations.
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() Observable
NewFloat returns a Float.
TimeSeries tracks data at granularities from 1 second to 16 weeks.
type TimeSeries struct {
// contains filtered or unexported fields
}
func NewTimeSeries(f func() Observable) *TimeSeries
NewTimeSeries creates a new TimeSeries using the function provided for creating new Observable.
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 (ts *TimeSeries) Add(observation Observable)
Add records an observation at the current time.
func (ts *TimeSeries) AddWithTime(observation Observable, t time.Time)
AddWithTime records an observation at the specified time.
func (ts *TimeSeries) Clear()
Clear removes all observations from the time series.
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 (ts *TimeSeries) Latest(level, num int) Observable
Latest returns the sum of the num latest buckets from the level.
func (ts *TimeSeries) LatestBuckets(level, num int) []Observable
LatestBuckets returns a copy of the num latest buckets from level.
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 (ts *TimeSeries) Recent(delta time.Duration) Observable
Recent returns the sum of observations from the last delta.
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 (ts *TimeSeries) ScaleBy(factor float64)
ScaleBy updates observations by scaling by factor.
func (ts *TimeSeries) Total() Observable
Total returns the total of all observations.