Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TimedFloat64Buckets ¶
type TimedFloat64Buckets struct {
// contains filtered or unexported fields
}
TimedFloat64Buckets keeps buckets that have been collected at a certain time.
func NewTimedFloat64Buckets ¶
func NewTimedFloat64Buckets(window, granularity time.Duration) *TimedFloat64Buckets
NewTimedFloat64Buckets generates a new TimedFloat64Buckets with the given granularity.
func (*TimedFloat64Buckets) IsEmpty ¶
func (t *TimedFloat64Buckets) IsEmpty(now time.Time) bool
IsEmpty returns true if no data has been recorded for the `window` period.
func (*TimedFloat64Buckets) Record ¶
func (t *TimedFloat64Buckets) Record(now time.Time, value float64)
Record adds a value with an associated time to the correct bucket. If this record would introduce a gap in the data, any intervening times between the last write and this one will be recorded as zero. If an entire window length has expired without data, the firstWrite time is reset, meaning the WindowAverage will be of a partial window until enough data is received to fill it again.
func (*TimedFloat64Buckets) ResizeWindow ¶ added in v0.12.0
func (t *TimedFloat64Buckets) ResizeWindow(w time.Duration)
ResizeWindow resizes the window. This is an O(N) operation, and is not supposed to be executed very often.
func (*TimedFloat64Buckets) String ¶ added in v0.12.0
func (t *TimedFloat64Buckets) String() string
String implements the Stringer interface.
func (*TimedFloat64Buckets) WindowAverage ¶ added in v0.12.0
func (t *TimedFloat64Buckets) WindowAverage(now time.Time) float64
WindowAverage returns the average bucket value over the window.
If the first write was less than the window length ago, an average is returned over the partial window. For example, if firstWrite was 6 seconds ago, the average will be over these 6 seconds worth of buckets, even if the window is 60s. If a window passes with no data being received, the first write time is reset so this behaviour takes effect again.
Similarly, if we have not received recent data, the average is based on a partial window. For example, if the window is 60 seconds but we last received data 10 seconds ago, the window average will be the average over the first 50 seconds.
In other cases, for example if there are gaps in the data shorter than the window length, the missing data is assumed to be 0 and the average is over the whole window length inclusive of the missing data.
type WeightedFloat64Buckets ¶ added in v0.22.0
type WeightedFloat64Buckets struct { *TimedFloat64Buckets // contains filtered or unexported fields }
WeightedFloat64Buckets is the implementation of buckets, that uses weighted average algorithm.
func NewWeightedFloat64Buckets ¶ added in v0.22.0
func NewWeightedFloat64Buckets(window, granularity time.Duration) *WeightedFloat64Buckets
NewWeightedFloat64Buckets generates a new WeightedFloat64Buckets with the given granularity.
func (*WeightedFloat64Buckets) ResizeWindow ¶ added in v0.22.0
func (t *WeightedFloat64Buckets) ResizeWindow(w time.Duration)
ResizeWindow implements window resizing for the weighted averaging buckets object.
func (*WeightedFloat64Buckets) WindowAverage ¶ added in v0.22.0
func (t *WeightedFloat64Buckets) WindowAverage(now time.Time) float64
WindowAverage returns the exponential weighted average. This means that more recent items have much greater impact on the average than the older ones. TODO(vagababov): optimize for O(1) computation, if possible. E.g. with data [10, 10, 5, 5] (newest last), then the `WindowAverage` would return (10+10+5+5)/4 = 7.5 This with exponent of 0.6 would return 5*0.6+5*0.6*0.4+10*0.6*0.4^2+10*0.6*0.4^3 = 5.544 If we reverse the data to [5, 5, 10, 10] the simple average would remain the same, but this one would change to 9.072.