metrics

package
v0.0.0-...-92d349b Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: GPL-3.0, BSD-2-Clause-Views Imports: 9 Imported by: 0

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>

Index

Constants

This section is empty.

Variables

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

Functions

func Get

func Get(name string) interface{}

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

Types

type Counter

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

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

type DuplicateMetric

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

func (err DuplicateMetric) Error() string

type EWMA

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

func NewEWMA(alpha float64) EWMA

NewEWMA constructs a new EWMA with the given alpha.

func NewEWMA1

func NewEWMA1() EWMA

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

func NewEWMA15

func NewEWMA15() EWMA

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

func NewEWMA5

func NewEWMA5() EWMA

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

type EWMASnapshot

type EWMASnapshot float64

EWMASnapshot is a read-only copy of another EWMA.

func (EWMASnapshot) Rate

func (a EWMASnapshot) Rate() float64

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

func (EWMASnapshot) Snapshot

func (a EWMASnapshot) Snapshot() EWMA

Snapshot returns the snapshot.

func (EWMASnapshot) Tick

func (EWMASnapshot) Tick()

Tick panics.

func (EWMASnapshot) Update

func (EWMASnapshot) Update(int64)

Update panics.

type Gauge

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

Gauges hold an int64 value that can be set arbitrarily.

type GaugeFloat64

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

GaugeFloat64s hold a float64 value that can be set arbitrarily.

type Healthcheck

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

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

type Histogram

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.

type Meter

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 NewMeterForced

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.

type MeterSnapshot

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

MeterSnapshot is a read-only copy of another Meter.

func (*MeterSnapshot) Count

func (m *MeterSnapshot) Count() int64

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

func (*MeterSnapshot) Mark

func (*MeterSnapshot) Mark(n int64)

Mark panics.

func (*MeterSnapshot) Rate1

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

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

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

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

func (m *MeterSnapshot) Snapshot() Meter

Snapshot returns the snapshot.

func (*MeterSnapshot) Stop

func (m *MeterSnapshot) Stop()

Stop is a no-op.

type NilEWMA

type NilEWMA struct{}

NilEWMA is a no-op EWMA.

func (NilEWMA) Rate

func (NilEWMA) Rate() float64

Rate is a no-op.

func (NilEWMA) Snapshot

func (NilEWMA) Snapshot() EWMA

Snapshot is a no-op.

func (NilEWMA) Tick

func (NilEWMA) Tick()

Tick is a no-op.

func (NilEWMA) Update

func (NilEWMA) Update(n int64)

Update is a no-op.

type NilMeter

type NilMeter struct{}

NilMeter is a no-op Meter.

func (NilMeter) Count

func (NilMeter) Count() int64

Count is a no-op.

func (NilMeter) Mark

func (NilMeter) Mark(n int64)

Mark is a no-op.

func (NilMeter) Rate1

func (NilMeter) Rate1() float64

Rate1 is a no-op.

func (NilMeter) Rate15

func (NilMeter) Rate15() float64

Rate15 is a no-op.

func (NilMeter) Rate5

func (NilMeter) Rate5() float64

Rate5 is a no-op.

func (NilMeter) RateMean

func (NilMeter) RateMean() float64

RateMean is a no-op.

func (NilMeter) Snapshot

func (NilMeter) Snapshot() Meter

Snapshot is a no-op.

func (NilMeter) Stop

func (NilMeter) Stop()

Stop is a no-op.

type Registry

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 NewRegistry

func NewRegistry() Registry

Create a new registry.

type ResettingTimer

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.

type Sample

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.

type StandardEWMA

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

func (a *StandardEWMA) Rate() float64

Rate returns the moving average rate of events per second.

func (*StandardEWMA) Snapshot

func (a *StandardEWMA) Snapshot() EWMA

Snapshot returns a read-only copy of the EWMA.

func (*StandardEWMA) Tick

func (a *StandardEWMA) Tick()

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

func (*StandardEWMA) Update

func (a *StandardEWMA) Update(n int64)

Update adds n uncounted events.

type StandardMeter

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

StandardMeter is the standard implementation of a Meter.

func (*StandardMeter) Count

func (m *StandardMeter) Count() int64

Count returns the number of events recorded. It updates the meter to be as accurate as possible

func (*StandardMeter) Mark

func (m *StandardMeter) Mark(n int64)

Mark records the occurrence of n events.

func (*StandardMeter) Rate1

func (m *StandardMeter) Rate1() float64

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

func (*StandardMeter) Rate15

func (m *StandardMeter) Rate15() float64

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

func (*StandardMeter) Rate5

func (m *StandardMeter) Rate5() float64

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

func (*StandardMeter) RateMean

func (m *StandardMeter) RateMean() float64

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

func (*StandardMeter) Snapshot

func (m *StandardMeter) Snapshot() Meter

Snapshot returns a read-only copy of the meter.

func (*StandardMeter) Stop

func (m *StandardMeter) Stop()

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

type StandardRegistry

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

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

Call the given function for each registered metric.

func (*StandardRegistry) Get

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

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

func (*StandardRegistry) GetAll

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

GetAll metrics in the Registry

func (*StandardRegistry) GetOrRegister

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

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

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

func (r *StandardRegistry) RunHealthchecks()

Run all registered healthchecks.

func (*StandardRegistry) Unregister

func (r *StandardRegistry) Unregister(name string)

Unregister the metric with the given name.

func (*StandardRegistry) UnregisterAll

func (r *StandardRegistry) UnregisterAll()

Unregister all metrics. (Mostly for testing.)

type Stoppable

type Stoppable interface {
	Stop()
}

Stoppable defines the metrics which has to be stopped.

type Timer

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.

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

Jump to

Keyboard shortcuts

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