metrics

package
v0.0.0-...-7ccf3e0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2015 License: BSD-3-Clause Imports: 15 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// M1Alpha represents 1 minute at a 5 second interval
	M1Alpha = 1 - math.Exp(-5.0/60/1)
	// M5Alpha represents 5 minutes at a 5 second interval
	M5Alpha = 1 - math.Exp(-5.0/60/5)
	// M15Alpha represents 15 minutes at a 5 second interval
	M15Alpha = 1 - math.Exp(-5.0/60/15)
)
View Source
var (
	DefaultPercentiles     = []float64{0.5, 0.75, 0.9, 0.99, 0.999}
	DefaultPercentileNames = []string{"p50", "p75", "p90", "p99", "p999"}
)
View Source
var (
	DefaultPrecision = Precision{0.02, 100 * 1000}
	DefaultMaxMemory = 12 * 1024
)
View Source
var RuntimeMetrics = &runtimeMetrics{}

Functions

func MakeBucketsForError

func MakeBucketsForError(error float64) []int64

MakeBucketsForError compute all the bucket values from 1 until we run out of positive 64-bit ints for the given an error (+/-). The error should be in percent, between 0.0 and 1.0.

Each bucket's value will be the midpoint of an error range to the edge of the bucket in each direction, so for example, given a 5% error range (the default), the bucket with value N will cover numbers 5% smaller (0.95*N) and 5% larger (1.05*N).

For the usual default of 5%, this results in 200 buckets.

The last bucket (the "infinity" bucket) ranges up to math.MaxInt64, which we treat as infinity.

func RegistryHandler

func RegistryHandler(reg Registry) http.Handler

Types

type Collection

type Collection interface {
	Metrics() map[string]interface{}
}

type Counter

type Counter struct {
	// contains filtered or unexported fields
}

func NewCounter

func NewCounter() *Counter

NewCounter returns a counter implemented as an atomic uint64.

func (*Counter) Count

func (c *Counter) Count() uint64

func (*Counter) Inc

func (c *Counter) Inc(delta uint64)

func (*Counter) MarshaText

func (c *Counter) MarshaText() ([]byte, error)

func (*Counter) MarshalJSON

func (c *Counter) MarshalJSON() ([]byte, error)

func (*Counter) Reset

func (c *Counter) Reset() uint64

func (*Counter) String

func (c *Counter) String() string

type CounterFunc

type CounterFunc func() uint64

func (CounterFunc) Count

func (f CounterFunc) Count() uint64

type CounterMetric

type CounterMetric interface {
	Count() uint64
}

Counter is the interface for a counter metric.

type CounterValue

type CounterValue uint64

func (CounterValue) Count

func (v CounterValue) Count() uint64

type Distribution

type Distribution struct {
	// contains filtered or unexported fields
}

Distribution tracks the min, max, sum, count, and variance/stddev of a set of values.

func NewDistribution

func NewDistribution() *Distribution

NewDistribution returns a new instance of a Distribution

func (*Distribution) Count

func (d *Distribution) Count() uint64

Count returns the number of data points

func (*Distribution) MarshalJSON

func (d *Distribution) MarshalJSON() ([]byte, error)

func (*Distribution) MarshalText

func (d *Distribution) MarshalText() ([]byte, error)

func (*Distribution) Max

func (d *Distribution) Max() float64

Max returns the maximum value of all data points

func (*Distribution) Mean

func (d *Distribution) Mean() float64

Mean returns the average of all of all data points

func (*Distribution) Min

func (d *Distribution) Min() float64

Min returns the minimum value of all data points

func (*Distribution) Reset

func (d *Distribution) Reset()

Reset the distribution to its initial empty state.

func (*Distribution) StdDev

func (d *Distribution) StdDev() float64

StdDev returns the standard deviation of all data points

func (*Distribution) String

func (d *Distribution) String() string

func (*Distribution) Sum

func (d *Distribution) Sum() float64

Sum returns the sum of all data points

func (*Distribution) Update

func (d *Distribution) Update(value float64)

Update inserts a new data point

func (*Distribution) Value

func (d *Distribution) Value() DistributionValue

func (*Distribution) Variance

func (d *Distribution) Variance() float64

Variance returns the variance of all data points

type DistributionMetric

type DistributionMetric interface {
	Value() DistributionValue
}

type DistributionValue

type DistributionValue struct {
	Count    uint64
	Sum      float64
	Min      float64
	Max      float64
	Variance float64
}

func (DistributionValue) Mean

func (v DistributionValue) Mean() float64

type Doer

type Doer func(name string, metric interface{}) error

type EWMA

type EWMA struct {
	// contains filtered or unexported fields
}

EWMA is an exponentially-weighted moving average.

http://www.teamquest.com/pdfs/whitepaper/ldavg1.pdf - UNIX Load Average Part 1: How It Works http://www.teamquest.com/pdfs/whitepaper/ldavg2.pdf - UNIX Load Average Part 2: Not Your Average Average

func NewEWMA

func NewEWMA(interval time.Duration, alpha float64) *EWMA

