metrics

package
v1.9.2-evmc.6.3.0-0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2019 License: GPL-3.0, BSD-2-Clause-Views Imports: 23 Imported by: 0

README

go-metrics

travis build status

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

Documentation: http://godoc.org/github.com/rcrowley/go-metrics.

Usage

Create and update metrics:

c := metrics.NewCounter()
metrics.Register("foo", c)
c.Inc(47)

g := metrics.NewGauge()
metrics.Register("bar", g)
g.Update(47)

r := NewRegistry()
g := metrics.NewRegisteredFunctionalGauge("cache-evictions", r, func() int64 { return cache.getEvictionsCount() })

s := metrics.NewExpDecaySample(1028, 0.015) // or metrics.NewUniformSample(1028)
h := metrics.NewHistogram(s)
metrics.Register("baz", h)
h.Update(47)

m := metrics.NewMeter()
metrics.Register("quux", m)
m.Mark(47)

t := metrics.NewTimer()
metrics.Register("bang", t)
t.Time(func() {})
t.Update(47)

Register() is not threadsafe. For threadsafe metric registration use GetOrRegister:

t := metrics.GetOrRegisterTimer("account.create.latency", nil)
t.Time(func() {})
t.Update(47)

NOTE: Be sure to unregister short-lived meters and timers otherwise they will leak memory:

// Will call Stop() on the Meter to allow for garbage collection
metrics.Unregister("quux")
// Or similarly for a Timer that embeds a Meter
metrics.Unregister("bang")

Periodically log every metric in human-readable form to standard error:

go metrics.Log(metrics.DefaultRegistry, 5 * time.Second, log.New(os.Stderr, "metrics: ", log.Lmicroseconds))

Periodically log every metric in slightly-more-parseable form to syslog:

w, _ := syslog.Dial("unixgram", "/dev/log", syslog.LOG_INFO, "metrics")
go metrics.Syslog(metrics.DefaultRegistry, 60e9, w)

Periodically emit every metric to Graphite using the Graphite client:


import "github.com/cyberdelia/go-metrics-graphite"

addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:2003")
go graphite.Graphite(metrics.DefaultRegistry, 10e9, "metrics", addr)

Periodically emit every metric into InfluxDB:

NOTE: this has been pulled out of the library due to constant fluctuations in the InfluxDB API. In fact, all client libraries are on their way out. see issues #121 and #124 for progress and details.

import "github.com/vrischmann/go-metrics-influxdb"

go influxdb.InfluxDB(metrics.DefaultRegistry,
  10e9, 
  "127.0.0.1:8086", 
  "database-name", 
  "username", 
  "password"
)

Periodically upload every metric to Librato using the Librato client:

Note: the client included with this repository under the librato package has been deprecated and moved to the repository linked above.

import "github.com/mihasya/go-metrics-librato"

go librato.Librato(metrics.DefaultRegistry,
    10e9,                  // interval
    "example@example.com", // account owner email address
    "token",               // Librato API token
    "hostname",            // source
    []float64{0.95},       // percentiles to send
    time.Millisecond,      // time unit
)

Periodically emit every metric to StatHat:

import "github.com/rcrowley/go-metrics/stathat"

go stathat.Stathat(metrics.DefaultRegistry, 10e9, "example@example.com")

Maintain all metrics along with expvars at /debug/metrics:

This uses the same mechanism as the official expvar but exposed under /debug/metrics, which shows a json representation of all your usual expvars as well as all your go-metrics.

import "github.com/rcrowley/go-metrics/exp"

exp.Exp(metrics.DefaultRegistry)

Installation

go get github.com/rcrowley/go-metrics

StatHat support additionally requires their Go client:

go get github.com/stathat/go

Publishing Metrics

Clients are available for the following destinations:

Documentation

Overview

Go port of Coda Hale's Metrics library

<https://github.com/rcrowley/go-metrics>

Coda Hale's original work: <https://github.com/codahale/metrics>

Example
c := NewCounter()
Register("money", c)
c.Inc(17)

// Threadsafe registration
t := GetOrRegisterTimer("db.get.latency", nil)
t.Time(func() { time.Sleep(10 * time.Millisecond) })
t.Update(1)

fmt.Println(c.Count())
fmt.Println(t.Min())
Output:

17
1

Index

Examples

Constants

View Source
const InitialResettingTimerSliceCap = 10

Initial slice capacity for the values stored in a ResettingTimer

Variables

View Source
var (
	DefaultRegistry    = NewRegistry()
	EphemeralRegistry  = NewRegistry()
	AccountingRegistry = NewRegistry() // registry used in swarm
)
View Source
var Enabled = false

Enabled is checked by the constructor functions for all of the standard metrics. If it is true, the metric returned is a stub.

This global kill-switch helps quantify the observer effect and makes for less cluttered pprof profiles.

View Source
var EnabledExpensive = false

EnabledExpensive is a soft-flag meant for external packages to check if costly metrics gathering is allowed or not. The goal is to separate standard metrics for health monitoring and debug metrics that might impact runtime performance.

Functions

func CaptureDebugGCStats added in v1.8.2

func CaptureDebugGCStats(r Registry, d time.Duration)

Capture new values for the Go garbage collector statistics exported in debug.GCStats. This is designed to be called as a goroutine.

func CaptureDebugGCStatsOnce added in v1.8.2

func CaptureDebugGCStatsOnce(r Registry)

Capture new values for the Go garbage collector statistics exported in debug.GCStats. This is designed to be called in a background goroutine. Giving a registry which has not been given to RegisterDebugGCStats will panic.

Be careful (but much less so) with this because debug.ReadGCStats calls the C function runtime·lock(runtime·mheap) which, while not a stop-the-world operation, isn't something you want to be doing all the time.

func CaptureRuntimeMemStats added in v1.8.2

func CaptureRuntimeMemStats(r Registry, d time.Duration)

Capture new values for the Go runtime statistics exported in runtime.MemStats. This is designed to be called as a goroutine.

func CaptureRuntimeMemStatsOnce added in v1.8.2

func CaptureRuntimeMemStatsOnce(r Registry)

Capture new values for the Go runtime statistics exported in runtime.MemStats. This is designed to be called in a background goroutine. Giving a registry which has not been given to RegisterRuntimeMemStats will panic.

Be very careful with this because runtime.ReadMemStats calls the C functions runtime·semacquire(&runtime·worldsema) and runtime·stoptheworld() and that last one does what it says on the tin.

func CollectProcessMetrics

func CollectProcessMetrics(refresh time.Duration)

CollectProcessMetrics periodically collects various metrics about the running process.

func Each added in v1.8.2

func Each(f func(string, interface{}))

Call the given function for each registered metric.

func Get added in v1.8.2

func Get(name string) interface{}

Get the metric by the given name or nil if none is registered.

func GetOrRegister added in v1.8.2

func GetOrRegister(name string, i interface{}) interface{}

Gets an existing metric or creates and registers a new one. Threadsafe alternative to calling Get and Register on failure.

func Graphite added in v1.8.2

func Graphite(r Registry, d time.Duration, prefix string, addr *net.TCPAddr)

Graphite is a blocking exporter function which reports metrics in r to a graphite server located at addr, flushing them every d duration and prepending metric names with prefix.

Example
addr, _ := net.ResolveTCPAddr("net", ":2003")
go Graphite(DefaultRegistry, 1*time.Second, "some.prefix", addr)
Output:

func GraphiteOnce added in v1.8.2

func GraphiteOnce(c GraphiteConfig) error

GraphiteOnce performs a single submission to Graphite, returning a non-nil error on failed connections. This can be used in a loop similar to GraphiteWithConfig for custom error handling.

func GraphiteWithConfig added in v1.8.2

func GraphiteWithConfig(c GraphiteConfig)

GraphiteWithConfig is a blocking exporter function just like Graphite, but it takes a GraphiteConfig instead.

Example
addr, _ := net.ResolveTCPAddr("net", ":2003")
go GraphiteWithConfig(GraphiteConfig{
	Addr:          addr,
	Registry:      DefaultRegistry,
	FlushInterval: 1 * time.Second,
	DurationUnit:  time.Millisecond,
	Percentiles:   []float64{0.5, 0.75, 0.99, 0.999},
})
Output:

func Log added in v1.8.2

func Log(r Registry, freq time.Duration, l Logger)

func LogScaled added in v1.8.2

func LogScaled(r Registry, freq time.Duration, scale time.Duration, l Logger)

Output each metric in the given registry periodically using the given logger. Print timings in `scale` units (eg time.Millisecond) rather than nanos.

func MustRegister added in v1.8.2

func MustRegister(name string, i interface{})

Register the given metric under the given name. Panics if a metric by the given name is already registered.

func OpenTSDB added in v1.8.2

func OpenTSDB(r Registry, d time.Duration, prefix string, addr *net.TCPAddr)

OpenTSDB is a blocking exporter function which reports metrics in r to a TSDB server located at addr, flushing them every d duration and prepending metric names with prefix.

Example
addr, _ := net.ResolveTCPAddr("net", ":2003")
go OpenTSDB(DefaultRegistry, 1*time.Second, "some.prefix", addr)
Output:

