Documentation ¶
Index ¶
- type Window
- func (w *Window) Add(value float64)
- func (w *Window) AddAt(value float64, at time.Time)
- func (w *Window) Avg() float64
- func (w *Window) Count() int64
- func (w *Window) Evict()
- func (w *Window) First() float64
- func (w *Window) Last() float64
- func (w *Window) Max() float64
- func (w *Window) Mid() float64
- func (w *Window) Min() float64
- func (w *Window) Sum() float64
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
func NewWindow ¶
Example ¶
w := NewWindow(6, time.Second) w.Add(1) w.Add(2) time.Sleep(time.Second) w.Add(3) w.Add(4) w.Add(5) w.Add(6) w.Add(7) fmt.Println(w.Min(), w.Avg(), w.Max())
Output: 3 5 7
func (*Window) Add ¶
Add new value to the tail of the window and evict values from head if cnt > maxSize, or if value's timestamp is older than window duration.
func (*Window) AddAt ¶
AddAt adds new value to the tail of the window with a specified timestamp. Usually you need Add method. This one main purpose is to add past values on service restart. If you attempt to add value with timestamp older than the last one, it will be discarded.
func (*Window) Evict ¶
func (w *Window) Evict()
Evict clears outdated values from the window. This is useful if your updates do not come very often and you want to get some metric after some time from last Add and don't want vaules that are older than window duration to affect the result.
func (*Window) Mid ¶
Mid returns average between first and last values in the window. NaN if window is empty.