Documentation
¶
Index ¶
- func Avg(iterator Iterator) float64
- func Count(iterator Iterator) float64
- func Max(iterator Iterator) float64
- func Min(iterator Iterator) float64
- func Sum(iterator Iterator) float64
- type Aggregation
- type Bucket
- type Iterator
- type Metric
- type Options
- type RollingCounter
- type RollingCounterOpts
- type RollingGauge
- type RollingGaugeOpts
- type RollingWindow
- type RollingWindowOptions
- type Window
- func (w *Window) Add(offset int, val float64)
- func (w *Window) Append(offset int, val float64)
- func (w *Window) Bucket(offset int) Bucket
- func (w *Window) Iterator(offset int, count int) Iterator
- func (w *Window) ResetBucket(offset int)
- func (w *Window) ResetBuckets(offset int, count int)
- func (w *Window) ResetWindow()
- func (w *Window) Size() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Aggregation ¶
type Aggregation interface {
// Min finds the min value within the window.
Min() float64
// Max finds the max value within the window.
Max() float64
// Avg computes average value within the window.
Avg() float64
// Sum computes sum value within the window.
Sum() float64
}
Aggregation contains some common aggregation function. Each aggregation can compute summary statistics of window.
type Bucket ¶
type Bucket struct {
Points []float64 // stores individual data points
Count int64 // number of data points in this bucket
// contains filtered or unexported fields
}
Bucket is a basic structure that stores multiple float64 data points
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator is an iterator for traversing buckets in the window
type Metric ¶
type Metric interface {
// Add adds the given value to the counter.
Add(int64)
// Value gets the current value.
// If the metric's type is PointGauge, RollingCounter, RollingGauge,
// it returns the sum value within the window.
Value() int64
}
Metric is a sample interface. Implementations of Metrics in metric package are Counter, Gauge, PointGauge, RollingCounter and RollingGauge.
type RollingCounter ¶
type RollingCounter interface {
Metric
Aggregation
Timespan() int
// Reduce applies the reduction function to all buckets within the window.
Reduce(func(Iterator) float64) float64
}
RollingCounter represents a ring window based on time duration. e.g. [[1], [3], [5]]
func NewRollingCounter ¶
func NewRollingCounter(opts RollingCounterOpts) RollingCounter
NewRollingCounter creates a new RollingCounter bases on RollingCounterOpts.
type RollingCounterOpts ¶
RollingCounterOpts contains the arguments for creating RollingCounter.
type RollingGauge ¶
type RollingGauge interface {
Metric
Aggregation
// Latest returns the latest value.
Latest() float64
Timespan() int
// Reduce applies the reduction function to all buckets within the window.
Reduce(func(Iterator) float64) float64
}
RollingGauge represents a ring window based on time duration.
func NewRollingGauge ¶
func NewRollingGauge(opts RollingGaugeOpts) RollingGauge
NewRollingGauge creates a new RollingGauge based on RollingGaugeOpts.
type RollingGaugeOpts ¶
RollingGaugeOpts contains the arguments for creating RollingGauge.
type RollingWindow ¶
type RollingWindow struct {
// contains filtered or unexported fields
}
RollingWindow is a time-based rolling window
func NewRollingWindow ¶
func NewRollingWindow(opts RollingWindowOptions) *RollingWindow
NewRollingWindow creates a new rolling window
func (*RollingWindow) Add ¶
func (r *RollingWindow) Add(val float64)
Add adds a value to the current bucket and rolls the window according to time
type RollingWindowOptions ¶
type RollingWindowOptions struct {
Size int // Window size (number of buckets)
BucketDuration time.Duration // Duration of each bucket
}
RollingWindowOptions contains parameters for creating a rolling window
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
window implements a sliding time window
func (*Window) Iterator ¶
Iterator returns an iterator over count buckets starting from the specified offset
func (*Window) ResetBucket ¶
ResetBucket resets the bucket at the specified offset
func (*Window) ResetBuckets ¶
ResetBuckets resets count buckets starting from offset
func (*Window) ResetWindow ¶
func (w *Window) ResetWindow()
ResetWindow resets all buckets in the window