func OpenTSDBWithConfig added in v1.8.2

func OpenTSDBWithConfig(c OpenTSDBConfig)

OpenTSDBWithConfig is a blocking exporter function just like OpenTSDB, but it takes a OpenTSDBConfig instead.

Example
addr, _ := net.ResolveTCPAddr("net", ":2003")
go OpenTSDBWithConfig(OpenTSDBConfig{
	Addr:          addr,
	Registry:      DefaultRegistry,
	FlushInterval: 1 * time.Second,
	DurationUnit:  time.Millisecond,
})
Output:

func ReadCPUStats added in v1.9.0

func ReadCPUStats(stats *CPUStats)

ReadCPUStats retrieves the current CPU stats.

func ReadDiskStats

func ReadDiskStats(stats *DiskStats) error

ReadDiskStats retrieves the disk IO stats belonging to the current process.

func Register added in v1.8.2

func Register(name string, i interface{}) error

Register the given metric under the given name. Returns a DuplicateMetric if a metric by the given name is already registered.

func RegisterDebugGCStats added in v1.8.2

func RegisterDebugGCStats(r Registry)

Register metrics for the Go garbage collector statistics exported in debug.GCStats. The metrics are named by their fully-qualified Go symbols, i.e. debug.GCStats.PauseTotal.

func RegisterRuntimeMemStats added in v1.8.2

func RegisterRuntimeMemStats(r Registry)

Register runtimeMetrics for the Go runtime statistics exported in runtime and specifically runtime.MemStats. The runtimeMetrics are named by their fully-qualified Go symbols, i.e. runtime.MemStats.Alloc.

func RunHealthchecks added in v1.8.2

func RunHealthchecks()

Run all registered healthchecks.

func SampleMax added in v1.8.2

func SampleMax(values []int64) int64

SampleMax returns the maximum value of the slice of int64.

func SampleMean added in v1.8.2

func SampleMean(values []int64) float64

SampleMean returns the mean value of the slice of int64.

func SampleMin added in v1.8.2

func SampleMin(values []int64) int64

SampleMin returns the minimum value of the slice of int64.

func SamplePercentile added in v1.8.2

func SamplePercentile(values int64Slice, p float64) float64

SamplePercentiles returns an arbitrary percentile of the slice of int64.

func SamplePercentiles added in v1.8.2

func SamplePercentiles(values int64Slice, ps []float64) []float64

SamplePercentiles returns a slice of arbitrary percentiles of the slice of int64.

func SampleStdDev added in v1.8.2

func SampleStdDev(values []int64) float64

SampleStdDev returns the standard deviation of the slice of int64.

func SampleSum added in v1.8.2

func SampleSum(values []int64) int64

SampleSum returns the sum of the slice of int64.

func SampleVariance added in v1.8.2

func SampleVariance(values []int64) float64

SampleVariance returns the variance of the slice of int64.

func Syslog added in v1.8.2

func Syslog(r Registry, d time.Duration, w *syslog.Writer)

Output each metric in the given registry to syslog periodically using the given syslogger.

func Unregister added in v1.8.2

func Unregister(name string)

Unregister the metric with the given name.

func Write added in v1.8.2

func Write(r Registry, d time.Duration, w io.Writer)

Write sorts writes each metric in the given registry periodically to the given io.Writer.

func WriteJSON added in v1.8.2

func WriteJSON(r Registry, d time.Duration, w io.Writer)

WriteJSON writes metrics from the given registry periodically to the specified io.Writer as JSON.

func WriteJSONOnce added in v1.8.2

func WriteJSONOnce(r Registry, w io.Writer)

WriteJSONOnce writes metrics from the given registry to the specified io.Writer as JSON.

func WriteOnce added in v1.8.2

func WriteOnce(r Registry, w io.Writer)

WriteOnce sorts and writes metrics in the given registry to the given io.Writer.

Types

type CPUStats added in v1.9.0

type CPUStats struct {
	GlobalTime int64 // Time spent by the CPU working on all processes
	GlobalWait int64 // Time spent by waiting on disk for all processes
	LocalTime  int64 // Time spent by the CPU working on this process
}

CPUStats is the system and process CPU stats.

type Counter added in v1.8.2

type Counter interface {
	Clear()
	Count() int64
	Dec(int64)
	Inc(int64)
	Snapshot() Counter
}

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

func GetOrRegisterCounter added in v1.8.2

func GetOrRegisterCounter(name string, r Registry) Counter

GetOrRegisterCounter returns an existing Counter or constructs and registers a new StandardCounter.

func GetOrRegisterCounterForced added in v1.8.18

func GetOrRegisterCounterForced(name string, r Registry) Counter

GetOrRegisterCounterForced returns an existing Counter or constructs and registers a new Counter no matter the global switch is enabled or not. Be sure to unregister the counter from the registry once it is of no use to allow for garbage collection.

func NewCounter added in v1.5.0

func NewCounter() Counter

NewCounter constructs a new StandardCounter.

func NewCounterForced added in v1.8.18

func NewCounterForced() Counter

NewCounterForced constructs a new StandardCounter and returns it no matter if the global switch is enabled or not.

func NewRegisteredCounter added in v1.8.2

func NewRegisteredCounter(name string, r Registry) Counter

NewRegisteredCounter constructs and registers a new StandardCounter.

func NewRegisteredCounterForced added in v1.8.18

func NewRegisteredCounterForced(name string, r Registry) Counter

NewRegisteredCounterForced constructs and registers a new StandardCounter and launches a goroutine no matter the global switch is enabled or not. Be sure to unregister the counter from the registry once it is of no use to allow for garbage collection.

type CounterSnapshot added in v1.8.2

type CounterSnapshot int64

CounterSnapshot is a read-only copy of another Counter.

func (CounterSnapshot) Clear added in v1.8.2

func (CounterSnapshot) Clear()

Clear panics.

func (CounterSnapshot) Count added in v1.8.2

func (c CounterSnapshot) Count() int64

Count returns the count at the time the snapshot was taken.

func (CounterSnapshot) Dec added in v1.8.2

func (CounterSnapshot) Dec(int64)

Dec panics.

func (CounterSnapshot) Inc added in v1.8.2

func (CounterSnapshot) Inc(int64)

Inc panics.

func (CounterSnapshot) Snapshot added in v1.8.2

func (c CounterSnapshot) Snapshot() Counter

Snapshot returns the snapshot.

type DiskStats

type DiskStats struct {
	ReadCount  int64 // Number of read operations executed
	ReadBytes  int64 // Total number of bytes read
	WriteCount int64 // Number of write operations executed
	WriteBytes int64 // Total number of byte written
}

DiskStats is the per process disk io stats.

type DuplicateMetric added in v1.8.2

type DuplicateMetric string

DuplicateMetric is the error returned by Registry.Register when a metric already exists. If you mean to Register that metric you must first Unregister the existing metric.

func (DuplicateMetric) Error added in v1.8.2

func (err DuplicateMetric) Error() string

type EWMA added in v1.8.2

type EWMA interface {
	Rate() float64
	Snapshot() EWMA
	Tick()
	Update(int64)
}

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

func NewEWMA added in v1.8.2

func NewEWMA(alpha float64) EWMA

NewEWMA constructs a new EWMA with the given alpha.

func NewEWMA1 added in v1.8.2

func NewEWMA1() EWMA

NewEWMA1 constructs a new EWMA for a one-minute moving average.

func NewEWMA15 added in v1.8.2

func NewEWMA15() EWMA

NewEWMA15 constructs a new EWMA for a fifteen-minute moving average.

func NewEWMA5 added in v1.8.2

func NewEWMA5() EWMA

NewEWMA5 constructs a new EWMA for a five-minute moving average.

type EWMASnapshot added in v1.8.2

type EWMASnapshot float64

EWMASnapshot is a read-only copy of another EWMA.

func (EWMASnapshot) Rate added in v1.8.2

func (a EWMASnapshot) Rate() float64

Rate returns the rate of events per second at the time the snapshot was taken.

func (EWMASnapshot) Snapshot added in v1.8.2

func (a EWMASnapshot) Snapshot() EWMA

Snapshot returns the snapshot.

func (EWMASnapshot) Tick added in v1.8.2

func (EWMASnapshot) Tick()

Tick panics.

func (EWMASnapshot) Update added in v1.8.2

func (EWMASnapshot) Update(int64)

Update panics.

type ExpDecaySample added in v1.8.2

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

ExpDecaySample is an exponentially-decaying sample using a forward-decaying priority reservoir. See Cormode et al's "Forward Decay: A Practical Time Decay Model for Streaming Systems".

<http://dimacs.rutgers.edu/~graham/pubs/papers/fwddecay.pdf>

func (*ExpDecaySample) Clear added in v1.8.2

func (s *ExpDecaySample) Clear()

Clear clears all samples.

func (*ExpDecaySample) Count added in v1.8.2

func (s *ExpDecaySample) Count() int64

Count returns the number of samples recorded, which may exceed the reservoir size.

func (*ExpDecaySample) Max added in v1.8.2

func (s *ExpDecaySample) Max() int64

Max returns the maximum value in the sample, which may not be the maximum value ever to be part of the sample.

