UseNilMetrics 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.
var UseNilMetrics bool = false
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(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(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(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 Each(f func(string, interface{}))
Call the given function for each registered metric.
func Get(name string) interface{}
Get the metric by the given name or nil if none is registered.
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(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
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(c GraphiteConfig)
GraphiteWithConfig is a blocking exporter function just like Graphite, but it takes a GraphiteConfig instead.
▹ Example
func Log(r Registry, freq time.Duration, l Logger)
Log outputs each metric in the given registry periodically using the given logger.
func LogOnCue(r Registry, ch chan interface{}, l Logger)
LogOnCue outputs each metric in the given registry on demand through the channel using the given logger
func LogScaled(r Registry, freq time.Duration, scale time.Duration, l Logger)
LogScaled outputs each metric in the given registry periodically using the given logger. Print timings in `scale` units (eg time.Millisecond) rather than nanos.
func LogScaledOnCue(r Registry, ch chan interface{}, scale time.Duration, l Logger)
LogScaledOnCue outputs each metric in the given registry on demand through the channel using the given logger. Print timings in `scale` units (eg time.Millisecond) rather than nanos.
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(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
func OpenTSDBWithConfig(c OpenTSDBConfig)
OpenTSDBWithConfig is a blocking exporter function just like OpenTSDB, but it takes a OpenTSDBConfig instead.
▹ Example
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(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(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()
Run all registered healthchecks.
func SampleMax(values []int64) int64
SampleMax returns the maximum value of the slice of int64.
func SampleMean(values []int64) float64
SampleMean returns the mean value of the slice of int64.
func SampleMin(values []int64) int64
SampleMin returns the minimum value of the slice of int64.
func SamplePercentile(values int64Slice, p float64) float64
SamplePercentiles returns an arbitrary percentile of the slice of int64.
func SamplePercentiles(values int64Slice, ps []float64) []float64
SamplePercentiles returns a slice of arbitrary percentiles of the slice of int64.
func SampleStdDev(values []int64) float64
SampleStdDev returns the standard deviation of the slice of int64.
func SampleSum(values []int64) int64
SampleSum returns the sum of the slice of int64.
func SampleVariance(values []int64) float64
SampleVariance returns the variance of the slice of int64.
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(name string)
Unregister the metric with the given name.
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(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(r Registry, w io.Writer)
WriteJSONOnce writes metrics from the given registry to the specified io.Writer as JSON.
func WriteOnce(r Registry, w io.Writer)
WriteOnce sorts and writes metrics in the given registry to the given io.Writer.
Counters hold an int64 value that can be incremented and decremented.
type Counter interface { Clear() Count() int64 Dec(int64) Inc(int64) Snapshot() Counter }
func GetOrRegisterCounter(name string, r Registry) Counter
GetOrRegisterCounter returns an existing Counter or constructs and registers a new StandardCounter.
func NewCounter() Counter
NewCounter constructs a new StandardCounter.
func NewRegisteredCounter(name string, r Registry) Counter
NewRegisteredCounter constructs and registers a new StandardCounter.
CounterSnapshot is a read-only copy of another Counter.
type CounterSnapshot int64
func (CounterSnapshot) Clear()
Clear panics.
func (c CounterSnapshot) Count() int64
Count returns the count at the time the snapshot was taken.
func (CounterSnapshot) Dec(int64)
Dec panics.
func (CounterSnapshot) Inc(int64)
Inc panics.
func (c CounterSnapshot) Snapshot() Counter
Snapshot returns the snapshot.
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.
type DuplicateMetric string
func (err DuplicateMetric) Error() string
EWMAs continuously calculate an exponentially-weighted moving average based on an outside source of clock ticks.
type EWMA interface { Rate() float64 Snapshot() EWMA Tick() Update(int64) }
func NewEWMA(alpha float64) EWMA
NewEWMA constructs a new EWMA with the given alpha.
func NewEWMA1() EWMA
NewEWMA1 constructs a new EWMA for a one-minute moving average.
func NewEWMA15() EWMA
NewEWMA15 constructs a new EWMA for a fifteen-minute moving average.
func NewEWMA5() EWMA
NewEWMA5 constructs a new EWMA for a five-minute moving average.
EWMASnapshot is a read-only copy of another EWMA.
type EWMASnapshot float64
func (a EWMASnapshot) Rate() float64
Rate returns the rate of events per second at the time the snapshot was taken.
func (a EWMASnapshot) Snapshot() EWMA
Snapshot returns the snapshot.
func (EWMASnapshot) Tick()
Tick panics.
func (EWMASnapshot) Update(int64)
Update panics.
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>
type ExpDecaySample struct {
// contains filtered or unexported fields
}
func (s *ExpDecaySample) Clear()
Clear clears all samples.
func (s *ExpDecaySample) Count() int64
Count returns the number of samples recorded, which may exceed the reservoir size.
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 (s *ExpDecaySample) Mean() float64
Mean returns the mean of the values in the sample.
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 (s *ExpDecaySample) Percentile(p float64) float64
Percentile returns an arbitrary percentile of values in the sample.
func (s *ExpDecaySample) Percentiles(ps []float64) []float64
Percentiles returns a slice of arbitrary percentiles of values in the sample.
func (s *ExpDecaySample) Size() int
Size returns the size of the sample, which is at most the reservoir size.
func (s *ExpDecaySample) Snapshot() Sample
Snapshot returns a read-only copy of the sample.
func (s *ExpDecaySample) StdDev() float64
StdDev returns the standard deviation of the values in the sample.
func (s *ExpDecaySample) Sum() int64
Sum returns the sum of the values in the sample.
func (s *ExpDecaySample) Update(v int64)
Update samples a new value.
func (s *ExpDecaySample) Values() []int64
Values returns a copy of the values in the sample.
func (s *ExpDecaySample) Variance() float64
Variance returns the variance of the values in the sample.
FunctionalGauge returns value from given function
type FunctionalGauge struct {
// contains filtered or unexported fields
}
func (g FunctionalGauge) Snapshot() Gauge
Snapshot returns the snapshot.
func (FunctionalGauge) Update(int64)
Update panics.
func (g FunctionalGauge) Value() int64
Value returns the gauge's current value.
FunctionalGaugeFloat64 returns value from given function
type FunctionalGaugeFloat64 struct {
// contains filtered or unexported fields
}
func (g FunctionalGaugeFloat64) Snapshot() GaugeFloat64
Snapshot returns the snapshot.
func (FunctionalGaugeFloat64) Update(float64)
Update panics.
func (g FunctionalGaugeFloat64) Value() float64
Value returns the gauge's current value.
Gauges hold an int64 value that can be set arbitrarily.
type Gauge interface { Snapshot() Gauge Update(int64) Value() int64 }
func GetOrRegisterGauge(name string, r Registry) Gauge
GetOrRegisterGauge returns an existing Gauge or constructs and registers a new StandardGauge.
▹ Example
func NewFunctionalGauge(f func() int64) Gauge
NewFunctionalGauge constructs a new FunctionalGauge.
func NewGauge() Gauge
NewGauge constructs a new StandardGauge.
func NewRegisteredFunctionalGauge(name string, r Registry, f func() int64) Gauge
NewRegisteredFunctionalGauge constructs and registers a new StandardGauge.
func NewRegisteredGauge(name string, r Registry) Gauge
NewRegisteredGauge constructs and registers a new StandardGauge.
GaugeFloat64s hold a float64 value that can be set arbitrarily.
type GaugeFloat64 interface { Snapshot() GaugeFloat64 Update(float64) Value() float64 }
func GetOrRegisterGaugeFloat64(name string, r Registry) GaugeFloat64
GetOrRegisterGaugeFloat64 returns an existing GaugeFloat64 or constructs and registers a new StandardGaugeFloat64.
func NewFunctionalGaugeFloat64(f func() float64) GaugeFloat64
NewFunctionalGauge constructs a new FunctionalGauge.
func NewGaugeFloat64() GaugeFloat64
NewGaugeFloat64 constructs a new StandardGaugeFloat64.
func NewRegisteredFunctionalGaugeFloat64(name string, r Registry, f func() float64) GaugeFloat64
NewRegisteredFunctionalGauge constructs and registers a new StandardGauge.
func NewRegisteredGaugeFloat64(name string, r Registry) GaugeFloat64
NewRegisteredGaugeFloat64 constructs and registers a new StandardGaugeFloat64.
GaugeFloat64Snapshot is a read-only copy of another GaugeFloat64.
type GaugeFloat64Snapshot float64
func (g GaugeFloat64Snapshot) Snapshot() GaugeFloat64
Snapshot returns the snapshot.
func (GaugeFloat64Snapshot) Update(float64)
Update panics.
func (g GaugeFloat64Snapshot) Value() float64
Value returns the value at the time the snapshot was taken.
GaugeSnapshot is a read-only copy of another Gauge.
type GaugeSnapshot int64
func (g GaugeSnapshot) Snapshot() Gauge
Snapshot returns the snapshot.
func (GaugeSnapshot) Update(int64)
Update panics.
func (g GaugeSnapshot) Value() int64
Value returns the value at the time the snapshot was taken.
GraphiteConfig provides a container with configuration parameters for the Graphite exporter
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 }
Healthchecks hold an error value describing an arbitrary up/down status.
type Healthcheck interface { Check() Error() error Healthy() Unhealthy(error) }
func NewHealthcheck(f func(Healthcheck)) Healthcheck
NewHealthcheck constructs a new Healthcheck which will use the given function to update its status.
Histograms calculate distribution statistics from a series of int64 values.
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 }
func GetOrRegisterHistogram(name string, r Registry, s Sample) Histogram
GetOrRegisterHistogram returns an existing Histogram or constructs and registers a new StandardHistogram.
func NewHistogram(s Sample) Histogram
NewHistogram constructs a new StandardHistogram from a Sample.
func NewRegisteredHistogram(name string, r Registry, s Sample) Histogram
NewRegisteredHistogram constructs and registers a new StandardHistogram from a Sample.
HistogramSnapshot is a read-only copy of another Histogram.
type HistogramSnapshot struct {
// contains filtered or unexported fields
}
func (*HistogramSnapshot) Clear()
Clear panics.
func (h *HistogramSnapshot) Count() int64
Count returns the number of samples recorded at the time the snapshot was taken.
func (h *HistogramSnapshot) Max() int64
Max returns the maximum value in the sample at the time the snapshot was taken.
func (h *HistogramSnapshot) Mean() float64
Mean returns the mean of the values in the sample at the time the snapshot was taken.
func (h *HistogramSnapshot) Min() int64
Min returns the minimum value in the sample at the time the snapshot was taken.
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 (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 (h *HistogramSnapshot) Sample() Sample
Sample returns the Sample underlying the histogram.
func (h *HistogramSnapshot) Snapshot() Histogram
Snapshot returns the snapshot.
func (h *HistogramSnapshot) StdDev() float64
StdDev returns the standard deviation of the values in the sample at the time the snapshot was taken.
func (h *HistogramSnapshot) Sum() int64
Sum returns the sum in the sample at the time the snapshot was taken.
func (*HistogramSnapshot) Update(int64)
Update panics.
func (h *HistogramSnapshot) Variance() float64
Variance returns the variance of inputs at the time the snapshot was taken.
type Logger interface { Printf(format string, v ...interface{}) }
Meters count events to produce exponentially-weighted moving average rates at one-, five-, and fifteen-minutes and a mean rate.
type Meter interface { Count() int64 Mark(int64) Rate1() float64 Rate5() float64 Rate15() float64 RateMean() float64 Snapshot() Meter Stop() }
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 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 NewRegisteredMeter(name string, r Registry) Meter
NewMeter 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.
MeterSnapshot is a read-only copy of another Meter.
type MeterSnapshot struct {
// contains filtered or unexported fields
}
func (m *MeterSnapshot) Count() int64
Count returns the count of events at the time the snapshot was taken.
func (*MeterSnapshot) Mark(n int64)
Mark panics.
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 (m *MeterSnapshot) Rate15() float64
Rate15 returns the fifteen-minute moving average rate of events per second at the time the snapshot was taken.
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 (m *MeterSnapshot) RateMean() float64
RateMean returns the meter's mean rate of events per second at the time the snapshot was taken.
func (m *MeterSnapshot) Snapshot() Meter
Snapshot returns the snapshot.
func (m *MeterSnapshot) Stop()
Stop is a no-op.
NilCounter is a no-op Counter.
type NilCounter struct{}
func (NilCounter) Clear()
Clear is a no-op.
func (NilCounter) Count() int64
Count is a no-op.
func (NilCounter) Dec(i int64)
Dec is a no-op.
func (NilCounter) Inc(i int64)
Inc is a no-op.
func (NilCounter) Snapshot() Counter
Snapshot is a no-op.
NilEWMA is a no-op EWMA.
type NilEWMA struct{}
func (NilEWMA) Rate() float64
Rate is a no-op.
func (NilEWMA) Snapshot() EWMA
Snapshot is a no-op.
func (NilEWMA) Tick()
Tick is a no-op.
func (NilEWMA) Update(n int64)
Update is a no-op.
NilGauge is a no-op Gauge.
type NilGauge struct{}
func (NilGauge) Snapshot() Gauge
Snapshot is a no-op.
func (NilGauge) Update(v int64)
Update is a no-op.
func (NilGauge) Value() int64
Value is a no-op.
NilGauge is a no-op Gauge.
type NilGaugeFloat64 struct{}
func (NilGaugeFloat64) Snapshot() GaugeFloat64
Snapshot is a no-op.
func (NilGaugeFloat64) Update(v float64)
Update is a no-op.
func (NilGaugeFloat64) Value() float64
Value is a no-op.
NilHealthcheck is a no-op.
type NilHealthcheck struct{}
func (NilHealthcheck) Check()
Check is a no-op.
func (NilHealthcheck) Error() error
Error is a no-op.
func (NilHealthcheck) Healthy()
Healthy is a no-op.
func (NilHealthcheck) Unhealthy(error)
Unhealthy is a no-op.
NilHistogram is a no-op Histogram.
type NilHistogram struct{}
func (NilHistogram) Clear()
Clear is a no-op.
func (NilHistogram) Count() int64
Count is a no-op.
func (NilHistogram) Max() int64
Max is a no-op.
func (NilHistogram) Mean() float64
Mean is a no-op.
func (NilHistogram) Min() int64
Min is a no-op.
func (NilHistogram) Percentile(p float64) float64
Percentile is a no-op.
func (NilHistogram) Percentiles(ps []float64) []float64
Percentiles is a no-op.
func (NilHistogram) Sample() Sample
Sample is a no-op.
func (NilHistogram) Snapshot() Histogram
Snapshot is a no-op.
func (NilHistogram) StdDev() float64
StdDev is a no-op.
func (NilHistogram) Sum() int64
Sum is a no-op.
func (NilHistogram) Update(v int64)
Update is a no-op.
func (NilHistogram) Variance() float64
Variance is a no-op.
NilMeter is a no-op Meter.
type NilMeter struct{}
func (NilMeter) Count() int64
Count is a no-op.
func (NilMeter) Mark(n int64)
Mark is a no-op.
func (NilMeter) Rate1() float64
Rate1 is a no-op.
func (NilMeter) Rate15() float64
Rate15is a no-op.
func (NilMeter) Rate5() float64
Rate5 is a no-op.
func (NilMeter) RateMean() float64
RateMean is a no-op.
func (NilMeter) Snapshot() Meter
Snapshot is a no-op.
func (NilMeter) Stop()
Stop is a no-op.
NilSample is a no-op Sample.
type NilSample struct{}
func (NilSample) Clear()
Clear is a no-op.
func (NilSample) Count() int64
Count is a no-op.
func (NilSample) Max() int64
Max is a no-op.
func (NilSample) Mean() float64
Mean is a no-op.
func (NilSample) Min() int64
Min is a no-op.
func (NilSample) Percentile(p float64) float64
Percentile is a no-op.
func (NilSample) Percentiles(ps []float64) []float64
Percentiles is a no-op.
func (NilSample) Size() int
Size is a no-op.
func (NilSample) Snapshot() Sample
Sample is a no-op.
func (NilSample) StdDev() float64
StdDev is a no-op.
func (NilSample) Sum() int64
Sum is a no-op.
func (NilSample) Update(v int64)
Update is a no-op.
func (NilSample) Values() []int64
Values is a no-op.
func (NilSample) Variance() float64
Variance is a no-op.
NilTimer is a no-op Timer.
type NilTimer struct {
// contains filtered or unexported fields
}
func (NilTimer) Count() int64
Count is a no-op.
func (NilTimer) Max() int64
Max is a no-op.
func (NilTimer) Mean() float64
Mean is a no-op.
func (NilTimer) Min() int64
Min is a no-op.
func (NilTimer) Percentile(p float64) float64
Percentile is a no-op.
func (NilTimer) Percentiles(ps []float64) []float64
Percentiles is a no-op.
func (NilTimer) Rate1() float64
Rate1 is a no-op.
func (NilTimer) Rate15() float64
Rate15 is a no-op.
func (NilTimer) Rate5() float64
Rate5 is a no-op.
func (NilTimer) RateMean() float64
RateMean is a no-op.
func (NilTimer) Snapshot() Timer
Snapshot is a no-op.
func (NilTimer) StdDev() float64
StdDev is a no-op.
func (NilTimer) Stop()
Stop is a no-op.
func (NilTimer) Sum() int64
Sum is a no-op.
func (NilTimer) Time(func())
Time is a no-op.
func (NilTimer) Update(time.Duration)
Update is a no-op.
func (NilTimer) UpdateSince(time.Time)
UpdateSince is a no-op.
func (NilTimer) Variance() float64
Variance is a no-op.
OpenTSDBConfig provides a container with configuration parameters for the OpenTSDB exporter
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 }
type PrefixedRegistry struct {
// contains filtered or unexported fields
}
func (r *PrefixedRegistry) Each(fn func(string, interface{}))
Call the given function for each registered metric.
func (r *PrefixedRegistry) Get(name string) interface{}
Get the metric by the given name or nil if none is registered.
func (r *PrefixedRegistry) GetAll() map[string]map[string]interface{}
GetAll metrics in the Registry
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 (p *PrefixedRegistry) MarshalJSON() ([]byte, error)
func (r *PrefixedRegistry) Register(name string, metric interface{}) error
Register the given metric under the given name. The name will be prefixed.
func (r *PrefixedRegistry) RunHealthchecks()
Run all registered healthchecks.
func (r *PrefixedRegistry) Unregister(name string)
Unregister the metric with the given name. The name will be prefixed.
func (r *PrefixedRegistry) UnregisterAll()
Unregister all metrics. (Mostly for testing.)
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.
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() }
var DefaultRegistry Registry = NewRegistry()
func NewPrefixedChildRegistry(parent Registry, prefix string) Registry
func NewPrefixedRegistry(prefix string) Registry
func NewRegistry() Registry
Create a new registry.
Samples maintain a statistically-significant selection of values from a stream.
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 }
func NewExpDecaySample(reservoirSize int, alpha float64) Sample
NewExpDecaySample constructs a new exponentially-decaying sample with the given reservoir size and alpha.
func NewUniformSample(reservoirSize int) Sample
NewUniformSample constructs a new uniform sample with the given reservoir size.
SampleSnapshot is a read-only copy of another Sample.
type SampleSnapshot struct {
// contains filtered or unexported fields
}
func NewSampleSnapshot(count int64, values []int64) *SampleSnapshot
func (*SampleSnapshot) Clear()
Clear panics.
func (s *SampleSnapshot) Count() int64
Count returns the count of inputs at the time the snapshot was taken.
func (s *SampleSnapshot) Max() int64
Max returns the maximal value at the time the snapshot was taken.
func (s *SampleSnapshot) Mean() float64
Mean returns the mean value at the time the snapshot was taken.
func (s *SampleSnapshot) Min() int64
Min returns the minimal value at the time the snapshot was taken.
func (s *SampleSnapshot) Percentile(p float64) float64
Percentile returns an arbitrary percentile of values at the time the snapshot was taken.
func (s *SampleSnapshot) Percentiles(ps []float64) []float64
Percentiles returns a slice of arbitrary percentiles of values at the time the snapshot was taken.
func (s *SampleSnapshot) Size() int
Size returns the size of the sample at the time the snapshot was taken.
func (s *SampleSnapshot) Snapshot() Sample
Snapshot returns the snapshot.
func (s *SampleSnapshot) StdDev() float64
StdDev returns the standard deviation of values at the time the snapshot was taken.
func (s *SampleSnapshot) Sum() int64
Sum returns the sum of values at the time the snapshot was taken.
func (*SampleSnapshot) Update(int64)
Update panics.
func (s *SampleSnapshot) Values() []int64
Values returns a copy of the values in the sample.
func (s *SampleSnapshot) Variance() float64
Variance returns the variance of values at the time the snapshot was taken.
StandardCounter is the standard implementation of a Counter and uses the sync/atomic package to manage a single int64 value.
type StandardCounter struct {
// contains filtered or unexported fields
}
func (c *StandardCounter) Clear()
Clear sets the counter to zero.
func (c *StandardCounter) Count() int64
Count returns the current count.
func (c *StandardCounter) Dec(i int64)
Dec decrements the counter by the given amount.
func (c *StandardCounter) Inc(i int64)
Inc increments the counter by the given amount.
func (c *StandardCounter) Snapshot() Counter
Snapshot returns a read-only copy of the counter.
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.
type StandardEWMA struct {
// contains filtered or unexported fields
}
func (a *StandardEWMA) Rate() float64
Rate returns the moving average rate of events per second.
func (a *StandardEWMA) Snapshot() EWMA
Snapshot returns a read-only copy of the EWMA.
func (a *StandardEWMA) Tick()
Tick ticks the clock to update the moving average. It assumes it is called every five seconds.
func (a *StandardEWMA) Update(n int64)
Update adds n uncounted events.
StandardGauge is the standard implementation of a Gauge and uses the sync/atomic package to manage a single int64 value.
type StandardGauge struct {
// contains filtered or unexported fields
}
func (g *StandardGauge) Snapshot() Gauge
Snapshot returns a read-only copy of the gauge.
func (g *StandardGauge) Update(v int64)
Update updates the gauge's value.
func (g *StandardGauge) Value() int64
Value returns the gauge's current value.
StandardGaugeFloat64 is the standard implementation of a GaugeFloat64 and uses sync.Mutex to manage a single float64 value.
type StandardGaugeFloat64 struct {
// contains filtered or unexported fields
}
func (g *StandardGaugeFloat64) Snapshot() GaugeFloat64
Snapshot returns a read-only copy of the gauge.
func (g *StandardGaugeFloat64) Update(v float64)
Update updates the gauge's value.
func (g *StandardGaugeFloat64) Value() float64
Value returns the gauge's current value.
StandardHealthcheck is the standard implementation of a Healthcheck and stores the status and a function to call to update the status.
type StandardHealthcheck struct {
// contains filtered or unexported fields
}
func (h *StandardHealthcheck) Check()
Check runs the healthcheck function to update the healthcheck's status.
func (h *StandardHealthcheck) Error() error
Error returns the healthcheck's status, which will be nil if it is healthy.
func (h *StandardHealthcheck) Healthy()
Healthy marks the healthcheck as healthy.
func (h *StandardHealthcheck) Unhealthy(err error)
Unhealthy marks the healthcheck as unhealthy. The error is stored and may be retrieved by the Error method.
StandardHistogram is the standard implementation of a Histogram and uses a Sample to bound its memory use.
type StandardHistogram struct {
// contains filtered or unexported fields
}
func (h *StandardHistogram) Clear()
Clear clears the histogram and its sample.
func (h *StandardHistogram) Count() int64
Count returns the number of samples recorded since the histogram was last cleared.
func (h *StandardHistogram) Max() int64
Max returns the maximum value in the sample.
func (h *StandardHistogram) Mean() float64
Mean returns the mean of the values in the sample.
func (h *StandardHistogram) Min() int64
Min returns the minimum value in the sample.
func (h *StandardHistogram) Percentile(p float64) float64
Percentile returns an arbitrary percentile of the values in the sample.
func (h *StandardHistogram) Percentiles(ps []float64) []float64
Percentiles returns a slice of arbitrary percentiles of the values in the sample.
func (h *StandardHistogram) Sample() Sample
Sample returns the Sample underlying the histogram.
func (h *StandardHistogram) Snapshot() Histogram
Snapshot returns a read-only copy of the histogram.
func (h *StandardHistogram) StdDev() float64
StdDev returns the standard deviation of the values in the sample.
func (h *StandardHistogram) Sum() int64
Sum returns the sum in the sample.
func (h *StandardHistogram) Update(v int64)
Update samples a new value.
func (h *StandardHistogram) Variance() float64
Variance returns the variance of the values in the sample.
StandardMeter is the standard implementation of a Meter.
type StandardMeter struct {
// contains filtered or unexported fields
}
func (m *StandardMeter) Count() int64
Count returns the number of events recorded.
func (m *StandardMeter) Mark(n int64)
Mark records the occurance of n events.
func (m *StandardMeter) Rate1() float64
Rate1 returns the one-minute moving average rate of events per second.
func (m *StandardMeter) Rate15() float64
Rate15 returns the fifteen-minute moving average rate of events per second.
func (m *StandardMeter) Rate5() float64
Rate5 returns the five-minute moving average rate of events per second.
func (m *StandardMeter) RateMean() float64
RateMean returns the meter's mean rate of events per second.
func (m *StandardMeter) Snapshot() Meter
Snapshot returns a read-only copy of the meter.
func (m *StandardMeter) Stop()
Stop stops the meter, Mark() will be a no-op if you use it after being stopped.
The standard implementation of a Registry is a mutex-protected map of names to metrics.
type StandardRegistry struct {
// contains filtered or unexported fields
}
func (r *StandardRegistry) Each(f func(string, interface{}))
Call the given function for each registered metric.
func (r *StandardRegistry) Get(name string) interface{}
Get the metric by the given name or nil if none is registered.
func (r *StandardRegistry) GetAll() map[string]map[string]interface{}
GetAll metrics in the Registry
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 (r *StandardRegistry) MarshalJSON() ([]byte, error)
MarshalJSON returns a byte slice containing a JSON representation of all the metrics in the Registry.
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 (r *StandardRegistry) RunHealthchecks()
Run all registered healthchecks.
func (r *StandardRegistry) Unregister(name string)
Unregister the metric with the given name.
func (r *StandardRegistry) UnregisterAll()
Unregister all metrics. (Mostly for testing.)
StandardTimer is the standard implementation of a Timer and uses a Histogram and Meter.
type StandardTimer struct {
// contains filtered or unexported fields
}
func (t *StandardTimer) Count() int64
Count returns the number of events recorded.
func (t *StandardTimer) Max() int64
Max returns the maximum value in the sample.
func (t *StandardTimer) Mean() float64
Mean returns the mean of the values in the sample.
func (t *StandardTimer) Min() int64
Min returns the minimum value in the sample.
func (t *StandardTimer) Percentile(p float64) float64
Percentile returns an arbitrary percentile of the values in the sample.
func (t *StandardTimer) Percentiles(ps []float64) []float64
Percentiles returns a slice of arbitrary percentiles of the values in the sample.
func (t *StandardTimer) Rate1() float64
Rate1 returns the one-minute moving average rate of events per second.
func (t *StandardTimer) Rate15() float64
Rate15 returns the fifteen-minute moving average rate of events per second.
func (t *StandardTimer) Rate5() float64
Rate5 returns the five-minute moving average rate of events per second.
func (t *StandardTimer) RateMean() float64
RateMean returns the meter's mean rate of events per second.
func (t *StandardTimer) Snapshot() Timer
Snapshot returns a read-only copy of the timer.
func (t *StandardTimer) StdDev() float64
StdDev returns the standard deviation of the values in the sample.
func (t *StandardTimer) Stop()
Stop stops the meter.
func (t *StandardTimer) Sum() int64
Sum returns the sum in the sample.
func (t *StandardTimer) Time(f func())
Record the duration of the execution of the given function.
func (t *StandardTimer) Update(d time.Duration)
Record the duration of an event.
func (t *StandardTimer) UpdateSince(ts time.Time)
Record the duration of an event that started at a time and ends now.
func (t *StandardTimer) Variance() float64
Variance returns the variance of the values in the sample.
Stoppable defines the metrics which has to be stopped.
type Stoppable interface { Stop() }
Timers capture the duration and rate of events.
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 }
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
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(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() 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.
TimerSnapshot is a read-only copy of another Timer.
type TimerSnapshot struct {
// contains filtered or unexported fields
}
func (t *TimerSnapshot) Count() int64
Count returns the number of events recorded at the time the snapshot was taken.
func (t *TimerSnapshot) Max() int64
Max returns the maximum value at the time the snapshot was taken.
func (t *TimerSnapshot) Mean() float64
Mean returns the mean value at the time the snapshot was taken.
func (t *TimerSnapshot) Min() int64
Min returns the minimum value at the time the snapshot was taken.
func (t *TimerSnapshot) Percentile(p float64) float64
Percentile returns an arbitrary percentile of sampled values at the time the snapshot was taken.
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 (t *TimerSnapshot) Rate1() float64
Rate1 returns the one-minute moving average rate of events per second at the time the snapshot was taken.
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 (t *TimerSnapshot) Rate5() float64
Rate5 returns the five-minute moving average rate of events per second at the time the snapshot was taken.
func (t *TimerSnapshot) RateMean() float64
RateMean returns the meter's mean rate of events per second at the time the snapshot was taken.
func (t *TimerSnapshot) Snapshot() Timer
Snapshot returns the snapshot.
func (t *TimerSnapshot) StdDev() float64
StdDev returns the standard deviation of the values at the time the snapshot was taken.
func (t *TimerSnapshot) Stop()
Stop is a no-op.
func (t *TimerSnapshot) Sum() int64
Sum returns the sum at the time the snapshot was taken.
func (*TimerSnapshot) Time(func())
Time panics.
func (*TimerSnapshot) Update(time.Duration)
Update panics.
func (*TimerSnapshot) UpdateSince(time.Time)
UpdateSince panics.
func (t *TimerSnapshot) Variance() float64
Variance returns the variance of the values at the time the snapshot was taken.
A uniform sample using Vitter's Algorithm R.
<http://www.cs.umd.edu/~samir/498/vitter.pdf>
type UniformSample struct {
// contains filtered or unexported fields
}
func (s *UniformSample) Clear()
Clear clears all samples.
func (s *UniformSample) Count() int64
Count returns the number of samples recorded, which may exceed the reservoir size.
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 (s *UniformSample) Mean() float64
Mean returns the mean of the values in the sample.
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 (s *UniformSample) Percentile(p float64) float64
Percentile returns an arbitrary percentile of values in the sample.
func (s *UniformSample) Percentiles(ps []float64) []float64
Percentiles returns a slice of arbitrary percentiles of values in the sample.
func (s *UniformSample) Size() int
Size returns the size of the sample, which is at most the reservoir size.
func (s *UniformSample) Snapshot() Sample
Snapshot returns a read-only copy of the sample.
func (s *UniformSample) StdDev() float64
StdDev returns the standard deviation of the values in the sample.
func (s *UniformSample) Sum() int64
Sum returns the sum of the values in the sample.
func (s *UniformSample) Update(v int64)
Update samples a new value.
func (s *UniformSample) Values() []int64
Values returns a copy of the values in the sample.
func (s *UniformSample) Variance() float64
Variance returns the variance of the values in the sample.
Name | Synopsis |
---|---|
.. | |
cmd | |
metrics-bench | |
metrics-example | |
never-read | |
exp | Hook go-metrics into expvar on any /debug/metrics request, load all vars from the registry into expvar, and execute regular expvar handler |
librato | |
stathat | Metrics output to StatHat. |