rolling - ActiveState ActiveGo 1.8
...

Package rolling

import "github.com/afex/hystrix-go/hystrix/rolling"
Overview
Index

Overview ▾

type Number

Number tracks a numberBucket over a bounded number of time buckets. Currently the buckets are one second long and only the last 10 seconds are kept.

type Number struct {
    Buckets map[int64]*numberBucket
    Mutex   *sync.RWMutex
}

func NewNumber

func NewNumber() *Number

NewNumber initializes a RollingNumber struct.

func (*Number) Avg

func (r *Number) Avg(now time.Time) float64

func (*Number) Increment

func (r *Number) Increment(i float64)

Increment increments the number in current timeBucket.

func (*Number) Max

func (r *Number) Max(now time.Time) float64

Max returns the maximum value seen in the last 10 seconds.

func (*Number) Sum

func (r *Number) Sum(now time.Time) float64

Sum sums the values over the buckets in the last 10 seconds.

func (*Number) UpdateMax

func (r *Number) UpdateMax(n float64)

UpdateMax updates the maximum value in the current bucket.

type Timing

Timing maintains time Durations for each time bucket. The Durations are kept in an array to allow for a variety of statistics to be calculated from the source data.

type Timing struct {
    Buckets map[int64]*timingBucket
    Mutex   *sync.RWMutex

    CachedSortedDurations []time.Duration
    LastCachedTime        int64
}

func NewTiming

func NewTiming() *Timing

NewTiming creates a RollingTiming struct.

func (*Timing) Add

func (r *Timing) Add(duration time.Duration)

Add appends the time.Duration given to the current time bucket.

func (*Timing) Mean

func (r *Timing) Mean() uint32

Mean computes the average timing in the last 60 seconds.

func (*Timing) Percentile

func (r *Timing) Percentile(p float64) uint32

Percentile computes the percentile given with a linear interpolation.

func (*Timing) SortedDurations

func (r *Timing) SortedDurations() []time.Duration

SortedDurations returns an array of time.Duration sorted from shortest to longest that have occurred in the last 60 seconds.