func (*ExpDecaySample) Mean added in v1.8.2

func (s *ExpDecaySample) Mean() float64

Mean returns the mean of the values in the sample.

func (*ExpDecaySample) Min added in v1.8.2

func (s *ExpDecaySample) Min() int64

Min returns the minimum value in the sample, which may not be the minimum value ever to be part of the sample.

func (*ExpDecaySample) Percentile added in v1.8.2

func (s *ExpDecaySample) Percentile(p float64) float64

Percentile returns an arbitrary percentile of values in the sample.

func (*ExpDecaySample) Percentiles added in v1.8.2

func (s *ExpDecaySample) Percentiles(ps []float64) []float64

Percentiles returns a slice of arbitrary percentiles of values in the sample.

func (*ExpDecaySample) Size added in v1.8.2

func (s *ExpDecaySample) Size() int

Size returns the size of the sample, which is at most the reservoir size.

func (*ExpDecaySample) Snapshot added in v1.8.2

func (s *ExpDecaySample) Snapshot() Sample

Snapshot returns a read-only copy of the sample.

func (*ExpDecaySample) StdDev added in v1.8.2

func (s *ExpDecaySample) StdDev() float64

StdDev returns the standard deviation of the values in the sample.

func (*ExpDecaySample) Sum added in v1.8.2

func (s *ExpDecaySample) Sum() int64

Sum returns the sum of the values in the sample.

func (*ExpDecaySample) Update added in v1.8.2

func (s *ExpDecaySample) Update(v int64)

Update samples a new value.

func (*ExpDecaySample) Values added in v1.8.2

func (s *ExpDecaySample) Values() []int64

Values returns a copy of the values in the sample.

func (*ExpDecaySample) Variance added in v1.8.2

func (s *ExpDecaySample) Variance() float64

Variance returns the variance of the values in the sample.

type FunctionalGauge added in v1.8.2

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

FunctionalGauge returns value from given function

func (FunctionalGauge) Snapshot added in v1.8.2

func (g FunctionalGauge) Snapshot() Gauge

Snapshot returns the snapshot.

func (FunctionalGauge) Update added in v1.8.2

func (FunctionalGauge) Update(int64)

Update panics.

func (FunctionalGauge) Value added in v1.8.2

func (g FunctionalGauge) Value() int64

Value returns the gauge's current value.

type FunctionalGaugeFloat64 added in v1.8.2

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

FunctionalGaugeFloat64 returns value from given function

func (FunctionalGaugeFloat64) Snapshot added in v1.8.2

func (g FunctionalGaugeFloat64) Snapshot() GaugeFloat64

Snapshot returns the snapshot.

func (FunctionalGaugeFloat64) Update added in v1.8.2

Update panics.

func (FunctionalGaugeFloat64) Value added in v1.8.2

func (g FunctionalGaugeFloat64) Value() float64

Value returns the gauge's current value.

type Gauge added in v1.8.2

type Gauge interface {
	Snapshot() Gauge
	Update(int64)
	Value() int64
}

Gauges hold an int64 value that can be set arbitrarily.

func GetOrRegisterGauge added in v1.8.2

func GetOrRegisterGauge(name string, r Registry) Gauge

GetOrRegisterGauge returns an existing Gauge or constructs and registers a new StandardGauge.

Example
m := "server.bytes_sent"
g := GetOrRegisterGauge(m, nil)
g.Update(47)
fmt.Println(g.Value()) 
Output:

47

func NewFunctionalGauge added in v1.8.2

func NewFunctionalGauge(f func() int64) Gauge

NewFunctionalGauge constructs a new FunctionalGauge.

func NewGauge added in v1.8.2

func NewGauge() Gauge

NewGauge constructs a new StandardGauge.

func NewRegisteredFunctionalGauge added in v1.8.2

func NewRegisteredFunctionalGauge(name string, r Registry, f func() int64) Gauge

NewRegisteredFunctionalGauge constructs and registers a new StandardGauge.

func NewRegisteredGauge added in v1.8.2

func NewRegisteredGauge(name string, r Registry) Gauge

NewRegisteredGauge constructs and registers a new StandardGauge.

type GaugeFloat64 added in v1.8.2

type GaugeFloat64 interface {
	Snapshot() GaugeFloat64
	Update(float64)
	Value() float64
}

GaugeFloat64s hold a float64 value that can be set arbitrarily.

func GetOrRegisterGaugeFloat64 added in v1.8.2

func GetOrRegisterGaugeFloat64(name string, r Registry) GaugeFloat64

GetOrRegisterGaugeFloat64 returns an existing GaugeFloat64 or constructs and registers a new StandardGaugeFloat64.

func NewFunctionalGaugeFloat64 added in v1.8.2

func NewFunctionalGaugeFloat64(f func() float64) GaugeFloat64

NewFunctionalGauge constructs a new FunctionalGauge.

func NewGaugeFloat64 added in v1.8.2

func NewGaugeFloat64() GaugeFloat64

NewGaugeFloat64 constructs a new StandardGaugeFloat64.

func NewRegisteredFunctionalGaugeFloat64 added in v1.8.2

func NewRegisteredFunctionalGaugeFloat64(name string, r Registry, f func() float64) GaugeFloat64

NewRegisteredFunctionalGauge constructs and registers a new StandardGauge.

func NewRegisteredGaugeFloat64 added in v1.8.2

func NewRegisteredGaugeFloat64(name string, r Registry) GaugeFloat64

NewRegisteredGaugeFloat64 constructs and registers a new StandardGaugeFloat64.

type GaugeFloat64Snapshot added in v1.8.2

type GaugeFloat64Snapshot float64

GaugeFloat64Snapshot is a read-only copy of another GaugeFloat64.

func (GaugeFloat64Snapshot) Snapshot added in v1.8.2

func (g GaugeFloat64Snapshot) Snapshot() GaugeFloat64

Snapshot returns the snapshot.

func (GaugeFloat64Snapshot) Update added in v1.8.2

func (GaugeFloat64Snapshot) Update(float64)

Update panics.

func (GaugeFloat64Snapshot) Value added in v1.8.2

func (g GaugeFloat64Snapshot) Value() float64

Value returns the value at the time the snapshot was taken.

type GaugeSnapshot added in v1.8.2

type GaugeSnapshot int64

GaugeSnapshot is a read-only copy of another Gauge.

func (GaugeSnapshot) Snapshot added in v1.8.2

func (g GaugeSnapshot) Snapshot() Gauge

Snapshot returns the snapshot.

func (GaugeSnapshot) Update added in v1.8.2

func (GaugeSnapshot) Update(int64)

Update panics.

func (GaugeSnapshot) Value added in v1.8.2

func (g GaugeSnapshot) Value() int64

Value returns the value at the time the snapshot was taken.

type GraphiteConfig added in v1.8.2

type GraphiteConfig struct {
	Addr          *net.TCPAddr  // Network address to connect to
	Registry      Registry      // Registry to be exported
	FlushInterval time.Duration // Flush interval
	DurationUnit  time.Duration // Time conversion unit for durations
	Prefix        string        // Prefix to be prepended to metric names
	Percentiles   []float64     // Percentiles to export from timers and histograms
}

GraphiteConfig provides a container with configuration parameters for the Graphite exporter

type Healthcheck added in v1.8.2

type Healthcheck interface {
	Check()
	Error() error
	Healthy()
	Unhealthy(error)
}

Healthchecks hold an error value describing an arbitrary up/down status.

func NewHealthcheck added in v1.8.2

func NewHealthcheck(f func(Healthcheck)) Healthcheck

NewHealthcheck constructs a new Healthcheck which will use the given function to update its status.

type Histogram added in v1.8.2

type Histogram interface {
	Clear()
	Count() int64
	Max() int64
	Mean() float64
	Min() int64
	Percentile(float64) float64
	Percentiles([]float64) []float64
	Sample() Sample
	Snapshot() Histogram
	StdDev() float64
	Sum() int64
	Update(int64)
	Variance() float64
}

Histograms calculate distribution statistics from a series of int64 values.

func GetOrRegisterHistogram added in v1.8.2

func GetOrRegisterHistogram(name string, r Registry, s Sample) Histogram

GetOrRegisterHistogram returns an existing Histogram or constructs and registers a new StandardHistogram.

func NewHistogram added in v1.8.2

func NewHistogram(s Sample) Histogram

NewHistogram constructs a new StandardHistogram from a Sample.

func NewRegisteredHistogram added in v1.8.2

func NewRegisteredHistogram(name string, r Registry, s Sample) Histogram

NewRegisteredHistogram constructs and registers a new StandardHistogram from a Sample.

type HistogramSnapshot added in v1.8.2

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

HistogramSnapshot is a read-only copy of another Histogram.

func (*HistogramSnapshot) Clear added in v1.8.2

func (*HistogramSnapshot) Clear()

Clear panics.

func (*HistogramSnapshot) Count added in v1.8.2

func (h *HistogramSnapshot) Count() int64

Count returns the number of samples recorded at the time the snapshot was taken.

func (*HistogramSnapshot) Max added in v1.8.2

func (h *HistogramSnapshot) Max() int64

Max returns the maximum value in the sample at the time the snapshot was taken.