NewEWMA returns a new exponentially-weighte moving average.

func (*EWMA) MarshalJSON

func (e *EWMA) MarshalJSON() ([]byte, error)

func (*EWMA) MarshalText

func (e *EWMA) MarshalText() ([]byte, error)

func (*EWMA) Rate

func (e *EWMA) Rate() float64

Rate retusnt the current rate

func (*EWMA) Start

func (e *EWMA) Start()

Start the ticker

func (*EWMA) Stop

func (e *EWMA) Stop()

Stop the ticker

func (*EWMA) String

func (e *EWMA) String() string

func (*EWMA) Tick

func (e *EWMA) Tick()

Tick the moving average

func (*EWMA) Update

func (e *EWMA) Update(value uint64)

Update increments the uncounted value

type EWMAGauge

type EWMAGauge struct {
	// contains filtered or unexported fields
}

func NewEWMAGauge

func NewEWMAGauge(interval time.Duration, alpha float64, fun FloatGaugeFunc) *EWMAGauge

func (*EWMAGauge) MarshalJSON

func (e *EWMAGauge) MarshalJSON() ([]byte, error)

func (*EWMAGauge) MarshalText

func (e *EWMAGauge) MarshalText() ([]byte, error)

func (*EWMAGauge) Mean

func (e *EWMAGauge) Mean() float64

func (*EWMAGauge) Start

func (e *EWMAGauge) Start()

Start the ticker

func (*EWMAGauge) Stop

func (e *EWMAGauge) Stop()

Stop the ticker

func (*EWMAGauge) String

func (e *EWMAGauge) String() string

func (*EWMAGauge) Tick

func (e *EWMAGauge) Tick()

Tick the moving average

type FloatGaugeFunc

type FloatGaugeFunc func() float64

FloatGaugeFunc is used for stats reporting to identify the value as a floating point gauge

type GaugeFunc

type GaugeFunc func() float64

func (GaugeFunc) Value

func (f GaugeFunc) Value() float64

type GaugeMetric

type GaugeMetric interface {
	Value() float64
}

type GaugeValue

type GaugeValue float64

func (GaugeValue) Value

func (v GaugeValue) Value() float64

type Histogram

type Histogram interface {
	Clear()
	Update(int64)
	Distribution() DistributionValue
	Percentiles([]float64) []int64
	String() string
}

func NewBiasedHistogram

func NewBiasedHistogram() Histogram

NewBiasedHistogram returns a histogram that uses an exponentially decaying sample of 1028 elements, which offers a 99.9% confidence level with a 5% margin of error assuming a normal distribution, and an alpha factor of 0.015, which heavily biases the sample to the past 5 minutes of measurements.

func NewBucketedHistogram

func NewBucketedHistogram(bucketOffsets []int64) Histogram

NewBucketedHistogram returns a histogram that uses a fixed set of buckets for ranges of values. This is an implementation of the Histogram class from Ostrich. https://github.com/twitter/ostrich/blob/master/src/main/scala/com/twitter/ostrich/stats/Histogram.scala

func NewDefaultBucketedHistogram

func NewDefaultBucketedHistogram() Histogram

NewDefaultBucketedHistogram returns a bucketed histogram with an error of 5%

func NewDefaultMunroPatersonHistogram

func NewDefaultMunroPatersonHistogram() Histogram

func NewMunroPatersonHistogram

func NewMunroPatersonHistogram(bufSize, maxDepth int) Histogram

NewMunroPatersonHistogram returns an implemenation of the Munro-Paterson approximate histogram algorithm adapted from: https://github.com/twitter/commons/blob/master/src/java/com/twitter/common/stats/ApproximateHistogram.java http://szl.googlecode.com/svn-history/r36/trunk/src/emitters/szlquantile.cc

func NewMunroPatersonHistogramWithMaxMemory

func NewMunroPatersonHistogramWithMaxMemory(bytes int) Histogram

func NewMunroPatersonHistogramWithPrecision

func NewMunroPatersonHistogramWithPrecision(p Precision) Histogram

func NewSampledHistogram

func NewSampledHistogram(sample Sample) Histogram

func NewUnbiasedHistogram

func NewUnbiasedHistogram() Histogram

NewUnbiasedHistogram returns a histogram that uses a uniform sample of 1028 elements, which offers a 99.9% confidence level with a 5% margin of error assuming a normal distribution.

type HistogramExport

type HistogramExport struct {
	Histogram       Histogram
	Percentiles     []float64
	PercentileNames []string
}

func (*HistogramExport) MarshalJSON

func (e *HistogramExport) MarshalJSON() ([]byte, error)

func (*HistogramExport) MarshalText

func (e *HistogramExport) MarshalText() ([]byte, error)

func (*HistogramExport) String

func (e *HistogramExport) String() string

Return a JSON encoded version of the Histgram output

type IntegerGauge

type IntegerGauge struct {
	// contains filtered or unexported fields
}

func NewIntegerGauge

func NewIntegerGauge() *IntegerGauge

