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 Counter
- type CounterOpts
- type Gauge
- type GaugeOpts
- type Iterator
- type Metric
- type Opts
- type PointGauge
- type PointGaugeOpts
- type PointPolicy
- type RollingCounter
- type RollingCounterOpts
- type RollingGauge
- type RollingGaugeOpts
- type RollingPolicy
- type RollingPolicyOpts
- 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(offsets []int)
- func (w *Window) ResetWindow()
- func (w *Window) Size() int
- type WindowOpts
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 ¶
Bucket contains multiple float64 points.
type Counter ¶
type Counter interface { Metric }
Counter stores a numerical value that only ever goes up.
func NewCounter ¶
func NewCounter(opts CounterOpts) Counter
NewCounter creates a new Counter based on the CounterOpts.
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator iterates the buckets within 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 PointGauge ¶
type PointGauge interface { Aggregation Metric // Reduce applies the reduction function to all buckets within the window. Reduce(func(Iterator) float64) float64 }
PointGauge represents a ring window. Every buckets within the window contains one point. When the window is full, the earliest point will be overwrite.
func NewPointGauge ¶
func NewPointGauge(opts PointGaugeOpts) PointGauge
NewPointGauge creates a new PointGauge based on PointGaugeOpts.
type PointGaugeOpts ¶
type PointGaugeOpts struct { // Size represents the bucket size within the window. Size int }
PointGaugeOpts contains the arguments for creating PointGauge.
type PointPolicy ¶
type PointPolicy struct {
// contains filtered or unexported fields
}
PointPolicy is a policy of points within the window. PointPolicy wraps the window and make it seem like ring-buf. When using PointPolicy, every buckets within the windows contains at more one point. e.g. [[1], [2], [3]]
func NewPointPolicy ¶
func NewPointPolicy(window *Window) *PointPolicy
NewPointPolicy creates a new PointPolicy.
func (*PointPolicy) Append ¶
func (p *PointPolicy) Append(val float64)
Append appends the given points to the window.
type RollingCounter ¶
type RollingCounter interface { Metric Aggregation // 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 // 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. e.g. [[1, 2], [1, 2, 3], [1,2, 3, 4]]
func NewRollingGauge ¶
func NewRollingGauge(opts RollingGaugeOpts) RollingGauge
NewRollingGauge creates a new RollingGauge baseed on RollingGaugeOpts.
type RollingGaugeOpts ¶
RollingGaugeOpts contains the arguments for creating RollingGauge.
type RollingPolicy ¶
type RollingPolicy struct {
// contains filtered or unexported fields
}
RollingPolicy is a policy for ring window based on time duration. RollingPolicy moves bucket offset with time duration. e.g. If the last point is appended one bucket duration ago, RollingPolicy will increment current offset.
func NewRollingPolicy ¶
func NewRollingPolicy(window *Window, opts RollingPolicyOpts) *RollingPolicy
NewRollingPolicy creates a new RollingPolicy based on the given window and RollingPolicyOpts.
func (*RollingPolicy) Add ¶
func (r *RollingPolicy) Add(val float64)
Add adds the given value to the latest point within bucket.
func (*RollingPolicy) Append ¶
func (r *RollingPolicy) Append(val float64)
Append appends the given points to the window.
type RollingPolicyOpts ¶
RollingPolicyOpts contains the arguments for creating RollingPolicy.
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window contains multiple buckets.
func NewWindow ¶
func NewWindow(opts WindowOpts) *Window
NewWindow creates a new Window based on WindowOpts.
func (*Window) Add ¶
Add adds the given value to the latest point within bucket where index equals the given offset.
func (*Window) Append ¶
Append appends the given value to the bucket where index equals the given offset.
func (*Window) ResetBucket ¶
ResetBucket empties the bucket based on the given offset.
func (*Window) ResetBuckets ¶
ResetBuckets empties the buckets based on the given offsets.
func (*Window) ResetWindow ¶
func (w *Window) ResetWindow()
ResetWindow empties all buckets within the window.
type WindowOpts ¶
type WindowOpts struct {
Size int
}
WindowOpts contains the arguments for creating Window.