func (*HistogramSnapshot) Mean added in v1.8.2

func (h *HistogramSnapshot) Mean() float64

Mean returns the mean of the values in the sample at the time the snapshot was taken.

func (*HistogramSnapshot) Min added in v1.8.2

func (h *HistogramSnapshot) Min() int64

Min returns the minimum value in the sample at the time the snapshot was taken.

func (*HistogramSnapshot) Percentile added in v1.8.2

func (h *HistogramSnapshot) Percentile(p float64) float64

Percentile returns an arbitrary percentile of values in the sample at the time the snapshot was taken.

func (*HistogramSnapshot) Percentiles added in v1.8.2

func (h *HistogramSnapshot) Percentiles(ps []float64) []float64

Percentiles returns a slice of arbitrary percentiles of values in the sample at the time the snapshot was taken.

func (*HistogramSnapshot) Sample added in v1.8.2

func (h *HistogramSnapshot) Sample() Sample

Sample returns the Sample underlying the histogram.

func (*HistogramSnapshot) Snapshot added in v1.8.2

func (h *HistogramSnapshot) Snapshot() Histogram

Snapshot returns the snapshot.

func (*HistogramSnapshot) StdDev added in v1.8.2

func (h *HistogramSnapshot) StdDev() float64

StdDev returns the standard deviation of the values in the sample at the time the snapshot was taken.

func (*HistogramSnapshot) Sum added in v1.8.2

func (h *HistogramSnapshot) Sum() int64

Sum returns the sum in the sample at the time the snapshot was taken.

func (*HistogramSnapshot) Update added in v1.8.2

func (*HistogramSnapshot) Update(int64)

Update panics.

func (*HistogramSnapshot) Variance added in v1.8.2

func (h *HistogramSnapshot) Variance() float64

Variance returns the variance of inputs at the time the snapshot was taken.

type Int64Slice added in v1.8.2

type Int64Slice []int64

Int64Slice attaches the methods of sort.Interface to []int64, sorting in increasing order.

func (Int64Slice) Len added in v1.8.2

func (s Int64Slice) Len() int

func (Int64Slice) Less added in v1.8.2

func (s Int64Slice) Less(i, j int) bool

func (Int64Slice) Swap added in v1.8.2

func (s Int64Slice) Swap(i, j int)

type Logger added in v1.8.2

type Logger interface {
	Printf(format string, v ...interface{})
}

type Meter added in v1.8.2

type Meter interface {
	Count() int64
	Mark(int64)
	Rate1() float64
	Rate5() float64
	Rate15() float64
	RateMean() float64
	Snapshot() Meter
	Stop()
}

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

func GetOrRegisterMeter added in v1.8.2

func GetOrRegisterMeter(name string, r Registry) Meter

GetOrRegisterMeter returns an existing Meter or constructs and registers a new StandardMeter. Be sure to unregister the meter from the registry once it is of no use to allow for garbage collection.

func GetOrRegisterMeterForced added in v1.8.16

func GetOrRegisterMeterForced(name string, r Registry) Meter

GetOrRegisterMeterForced returns an existing Meter or constructs and registers a new StandardMeter no matter the global switch is enabled or not. Be sure to unregister the meter from the registry once it is of no use to allow for garbage collection.

func NewMeter

func NewMeter() Meter

NewMeter constructs a new StandardMeter and launches a goroutine. Be sure to call Stop() once the meter is of no use to allow for garbage collection.

func NewMeterForced added in v1.8.16

func NewMeterForced() Meter

NewMeterForced constructs a new StandardMeter and launches a goroutine no matter the global switch is enabled or not. Be sure to call Stop() once the meter is of no use to allow for garbage collection.

func NewRegisteredMeter added in v1.8.2

func NewRegisteredMeter(name string, r Registry) Meter

NewRegisteredMeter constructs and registers a new StandardMeter and launches a goroutine. Be sure to unregister the meter from the registry once it is of no use to allow for garbage collection.

func NewRegisteredMeterForced added in v1.8.16

func NewRegisteredMeterForced(name string, r Registry) Meter

NewRegisteredMeterForced constructs and registers a new StandardMeter and launches a goroutine no matter the global switch is enabled or not. Be sure to unregister the meter from the registry once it is of no use to allow for garbage collection.

type MeterSnapshot added in v1.8.2

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

MeterSnapshot is a read-only copy of another Meter.

func (*MeterSnapshot) Count added in v1.8.2

func (m *MeterSnapshot) Count() int64

Count returns the count of events at the time the snapshot was taken.

func (*MeterSnapshot) Mark added in v1.8.2

func (*MeterSnapshot) Mark(n int64)

Mark panics.

func (*MeterSnapshot) Rate1 added in v1.8.2

func (m *MeterSnapshot) Rate1() float64

Rate1 returns the one-minute moving average rate of events per second at the time the snapshot was taken.

func (*MeterSnapshot) Rate15 added in v1.8.2

func (m *MeterSnapshot) Rate15() float64

Rate15 returns the fifteen-minute moving average rate of events per second at the time the snapshot was taken.

func (*MeterSnapshot) Rate5 added in v1.8.2

func (m *MeterSnapshot) Rate5() float64

Rate5 returns the five-minute moving average rate of events per second at the time the snapshot was taken.

func (*MeterSnapshot) RateMean added in v1.8.2

func (m *MeterSnapshot) RateMean() float64

RateMean returns the meter's mean rate of events per second at the time the snapshot was taken.

func (*MeterSnapshot) Snapshot added in v1.8.2

func (m *MeterSnapshot) Snapshot() Meter

Snapshot returns the snapshot.

func (*MeterSnapshot) Stop added in v1.8.2

func (m *MeterSnapshot) Stop()

Stop is a no-op.

type NilCounter added in v1.8.2

type NilCounter struct{}

NilCounter is a no-op Counter.

func (NilCounter) Clear added in v1.8.2

func (NilCounter) Clear()

Clear is a no-op.

func (NilCounter) Count added in v1.8.2

func (NilCounter) Count() int64

Count is a no-op.

func (NilCounter) Dec added in v1.8.2

func (NilCounter) Dec(i int64)

Dec is a no-op.

func (NilCounter) Inc added in v1.8.2

func (NilCounter) Inc(i int64)

Inc is a no-op.

func (NilCounter) Snapshot added in v1.8.2

func (NilCounter) Snapshot() Counter

Snapshot is a no-op.

type NilEWMA added in v1.8.2

type NilEWMA struct{}

NilEWMA is a no-op EWMA.

func (NilEWMA) Rate added in v1.8.2

func (NilEWMA) Rate() float64

Rate is a no-op.

func (NilEWMA) Snapshot added in v1.8.2

func (NilEWMA) Snapshot() EWMA

Snapshot is a no-op.

func (NilEWMA) Tick added in v1.8.2

func (NilEWMA) Tick()

Tick is a no-op.

func (NilEWMA) Update added in v1.8.2

func (NilEWMA) Update(n int64)

Update is a no-op.

type NilGauge added in v1.8.2

type NilGauge struct{}

NilGauge is a no-op Gauge.

func (NilGauge) Snapshot added in v1.8.2

func (NilGauge) Snapshot() Gauge

Snapshot is a no-op.

func (NilGauge) Update added in v1.8.2

func (NilGauge) Update(v int64)

Update is a no-op.

func (NilGauge) Value added in v1.8.2

func (NilGauge) Value() int64

Value is a no-op.

type NilGaugeFloat64 added in v1.8.2

type NilGaugeFloat64 struct{}

NilGauge is a no-op Gauge.

func (NilGaugeFloat64) Snapshot added in v1.8.2

func (NilGaugeFloat64) Snapshot() GaugeFloat64

Snapshot is a no-op.

func (NilGaugeFloat64) Update added in v1.8.2

func (NilGaugeFloat64) Update(v float64)

Update is a no-op.

func (NilGaugeFloat64) Value added in v1.8.2

func (NilGaugeFloat64) Value() float64

Value is a no-op.

type NilHealthcheck added in v1.8.2

type NilHealthcheck struct{}

NilHealthcheck is a no-op.

func (NilHealthcheck) Check added in v1.8.2

func (NilHealthcheck) Check()

Check is a no-op.

func (NilHealthcheck) Error added in v1.8.2

func (NilHealthcheck) Error() error

Error is a no-op.

func (NilHealthcheck) Healthy added in v1.8.2

func (NilHealthcheck) Healthy()

Healthy is a no-op.

func (NilHealthcheck) Unhealthy added in v1.8.2

func (NilHealthcheck) Unhealthy(error)

Unhealthy is a no-op.

type NilHistogram added in v1.8.2

type NilHistogram struct{}

NilHistogram is a no-op Histogram.

func (NilHistogram) Clear added in v1.8.2

func (NilHistogram) Clear()

Clear is a no-op.

func (NilHistogram) Count added in v1.8.2

func (NilHistogram) Count() int64

Count is a no-op.

func (NilHistogram) Max added in v1.8.2

func (NilHistogram) Max() int64

Max is a no-op.

func (NilHistogram) Mean added in v1.8.2

func (NilHistogram) Mean() float64

Mean is a no-op.