func (*IntegerGauge) Dec

func (c *IntegerGauge) Dec(delta int64)

func (*IntegerGauge) Inc

func (c *IntegerGauge) Inc(delta int64)

func (*IntegerGauge) IntegerValue

func (c *IntegerGauge) IntegerValue() int64

func (*IntegerGauge) MarshalJSON

func (c *IntegerGauge) MarshalJSON() ([]byte, error)

func (*IntegerGauge) MarshalText

func (c *IntegerGauge) MarshalText() ([]byte, error)

func (*IntegerGauge) Reset

func (c *IntegerGauge) Reset() int64

func (*IntegerGauge) Set

func (c *IntegerGauge) Set(value int64)

func (*IntegerGauge) String

func (c *IntegerGauge) String() string

func (*IntegerGauge) Value

func (c *IntegerGauge) Value() float64

type Meter

type Meter struct {
	// contains filtered or unexported fields
}

Meter is the combination of three EWMA metrics: 1 min, 5 min, and 15 min.

func NewMeter

func NewMeter() *Meter

NewMeter returns a new instance of Meter

func (*Meter) Count

func (m *Meter) Count() uint64

Count returns the number of values added.

func (*Meter) FifteenMinuteRate

func (m *Meter) FifteenMinuteRate() float64

FifteenMinuteRate returns the 15 minute EWMA rate

func (*Meter) FiveMinuteRate

func (m *Meter) FiveMinuteRate() float64

FiveMinuteRate returns the 5 minute EWMA rate

func (*Meter) MarshalJSON

func (m *Meter) MarshalJSON() ([]byte, error)

func (*Meter) MarshalText

func (m *Meter) MarshalText() ([]byte, error)

func (*Meter) MeanRate

func (m *Meter) MeanRate() float64

MeanRate returns the average rate

func (*Meter) OneMinuteRate

func (m *Meter) OneMinuteRate() float64

OneMinuteRate returns the 1 minute EWMA rate

func (*Meter) Stop

func (m *Meter) Stop()

Stop the ticker

func (*Meter) String

func (m *Meter) String() string

func (*Meter) Update

func (m *Meter) Update(delta uint64)

Update increments the EWMA metrics.

type NamedDistribution

type NamedDistribution struct {
	Name  string
	Value DistributionValue
}

type NamedValue

type NamedValue struct {
	Name  string
	Value float64
}

type Precision

type Precision struct {
	Episilon float64
	N        int
}

Precision expresses the maximum epsilon tolerated for a typical size of input

type Registry

type Registry interface {
	Scope(scope string) Registry
	Add(name string, metric interface{})
	Remove(name string)
	Do(f Doer) error
}

func NewFilterdRegistry

func NewFilterdRegistry(registry Registry, include []*regexp.Regexp, exclude []*regexp.Regexp) Registry

func NewRegistry

func NewRegistry() Registry

type RegistrySnapshot

type RegistrySnapshot struct {
	Values        []NamedValue
	Distributions []NamedDistribution
	// contains filtered or unexported fields
}

func NewRegistrySnapshot

func NewRegistrySnapshot(resetOnSnapshot bool) *RegistrySnapshot

func (*RegistrySnapshot) Add

func (rs *RegistrySnapshot) Add(name string, metric interface{})

func (*RegistrySnapshot) Do

func (rs *RegistrySnapshot) Do(f Doer) error

func (*RegistrySnapshot) Remove

func (rs *RegistrySnapshot) Remove(name string)

func (*RegistrySnapshot) Scope

func (rs *RegistrySnapshot) Scope(scope string) Registry

func (*RegistrySnapshot) Snapshot

func (rs *RegistrySnapshot) Snapshot(registry Registry)

type Sample

type Sample interface {
	Clear()
	Len() int
	Values() []int64
	Update(value int64)
}

func NewExponentiallyDecayingSample

func NewExponentiallyDecayingSample(reservoirSize int, alpha float64) Sample

NewExponentiallyDecayingSample returns an exponentially-decaying random sample of values. Uses Cormode et al's forward-decaying priority reservoir sampling method to produce a statistically representative sample, exponentially biased towards newer entries.

http://www.research.att.com/people/Cormode_Graham/library/publications/CormodeShkapenyukSrivastavaXu09.pdf Cormode et al. Forward Decay: A Practical Time Decay Model for Streaming Systems. ICDE '09: Proceedings of the 2009 IEEE International Conference on Data Engineering (2009)

func NewExponentiallyDecayingSampleWithCustomTime

func NewExponentiallyDecayingSampleWithCustomTime(reservoirSize int, alpha float64, now func() time.Time) Sample

NewExponentiallyDecayingSampleWithCustomTime returns an exponentially-decaying random sample of values using a custom time function.

func NewUniformSample

func NewUniformSample(reservoirSize int) Sample

NewUniformSample returns a sample randomly selects from a stream. Uses Vitter's Algorithm R to produce a statistically representative sample.

http://www.cs.umd.edu/~samir/498/vitter.pdf - Random Sampling with a Reservoir

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL