README

metrics Build Status

Documentation: http://godoc.org/github.com/facebookgo/metrics

Go port of Coda Hale's Metrics library: https://github.com/codahale/metrics

Documentation

Overview

Package metrics provides various measuring instruments.

This library is based on Coda Hale's original work: https://github.com/codahale/metrics, and a fork of https://github.com/rcrowley/go-metrics.

Index

Constants

View Source
const TickDuration = 5 * time.Second

TickDuration defines the rate at which Tick() should get called for EWMA and other Tickable things that rely on EWMA like Meter & Timer.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

type Counter interface {
	// Clear the counter: set it to zero.
	Clear()

	// Return the current count.
	Count() int64

	// Decrement the counter by the given amount.
	Dec(amount int64) Counter

	// Increment the counter by the given amount.
	Inc(amount int64) Counter
}

Counters hold an int64 value that can be incremented and decremented.

func NewCounter

func NewCounter() Counter

Create a new counter.

type EWMA

type EWMA interface {
	// Return the moving average rate of events per second.
	Rate() float64

	// Tick the clock to update the moving average.
	Tick()

	// Add n uncounted events.
	Update(n int64)
}

EWMAs continuously calculate an exponentially-weighted moving average based on an outside source of clock ticks.

func NewEWMA

func NewEWMA(alpha float64) EWMA

Create a new EWMA with the given alpha.

func NewEWMA1

func NewEWMA1() EWMA

Create a new EWMA with alpha set for a one-minute moving average.

func NewEWMA15

func NewEWMA15() EWMA

Create a new EWMA with alpha set for a fifteen-minute moving average.

func NewEWMA5

func NewEWMA5() EWMA

Create a new EWMA with alpha set for a five-minute moving average.

type Gauge

type Gauge interface {
	// Update the gauge's value.
	Update(value int64)

	// Return the gauge's current value.
	Value() int64
}

Gauges hold an int64 value that can be set arbitrarily.

func NewGauge

func NewGauge() Gauge

Create a new gauge.

type Histogram

type Histogram interface {
	// Clear the histogram.
	Clear()

	// Return the count of inputs since the histogram was last cleared.
	Count() int64

	// Return the maximal value seen since the histogram was last cleared.
	Max() int64

	// Return the mean of all values seen since the histogram was last cleared.
	Mean() float64

	// Return the minimal value seen since the histogram was last cleared.
	Min() int64

	// Return an arbitrary percentile of all values seen since the histogram was
	// last cleared.
	Percentile(p float64) float64

	// Return a slice of arbitrary percentiles of all values seen since the
	// histogram was last cleared.
	Percentiles(ps []float64) []float64

	// Return the standard deviation of all values seen since the histogram was
	// last cleared.
	StdDev() float64

	// Update the histogram with a new value.
	Update(value int64)

	// Return the variance of all values seen since the histogram was last cleared.
	Variance() float64
}

Histograms calculate distribution statistics from an int64 value.

func NewHistogram

func NewHistogram(s Sample) Histogram

Create a new histogram with the given Sample. The initial values compare so that the first value will be both min and max and the variance is flagged for special treatment on its first iteration.

type Meter

type Meter interface {
	// Return the count of events seen.
	Count() int64

	// Mark the occurance of n events.
	Mark(n int64)

	// Tick the clock to update the moving average.
	Tick()

	// Return the meter's one-minute moving average rate of events.
	Rate1() float64

	// Return the meter's five-minute moving average rate of events.
	Rate5() float64

	// Return the meter's fifteen-minute moving average rate of events.
	Rate15() float64

	// Return the meter's mean rate of events.
	RateMean() float64
}

Meters count events to produce exponentially-weighted moving average rates at one-, five-, and fifteen-minutes and a mean rate.

func NewMeter

func NewMeter() Meter

Create a new meter.

type Sample

type Sample interface {
	// Clear all samples.
	Clear()

	// Return the size of the sample, which is at most the reservoir size.
	Size() int

	// Update the sample with a new value.
	Update(value int64)

	// Return all the values in the sample.
	Values() []int64
}

Samples maintain a statistically-significant selection of values from a stream.

func NewExpDecaySample

func NewExpDecaySample(reservoirSize int, alpha float64) Sample

Create a new exponentially-decaying sample with the given reservoir size and alpha.

func NewUniformSample

func NewUniformSample(reservoirSize int) Sample

Create a new uniform sample with the given reservoir size.

type Tickable

type Tickable interface {
	// Tick the clock to update the moving average.
	Tick()
}

Tickable defines the interface implemented by metrics that need to Tick.

type Timer

type Timer interface {
	// Return the count of inputs.
	Count() int64

	// Return the maximal value seen.
	Max() int64

	// Return the mean of all values seen.
	Mean() float64

	// Return the minimal value seen.
	Min() int64

	// Return an arbitrary percentile of all values seen.
	Percentile(p float64) float64

	// Return a slice of arbitrary percentiles of all values seen.
	Percentiles(ps []float64) []float64

	// Return the meter's one-minute moving average rate of events.
	Rate1() float64

	// Return the meter's five-minute moving average rate of events.
	Rate5() float64

	// Return the meter's fifteen-minute moving average rate of events.
	Rate15() float64

	// Return the meter's mean rate of events.
	RateMean() float64

	// Return the standard deviation of all values seen.
	StdDev() float64

	// Start captures the current time and returns a value which implements Stop
	// to log the elapsed time. It should be used like:
	//
	//     defer timer.Start().Stop()
	Start() interface {
		Stop()
	}

	// Record the duration of an event.
	Update(d time.Duration)

	// Record the duration of an event that started at a time and ends now.
	UpdateSince(t time.Time)

	// Tick the clock to update the moving average.
	Tick()
}

Timers capture the duration and rate of events.

func NewCustomTimer

func NewCustomTimer(h Histogram, m Meter) Timer

Create a new timer with the given Histogram and Meter.

func NewTimer

func NewTimer() Timer

Create a new timer with a standard histogram and meter. The histogram will use an exponentially-decaying sample with the same reservoir size and alpha as UNIX load averages.