func (NilHistogram) Min added in v1.8.2

func (NilHistogram) Min() int64

Min is a no-op.

func (NilHistogram) Percentile added in v1.8.2

func (NilHistogram) Percentile(p float64) float64

Percentile is a no-op.

func (NilHistogram) Percentiles added in v1.8.2

func (NilHistogram) Percentiles(ps []float64) []float64

Percentiles is a no-op.

func (NilHistogram) Sample added in v1.8.2

func (NilHistogram) Sample() Sample

Sample is a no-op.

func (NilHistogram) Snapshot added in v1.8.2

func (NilHistogram) Snapshot() Histogram

Snapshot is a no-op.

func (NilHistogram) StdDev added in v1.8.2

func (NilHistogram) StdDev() float64

StdDev is a no-op.

func (NilHistogram) Sum added in v1.8.2

func (NilHistogram) Sum() int64

Sum is a no-op.

func (NilHistogram) Update added in v1.8.2

func (NilHistogram) Update(v int64)

Update is a no-op.

func (NilHistogram) Variance added in v1.8.2

func (NilHistogram) Variance() float64

Variance is a no-op.

type NilMeter added in v1.8.2

type NilMeter struct{}

NilMeter is a no-op Meter.

func (NilMeter) Count added in v1.8.2

func (NilMeter) Count() int64

Count is a no-op.

func (NilMeter) Mark added in v1.8.2

func (NilMeter) Mark(n int64)

Mark is a no-op.

func (NilMeter) Rate1 added in v1.8.2

func (NilMeter) Rate1() float64

Rate1 is a no-op.

func (NilMeter) Rate15 added in v1.8.2

func (NilMeter) Rate15() float64

Rate15is a no-op.

func (NilMeter) Rate5 added in v1.8.2

func (NilMeter) Rate5() float64

Rate5 is a no-op.

func (NilMeter) RateMean added in v1.8.2

func (NilMeter) RateMean() float64

RateMean is a no-op.

func (NilMeter) Snapshot added in v1.8.2

func (NilMeter) Snapshot() Meter

Snapshot is a no-op.

func (NilMeter) Stop added in v1.8.2

func (NilMeter) Stop()

Stop is a no-op.

type NilResettingTimer added in v1.8.2

type NilResettingTimer struct {
}

NilResettingTimer is a no-op ResettingTimer.

func (NilResettingTimer) Mean added in v1.8.2

func (NilResettingTimer) Mean() float64

Mean panics.

func (NilResettingTimer) Percentiles added in v1.8.2

func (NilResettingTimer) Percentiles([]float64) []int64

Percentiles panics.

func (NilResettingTimer) Snapshot added in v1.8.2

func (NilResettingTimer) Snapshot() ResettingTimer

Snapshot is a no-op.

func (NilResettingTimer) Time added in v1.8.2

func (NilResettingTimer) Time(func())

Time is a no-op.

func (NilResettingTimer) Update added in v1.8.2

Update is a no-op.

func (NilResettingTimer) UpdateSince added in v1.8.2

func (NilResettingTimer) UpdateSince(time.Time)

UpdateSince is a no-op.

func (NilResettingTimer) Values added in v1.8.2

func (NilResettingTimer) Values() []int64

Values is a no-op.

type NilSample added in v1.8.2

type NilSample struct{}

NilSample is a no-op Sample.

func (NilSample) Clear added in v1.8.2

func (NilSample) Clear()

Clear is a no-op.

func (NilSample) Count added in v1.8.2

func (NilSample) Count() int64

Count is a no-op.

func (NilSample) Max added in v1.8.2

func (NilSample) Max() int64

Max is a no-op.

func (NilSample) Mean added in v1.8.2

func (NilSample) Mean() float64

Mean is a no-op.

func (NilSample) Min added in v1.8.2

func (NilSample) Min() int64

Min is a no-op.

func (NilSample) Percentile added in v1.8.2

func (NilSample) Percentile(p float64) float64

Percentile is a no-op.

func (NilSample) Percentiles added in v1.8.2

func (NilSample) Percentiles(ps []float64) []float64

Percentiles is a no-op.

func (NilSample) Size added in v1.8.2

func (NilSample) Size() int

Size is a no-op.

func (NilSample) Snapshot added in v1.8.2

func (NilSample) Snapshot() Sample

Sample is a no-op.

func (NilSample) StdDev added in v1.8.2

func (NilSample) StdDev() float64

StdDev is a no-op.

func (NilSample) Sum added in v1.8.2

func (NilSample) Sum() int64

Sum is a no-op.

func (NilSample) Update added in v1.8.2

func (NilSample) Update(v int64)

Update is a no-op.

func (NilSample) Values added in v1.8.2

func (NilSample) Values() []int64

Values is a no-op.

func (NilSample) Variance added in v1.8.2

func (NilSample) Variance() float64

Variance is a no-op.

type NilTimer added in v1.8.2

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

NilTimer is a no-op Timer.

func (NilTimer) Count added in v1.8.2

func (NilTimer) Count() int64

Count is a no-op.

func (NilTimer) Max added in v1.8.2

func (NilTimer) Max() int64

Max is a no-op.

func (NilTimer) Mean added in v1.8.2

func (NilTimer) Mean() float64

Mean is a no-op.

func (NilTimer) Min added in v1.8.2

func (NilTimer) Min() int64

Min is a no-op.

func (NilTimer) Percentile added in v1.8.2

func (NilTimer) Percentile(p float64) float64

Percentile is a no-op.

func (NilTimer) Percentiles added in v1.8.2

func (NilTimer) Percentiles(ps []float64) []float64

Percentiles is a no-op.

func (NilTimer) Rate1 added in v1.8.2

func (NilTimer) Rate1() float64

Rate1 is a no-op.

func (NilTimer) Rate15 added in v1.8.2

func (NilTimer) Rate15() float64

Rate15 is a no-op.

func (NilTimer) Rate5 added in v1.8.2

func (NilTimer) Rate5() float64

Rate5 is a no-op.

func (NilTimer) RateMean added in v1.8.2

func (NilTimer) RateMean() float64

RateMean is a no-op.

func (NilTimer) Snapshot added in v1.8.2

func (NilTimer) Snapshot() Timer

Snapshot is a no-op.

func (NilTimer) StdDev added in v1.8.2

func (NilTimer) StdDev() float64

StdDev is a no-op.

func (NilTimer) Stop added in v1.8.2

func (NilTimer) Stop()

Stop is a no-op.

func (NilTimer) Sum added in v1.8.2

func (NilTimer) Sum() int64

Sum is a no-op.

func (NilTimer) Time added in v1.8.2

func (NilTimer) Time(func())

Time is a no-op.

func (NilTimer) Update added in v1.8.2

func (NilTimer) Update(time.Duration)

Update is a no-op.

func (NilTimer) UpdateSince added in v1.8.2

func (NilTimer) UpdateSince(time.Time)

UpdateSince is a no-op.

func (NilTimer) Variance added in v1.8.2

func (NilTimer) Variance() float64

Variance is a no-op.

type OpenTSDBConfig added in v1.8.2

type OpenTSDBConfig struct {
	Addr          *net.TCPAddr  // Network address to connect to
	Registry      Registry      // Registry to be exported
	FlushInterval time.Duration // Flush interval
	DurationUnit  time.Duration // Time conversion unit for durations
	Prefix        string        // Prefix to be prepended to metric names
}

OpenTSDBConfig provides a container with configuration parameters for the OpenTSDB exporter

type PrefixedRegistry added in v1.8.2

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

func (*PrefixedRegistry) Each added in v1.8.2

func (r *PrefixedRegistry) Each(fn func(string, interface{}))

Call the given function for each registered metric.

func (*PrefixedRegistry) Get added in v1.8.2

func (r *PrefixedRegistry) Get(name string) interface{}

Get the metric by the given name or nil if none is registered.

func (*PrefixedRegistry) GetAll added in v1.8.2

func (r *PrefixedRegistry) GetAll() map[string]map[string]interface{}

GetAll metrics in the Registry

func (*PrefixedRegistry) GetOrRegister added in v1.8.2

func (r *PrefixedRegistry) GetOrRegister(name string, metric interface{}) interface{}

Gets an existing metric or registers the given one. The interface can be the metric to register if not found in registry, or a function returning the metric for lazy instantiation.

func (*PrefixedRegistry) MarshalJSON added in v1.8.2

func (p *PrefixedRegistry) MarshalJSON() ([]byte, error)

func (*PrefixedRegistry) Register added in v1.8.2

func (r *PrefixedRegistry) Register(name string, metric interface{}) error

Register the given metric under the given name. The name will be prefixed.

func (*PrefixedRegistry) RunHealthchecks added in v1.8.2

func (r *PrefixedRegistry) RunHealthchecks()

Run all registered healthchecks.

func (*PrefixedRegistry) Unregister added in v1.8.2

func (r *PrefixedRegistry) Unregister(name string)

Unregister the metric with the given name. The name will be prefixed.

func (*PrefixedRegistry) UnregisterAll added in v1.8.2

func (r *PrefixedRegistry) UnregisterAll()

Unregister all metrics. (Mostly for testing.)

type Registry added in v1.8.2

type Registry interface {

	// Call the given function for each registered metric.
	Each(func(string, interface{}))

	// Get the metric by the given name or nil if none is registered.
	Get(string) interface{}

	// GetAll metrics in the Registry.
	GetAll() map[string]map[string]interface{}

	// Gets an existing metric or registers the given one.
	// The interface can be the metric to register if not found in registry,
	// or a function returning the metric for lazy instantiation.
	GetOrRegister(string, interface{}) interface{}

	// Register the given metric under the given name.
	Register(string, interface{}) error

	// Run all registered healthchecks.
	RunHealthchecks()

	// Unregister the metric with the given name.
	Unregister(string)

	// Unregister all metrics.  (Mostly for testing.)
	UnregisterAll()
}

A Registry holds references to a set of metrics by name and can iterate over them, calling callback functions provided by the user.

This is an interface so as to encourage other structs to implement the Registry API as appropriate.

func NewPrefixedChildRegistry added in v1.8.2

func NewPrefixedChildRegistry(parent Registry, prefix string) Registry

func NewPrefixedRegistry added in v1.8.2

func NewPrefixedRegistry(prefix string) Registry

func NewRegistry added in v1.8.2

func NewRegistry() Registry

Create a new registry.

type ResettingTimer added in v1.8.2

type ResettingTimer interface {
	Values() []int64
	Snapshot() ResettingTimer
	Percentiles([]float64) []int64
	Mean() float64
	Time(func())
	Update(time.Duration)
	UpdateSince(time.Time)
}

ResettingTimer is used for storing aggregated values for timers, which are reset on every flush interval.

func GetOrRegisterResettingTimer added in v1.8.2

func GetOrRegisterResettingTimer(name string, r Registry) ResettingTimer

GetOrRegisterResettingTimer returns an existing ResettingTimer or constructs and registers a new StandardResettingTimer.

func NewRegisteredResettingTimer added in v1.8.2

func NewRegisteredResettingTimer(name string, r Registry) ResettingTimer

NewRegisteredResettingTimer constructs and registers a new StandardResettingTimer.

func NewResettingTimer added in v1.8.2

func NewResettingTimer() ResettingTimer

NewResettingTimer constructs a new StandardResettingTimer

type ResettingTimerSnapshot added in v1.8.2

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

ResettingTimerSnapshot is a point-in-time copy of another ResettingTimer.

func (*ResettingTimerSnapshot) Mean added in v1.8.2

func (t *ResettingTimerSnapshot) Mean() float64

Mean returns the mean of the snapshotted values

func (*ResettingTimerSnapshot) Percentiles added in v1.8.2

func (t *ResettingTimerSnapshot) Percentiles(percentiles []float64) []int64

Percentiles returns the boundaries for the input percentiles.

func (*ResettingTimerSnapshot) Snapshot added in v1.8.2

func (t *ResettingTimerSnapshot) Snapshot() ResettingTimer

Snapshot returns the snapshot.

func (*ResettingTimerSnapshot) Time added in v1.8.2

func (*ResettingTimerSnapshot) Time(func())

Time panics.

func (*ResettingTimerSnapshot) Update added in v1.8.2

Update panics.

func (*ResettingTimerSnapshot) UpdateSince added in v1.8.2

func (*ResettingTimerSnapshot) UpdateSince(time.Time)

UpdateSince panics.

func (*ResettingTimerSnapshot) Values added in v1.8.2

func (t *ResettingTimerSnapshot) Values() []int64

Values returns all values from snapshot.

type Sample added in v1.8.2

type Sample interface {
	Clear()
	Count() int64
	Max() int64
	Mean() float64
	Min() int64
	Percentile(float64) float64
	Percentiles([]float64) []float64
	Size() int
	Snapshot() Sample
	StdDev() float64
	Sum() int64
	Update(int64)
	Values() []int64
	Variance() float64
}

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

func NewExpDecaySample added in v1.8.2

func NewExpDecaySample(reservoirSize int, alpha float64) Sample

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

func NewUniformSample added in v1.8.2

func NewUniformSample(reservoirSize int) Sample

NewUniformSample constructs a new uniform sample with the given reservoir size.

type SampleSnapshot added in v1.8.2

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

SampleSnapshot is a read-only copy of another Sample.

func NewSampleSnapshot added in v1.8.2

func NewSampleSnapshot(count int64, values []int64) *SampleSnapshot

func (*SampleSnapshot) Clear added in v1.8.2

func (*SampleSnapshot) Clear()

Clear panics.

func (*SampleSnapshot) Count added in v1.8.2

func (s *SampleSnapshot) Count() int64

Count returns the count of inputs at the time the snapshot was taken.

func (*SampleSnapshot) Max added in v1.8.2

func (s *SampleSnapshot) Max() int64

Max returns the maximal value at the time the snapshot was taken.

func (*SampleSnapshot) Mean added in v1.8.2

func (s *SampleSnapshot) Mean() float64

Mean returns the mean value at the time the snapshot was taken.

func (*SampleSnapshot) Min added in v1.8.2

func (s *SampleSnapshot) Min() int64

Min returns the minimal value at the time the snapshot was taken.

func (*SampleSnapshot) Percentile added in v1.8.2

func (s *SampleSnapshot) Percentile(p float64) float64

Percentile returns an arbitrary percentile of values at the time the snapshot was taken.

func (*SampleSnapshot) Percentiles added in v1.8.2

func (s *SampleSnapshot) Percentiles(ps []float64) []float64

Percentiles returns a slice of arbitrary percentiles of values at the time the snapshot was taken.

func (*SampleSnapshot) Size added in v1.8.2

func (s *SampleSnapshot) Size() int

Size returns the size of the sample at the time the snapshot was taken.

func (*SampleSnapshot) Snapshot added in v1.8.2

func (s *SampleSnapshot) Snapshot() Sample

Snapshot returns the snapshot.

func (*SampleSnapshot) StdDev added in v1.8.2

func (s *SampleSnapshot) StdDev() float64

StdDev returns the standard deviation of values at the time the snapshot was taken.

func (*SampleSnapshot) Sum added in v1.8.2

func (s *SampleSnapshot) Sum() int64

Sum returns the sum of values at the time the snapshot was taken.

func (*SampleSnapshot) Update added in v1.8.2

func (*SampleSnapshot) Update(int64)

Update panics.

func (*SampleSnapshot) Values added in v1.8.2

func (s *SampleSnapshot) Values() []int64

Values returns a copy of the values in the sample.

func (*SampleSnapshot) Variance added in v1.8.2

func (s *SampleSnapshot) Variance() float64

Variance returns the variance of values at the time the snapshot was taken.

type StandardCounter added in v1.8.2

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

StandardCounter is the standard implementation of a Counter and uses the sync/atomic package to manage a single int64 value.

func (*StandardCounter) Clear added in v1.8.2

func (c *StandardCounter) Clear()

Clear sets the counter to zero.

func (*StandardCounter) Count added in v1.8.2

func (c *StandardCounter) Count() int64

Count returns the current count.

func (*StandardCounter) Dec added in v1.8.2

func (c *StandardCounter) Dec(i int64)

Dec decrements the counter by the given amount.

func (*StandardCounter) Inc added in v1.8.2

func (c *StandardCounter) Inc(i int64)

Inc increments the counter by the given amount.

func (*StandardCounter) Snapshot added in v1.8.2

func (c *StandardCounter) Snapshot() Counter

Snapshot returns a read-only copy of the counter.

type StandardEWMA added in v1.8.2

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

StandardEWMA is the standard implementation of an EWMA and tracks the number of uncounted events and processes them on each tick. It uses the sync/atomic package to manage uncounted events.

func (*StandardEWMA) Rate added in v1.8.2

func (a *StandardEWMA) Rate() float64

Rate returns the moving average rate of events per second.

func (*StandardEWMA) Snapshot added in v1.8.2

func (a *StandardEWMA) Snapshot() EWMA

Snapshot returns a read-only copy of the EWMA.

func (*StandardEWMA) Tick added in v1.8.2

func (a *StandardEWMA) Tick()

Tick ticks the clock to update the moving average. It assumes it is called every five seconds.

func (*StandardEWMA) Update added in v1.8.2

func (a *StandardEWMA) Update(n int64)

Update adds n uncounted events.

type StandardGauge added in v1.8.2

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

StandardGauge is the standard implementation of a Gauge and uses the sync/atomic package to manage a single int64 value.

func (*StandardGauge) Snapshot added in v1.8.2

func (g *StandardGauge) Snapshot() Gauge

Snapshot returns a read-only copy of the gauge.

func (*StandardGauge) Update added in v1.8.2

func (g *StandardGauge) Update(v int64)

Update updates the gauge's value.

func (*StandardGauge) Value added in v1.8.2

func (g *StandardGauge) Value() int64

Value returns the gauge's current value.

type StandardGaugeFloat64 added in v1.8.2

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

StandardGaugeFloat64 is the standard implementation of a GaugeFloat64 and uses sync.Mutex to manage a single float64 value.

func (*StandardGaugeFloat64) Snapshot added in v1.8.2

func (g *StandardGaugeFloat64) Snapshot() GaugeFloat64

Snapshot returns a read-only copy of the gauge.

func (*StandardGaugeFloat64) Update added in v1.8.2

func (g *StandardGaugeFloat64) Update(v float64)

Update updates the gauge's value.

func (*StandardGaugeFloat64) Value added in v1.8.2

func (g *StandardGaugeFloat64) Value() float64

Value returns the gauge's current value.

type StandardHealthcheck added in v1.8.2

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

StandardHealthcheck is the standard implementation of a Healthcheck and stores the status and a function to call to update the status.

func (*StandardHealthcheck) Check added in v1.8.2

func (h *StandardHealthcheck) Check()

Check runs the healthcheck function to update the healthcheck's status.

func (*StandardHealthcheck) Error added in v1.8.2

func (h *StandardHealthcheck) Error() error

Error returns the healthcheck's status, which will be nil if it is healthy.

func (*StandardHealthcheck) Healthy added in v1.8.2

func (h *StandardHealthcheck) Healthy()

Healthy marks the healthcheck as healthy.

func (*StandardHealthcheck) Unhealthy added in v1.8.2

func (h *StandardHealthcheck) Unhealthy(err error)

Unhealthy marks the healthcheck as unhealthy. The error is stored and may be retrieved by the Error method.

type StandardHistogram added in v1.8.2

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

StandardHistogram is the standard implementation of a Histogram and uses a Sample to bound its memory use.

func (*StandardHistogram) Clear added in v1.8.2

func (h *StandardHistogram) Clear()

Clear clears the histogram and its sample.

func (*StandardHistogram) Count added in v1.8.2

func (h *StandardHistogram) Count() int64

Count returns the number of samples recorded since the histogram was last cleared.

func (*StandardHistogram) Max added in v1.8.2

func (h *StandardHistogram) Max() int64

Max returns the maximum value in the sample.

func (*StandardHistogram) Mean added in v1.8.2

func (h *StandardHistogram) Mean() float64

Mean returns the mean of the values in the sample.

func (*StandardHistogram) Min added in v1.8.2

func (h *StandardHistogram) Min() int64

Min returns the minimum value in the sample.

func (*StandardHistogram) Percentile added in v1.8.2

func (h *StandardHistogram) Percentile(p float64) float64

Percentile returns an arbitrary percentile of the values in the sample.

func (*StandardHistogram) Percentiles added in v1.8.2

func (h *StandardHistogram) Percentiles(ps []float64) []float64

Percentiles returns a slice of arbitrary percentiles of the values in the sample.

func (*StandardHistogram) Sample added in v1.8.2

func (h *StandardHistogram) Sample() Sample

Sample returns the Sample underlying the histogram.

func (*StandardHistogram) Snapshot added in v1.8.2

func (h *StandardHistogram) Snapshot() Histogram

Snapshot returns a read-only copy of the histogram.

func (*StandardHistogram) StdDev added in v1.8.2

func (h *StandardHistogram) StdDev() float64

StdDev returns the standard deviation of the values in the sample.

func (*StandardHistogram) Sum added in v1.8.2

func (h *StandardHistogram) Sum() int64

Sum returns the sum in the sample.

func (*StandardHistogram) Update added in v1.8.2

func (h *StandardHistogram) Update(v int64)

Update samples a new value.

func (*StandardHistogram) Variance added in v1.8.2

func (h *StandardHistogram) Variance() float64

Variance returns the variance of the values in the sample.

type StandardMeter added in v1.8.2

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

StandardMeter is the standard implementation of a Meter.

func (*StandardMeter) Count added in v1.8.2

func (m *StandardMeter) Count() int64

Count returns the number of events recorded.

func (*StandardMeter) Mark added in v1.8.2

func (m *StandardMeter) Mark(n int64)

Mark records the occurrence of n events.

func (*StandardMeter) Rate1 added in v1.8.2

func (m *StandardMeter) Rate1() float64

Rate1 returns the one-minute moving average rate of events per second.

func (*StandardMeter) Rate15 added in v1.8.2

func (m *StandardMeter) Rate15() float64

Rate15 returns the fifteen-minute moving average rate of events per second.

func (*StandardMeter) Rate5 added in v1.8.2

func (m *StandardMeter) Rate5() float64

Rate5 returns the five-minute moving average rate of events per second.

func (*StandardMeter) RateMean added in v1.8.2

func (m *StandardMeter) RateMean() float64

RateMean returns the meter's mean rate of events per second.

func (*StandardMeter) Snapshot added in v1.8.2

func (m *StandardMeter) Snapshot() Meter

Snapshot returns a read-only copy of the meter.

func (*StandardMeter) Stop added in v1.8.2

func (m *StandardMeter) Stop()

Stop stops the meter, Mark() will be a no-op if you use it after being stopped.

type StandardRegistry added in v1.8.2

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

The standard implementation of a Registry is a mutex-protected map of names to metrics.

func (*StandardRegistry) Each added in v1.8.2

func (r *StandardRegistry) Each(f func(string, interface{}))

Call the given function for each registered metric.

func (*StandardRegistry) Get added in v1.8.2

func (r *StandardRegistry) Get(name string) interface{}

Get the metric by the given name or nil if none is registered.

func (*StandardRegistry) GetAll added in v1.8.2

func (r *StandardRegistry) GetAll() map[string]map[string]interface{}

GetAll metrics in the Registry

func (*StandardRegistry) GetOrRegister added in v1.8.2

func (r *StandardRegistry) GetOrRegister(name string, i interface{}) interface{}

Gets an existing metric or creates and registers a new one. Threadsafe alternative to calling Get and Register on failure. The interface can be the metric to register if not found in registry, or a function returning the metric for lazy instantiation.

func (*StandardRegistry) MarshalJSON added in v1.8.2

func (r *StandardRegistry) MarshalJSON() ([]byte, error)

MarshalJSON returns a byte slice containing a JSON representation of all the metrics in the Registry.

func (*StandardRegistry) Register added in v1.8.2

func (r *StandardRegistry) Register(name string, i interface{}) error

Register the given metric under the given name. Returns a DuplicateMetric if a metric by the given name is already registered.

func (*StandardRegistry) RunHealthchecks added in v1.8.2

func (r *StandardRegistry) RunHealthchecks()

Run all registered healthchecks.

func (*StandardRegistry) Unregister added in v1.8.2

func (r *StandardRegistry) Unregister(name string)

Unregister the metric with the given name.

func (*StandardRegistry) UnregisterAll added in v1.8.2

func (r *StandardRegistry) UnregisterAll()

Unregister all metrics. (Mostly for testing.)

type StandardResettingTimer added in v1.8.2

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

StandardResettingTimer is the standard implementation of a ResettingTimer. and Meter.

func (*StandardResettingTimer) Mean added in v1.8.2

func (t *StandardResettingTimer) Mean() float64

Mean panics.

func (*StandardResettingTimer) Percentiles added in v1.8.2

func (t *StandardResettingTimer) Percentiles([]float64) []int64

Percentiles panics.

func (*StandardResettingTimer) Snapshot added in v1.8.2

func (t *StandardResettingTimer) Snapshot() ResettingTimer

Snapshot resets the timer and returns a read-only copy of its contents.

func (*StandardResettingTimer) Time added in v1.8.2

func (t *StandardResettingTimer) Time(f func())

Record the duration of the execution of the given function.

func (*StandardResettingTimer) Update added in v1.8.2

func (t *StandardResettingTimer) Update(d time.Duration)

Record the duration of an event.

func (*StandardResettingTimer) UpdateSince added in v1.8.2

func (t *StandardResettingTimer) UpdateSince(ts time.Time)

Record the duration of an event that started at a time and ends now.

func (*StandardResettingTimer) Values added in v1.8.2

func (t *StandardResettingTimer) Values() []int64

Values returns a slice with all measurements.

type StandardTimer added in v1.8.2

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

StandardTimer is the standard implementation of a Timer and uses a Histogram and Meter.

func (*StandardTimer) Count added in v1.8.2

func (t *StandardTimer) Count() int64

Count returns the number of events recorded.

func (*StandardTimer) Max added in v1.8.2

func (t *StandardTimer) Max() int64

Max returns the maximum value in the sample.

func (*StandardTimer) Mean added in v1.8.2

func (t *StandardTimer) Mean() float64

Mean returns the mean of the values in the sample.

func (*StandardTimer) Min added in v1.8.2

func (t *StandardTimer) Min() int64

Min returns the minimum value in the sample.

func (*StandardTimer) Percentile added in v1.8.2

func (t *StandardTimer) Percentile(p float64) float64

Percentile returns an arbitrary percentile of the values in the sample.

func (*StandardTimer) Percentiles added in v1.8.2

func (t *StandardTimer) Percentiles(ps []float64) []float64

Percentiles returns a slice of arbitrary percentiles of the values in the sample.

func (*StandardTimer) Rate1 added in v1.8.2

func (t *StandardTimer) Rate1() float64

Rate1 returns the one-minute moving average rate of events per second.

func (*StandardTimer) Rate15 added in v1.8.2

func (t *StandardTimer) Rate15() float64

Rate15 returns the fifteen-minute moving average rate of events per second.

func (*StandardTimer) Rate5 added in v1.8.2

func (t *StandardTimer) Rate5() float64

Rate5 returns the five-minute moving average rate of events per second.

func (*StandardTimer) RateMean added in v1.8.2

func (t *StandardTimer) RateMean() float64

RateMean returns the meter's mean rate of events per second.

func (*StandardTimer) Snapshot added in v1.8.2

func (t *StandardTimer) Snapshot() Timer

Snapshot returns a read-only copy of the timer.

func (*StandardTimer) StdDev added in v1.8.2

func (t *StandardTimer) StdDev() float64

StdDev returns the standard deviation of the values in the sample.

func (*StandardTimer) Stop added in v1.8.2

func (t *StandardTimer) Stop()

Stop stops the meter.

func (*StandardTimer) Sum added in v1.8.2

func (t *StandardTimer) Sum() int64

Sum returns the sum in the sample.

func (*StandardTimer) Time added in v1.8.2

func (t *StandardTimer) Time(f func())

Record the duration of the execution of the given function.

func (*StandardTimer) Update added in v1.8.2

func (t *StandardTimer) Update(d time.Duration)

Record the duration of an event.

func (*StandardTimer) UpdateSince added in v1.8.2

func (t *StandardTimer) UpdateSince(ts time.Time)

Record the duration of an event that started at a time and ends now.

func (*StandardTimer) Variance added in v1.8.2

func (t *StandardTimer) Variance() float64

Variance returns the variance of the values in the sample.

type Stoppable added in v1.8.2

type Stoppable interface {
	Stop()
}

Stoppable defines the metrics which has to be stopped.

type Timer added in v1.8.2

type Timer interface {
	Count() int64
	Max() int64
	Mean() float64
	Min() int64
	Percentile(float64) float64
	Percentiles([]float64) []float64
	Rate1() float64
	Rate5() float64
	Rate15() float64
	RateMean() float64
	Snapshot() Timer
	StdDev() float64
	Stop()
	Sum() int64
	Time(func())
	Update(time.Duration)
	UpdateSince(time.Time)
	Variance() float64
}

Timers capture the duration and rate of events.

func GetOrRegisterTimer added in v1.8.2

func GetOrRegisterTimer(name string, r Registry) Timer

GetOrRegisterTimer returns an existing Timer or constructs and registers a new StandardTimer. Be sure to unregister the meter from the registry once it is of no use to allow for garbage collection.

Example
m := "account.create.latency"
t := GetOrRegisterTimer(m, nil)
t.Update(47)
fmt.Println(t.Max()) 
Output:

47

func NewCustomTimer added in v1.8.2

func NewCustomTimer(h Histogram, m Meter) Timer

NewCustomTimer constructs a new StandardTimer from a Histogram and a Meter. Be sure to call Stop() once the timer is of no use to allow for garbage collection.

func NewRegisteredTimer added in v1.8.2

func NewRegisteredTimer(name string, r Registry) Timer

NewRegisteredTimer constructs and registers a new StandardTimer. Be sure to unregister the meter from the registry once it is of no use to allow for garbage collection.

func NewTimer

func NewTimer() Timer

NewTimer constructs a new StandardTimer using an exponentially-decaying sample with the same reservoir size and alpha as UNIX load averages. Be sure to call Stop() once the timer is of no use to allow for garbage collection.

type TimerSnapshot added in v1.8.2

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

TimerSnapshot is a read-only copy of another Timer.

func (*TimerSnapshot) Count added in v1.8.2

func (t *TimerSnapshot) Count() int64

Count returns the number of events recorded at the time the snapshot was taken.

func (*TimerSnapshot) Max added in v1.8.2

func (t *TimerSnapshot) Max() int64

Max returns the maximum value at the time the snapshot was taken.

func (*TimerSnapshot) Mean added in v1.8.2

func (t *TimerSnapshot) Mean() float64

Mean returns the mean value at the time the snapshot was taken.

func (*TimerSnapshot) Min added in v1.8.2

func (t *TimerSnapshot) Min() int64

Min returns the minimum value at the time the snapshot was taken.

func (*TimerSnapshot) Percentile added in v1.8.2

func (t *TimerSnapshot) Percentile(p float64) float64

Percentile returns an arbitrary percentile of sampled values at the time the snapshot was taken.

func (*TimerSnapshot) Percentiles added in v1.8.2

func (t *TimerSnapshot) Percentiles(ps []float64) []float64

Percentiles returns a slice of arbitrary percentiles of sampled values at the time the snapshot was taken.

func (*TimerSnapshot) Rate1 added in v1.8.2

func (t *TimerSnapshot) Rate1() float64

Rate1 returns the one-minute moving average rate of events per second at the time the snapshot was taken.

func (*TimerSnapshot) Rate15 added in v1.8.2

func (t *TimerSnapshot) Rate15() float64

Rate15 returns the fifteen-minute moving average rate of events per second at the time the snapshot was taken.

func (*TimerSnapshot) Rate5 added in v1.8.2

func (t *TimerSnapshot) Rate5() float64

Rate5 returns the five-minute moving average rate of events per second at the time the snapshot was taken.

func (*TimerSnapshot) RateMean added in v1.8.2

func (t *TimerSnapshot) RateMean() float64

RateMean returns the meter's mean rate of events per second at the time the snapshot was taken.

func (*TimerSnapshot) Snapshot added in v1.8.2

func (t *TimerSnapshot) Snapshot() Timer

Snapshot returns the snapshot.

func (*TimerSnapshot) StdDev added in v1.8.2

func (t *TimerSnapshot) StdDev() float64

StdDev returns the standard deviation of the values at the time the snapshot was taken.

func (*TimerSnapshot) Stop added in v1.8.2

func (t *TimerSnapshot) Stop()

Stop is a no-op.

func (*TimerSnapshot) Sum added in v1.8.2

func (t *TimerSnapshot) Sum() int64

Sum returns the sum at the time the snapshot was taken.

func (*TimerSnapshot) Time added in v1.8.2

func (*TimerSnapshot) Time(func())

Time panics.

func (*TimerSnapshot) Update added in v1.8.2

func (*TimerSnapshot) Update(time.Duration)

Update panics.

func (*TimerSnapshot) UpdateSince added in v1.8.2

func (*TimerSnapshot) UpdateSince(time.Time)

UpdateSince panics.

func (*TimerSnapshot) Variance added in v1.8.2

func (t *TimerSnapshot) Variance() float64

Variance returns the variance of the values at the time the snapshot was taken.

type UniformSample added in v1.8.2

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

A uniform sample using Vitter's Algorithm R.

<http://www.cs.umd.edu/~samir/498/vitter.pdf>

func (*UniformSample) Clear added in v1.8.2

func (s *UniformSample) Clear()

Clear clears all samples.

func (*UniformSample) Count added in v1.8.2

func (s *UniformSample) Count() int64

Count returns the number of samples recorded, which may exceed the reservoir size.

func (*UniformSample) Max added in v1.8.2

func (s *UniformSample) Max() int64

Max returns the maximum value in the sample, which may not be the maximum value ever to be part of the sample.

func (*UniformSample) Mean added in v1.8.2

func (s *UniformSample) Mean() float64

Mean returns the mean of the values in the sample.

func (*UniformSample) Min added in v1.8.2

func (s *UniformSample) Min() int64

Min returns the minimum value in the sample, which may not be the minimum value ever to be part of the sample.

func (*UniformSample) Percentile added in v1.8.2

func (s *UniformSample) Percentile(p float64) float64

Percentile returns an arbitrary percentile of values in the sample.

func (*UniformSample) Percentiles added in v1.8.2

func (s *UniformSample) Percentiles(ps []float64) []float64

Percentiles returns a slice of arbitrary percentiles of values in the sample.

func (*UniformSample) Size added in v1.8.2

func (s *UniformSample) Size() int

Size returns the size of the sample, which is at most the reservoir size.

func (*UniformSample) Snapshot added in v1.8.2

func (s *UniformSample) Snapshot() Sample

Snapshot returns a read-only copy of the sample.

func (*UniformSample) StdDev added in v1.8.2

func (s *UniformSample) StdDev() float64

StdDev returns the standard deviation of the values in the sample.

func (*UniformSample) Sum added in v1.8.2

func (s *UniformSample) Sum() int64

Sum returns the sum of the values in the sample.

func (*UniformSample) Update added in v1.8.2

func (s *UniformSample) Update(v int64)

Update samples a new value.

func (*UniformSample) Values added in v1.8.2

func (s *UniformSample) Values() []int64

Values returns a copy of the values in the sample.

func (*UniformSample) Variance added in v1.8.2

func (s *UniformSample) Variance() float64

Variance returns the variance of the values in the sample.

Directories

Path Synopsis
Hook go-metrics into expvar on any /debug/metrics request, load all vars from the registry into expvar, and execute regular expvar handler
Hook go-metrics into expvar on any /debug/metrics request, load all vars from the registry into expvar, and execute regular expvar handler
Package prometheus exposes go-metrics into a Prometheus format.
Package prometheus exposes go-metrics into a Prometheus format.

Jump to

Keyboard shortcuts

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