metrics

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSample

func NewSample(c *Config) *_Sample

NewSample initializes a new metric sample.

Types

type Config

type Config struct {
	Size int
}

Config sample config

type Counter

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

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

func GetOrRegisterCounter

func GetOrRegisterCounter(name string, r Metrics) Counter

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

func NewCounter

func NewCounter() Counter

NewCounter constructs a new StandardCounter.

type CounterSnapshot

type CounterSnapshot int64

CounterSnapshot is a read-only copy of another Counter.

func (CounterSnapshot) Count

func (c CounterSnapshot) Count() int64

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

func (CounterSnapshot) Dec

func (CounterSnapshot) Dec(int64)

Dec panics.

func (CounterSnapshot) Inc

func (CounterSnapshot) Inc(int64)

Inc panics.

func (CounterSnapshot) Reset

func (CounterSnapshot) Reset()

Reset reset clear panics.

func (CounterSnapshot) Snapshot

func (c CounterSnapshot) Snapshot() Counter

Snapshot returns the snapshot.

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 Gauge

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

Gauge hold an int64 value that can be set arbitrarily.

func GetOrRegisterGauge

func GetOrRegisterGauge(name string, r Metrics) Gauge

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

func NewGauge

func NewGauge() Gauge

NewGauge constructs a new StandardGauge.

type GaugeSnapshot

type GaugeSnapshot int64

GaugeSnapshot is a read-only copy of another Gauge.

func (GaugeSnapshot) Snapshot

func (g GaugeSnapshot) Snapshot() Gauge

Snapshot returns the snapshot.

func (GaugeSnapshot) Update

func (GaugeSnapshot) Update(int64)

Update panics.

func (GaugeSnapshot) Value

func (g GaugeSnapshot) Value() int64

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

type Histogram

type Histogram interface {
	Reset()
	Cumulative() time.Duration // Cumulative time of all sampled events.
	HMean() time.Duration      // Event duration harmonic mean.
	Avg() time.Duration        // Event duration average.
	P50() time.Duration        // Event duration nth percentiles ..
	P75() time.Duration
	P95() time.Duration
	P99() time.Duration
	P999() time.Duration
	Long5p() time.Duration  // Average of the longest 5% event durations.
	Short5p() time.Duration // Average of the shortest 5% event durations.
	Max() time.Duration     // Highest event duration.
	Min() time.Duration     // Lowest event duration.
	StdDev() time.Duration  // Standard deviation.
	Range() time.Duration   // Event duration range (Max-Min).
	AddTime(time.Duration)
	SetWallTime(time.Duration)
	Snapshot() Histogram
}

Histogram calculate distribution statistics from a series of int64 values.

func GetOrRegisterHistogram

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

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

func NewHistogram

func NewHistogram(s Sample) Histogram

NewHistogram constructs a new StandardHistogram from a Sample.

type HistogramSnapshot

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

HistogramSnapshot is a read-only copy of another Histogram.

func (*HistogramSnapshot) AddTime

func (h *HistogramSnapshot) AddTime(t time.Duration)

AddTime panics

func (*HistogramSnapshot) Avg

func (h *HistogramSnapshot) Avg() time.Duration

Avg returns average of number of events recorded.

func (*HistogramSnapshot) Cumulative

func (h *HistogramSnapshot) Cumulative() time.Duration

Cumulative returns cumulative time of all sampled events.

func (*HistogramSnapshot) HMean

func (h *HistogramSnapshot) HMean() time.Duration

HMean returns event duration harmonic mean.

func (*HistogramSnapshot) Long5p

func (h *HistogramSnapshot) Long5p() time.Duration

Long5p returns average of the longest 5% event durations.

func (*HistogramSnapshot) Max

func (h *HistogramSnapshot) Max() time.Duration

Max returns highest event duration.

func (*HistogramSnapshot) Min

func (h *HistogramSnapshot) Min() time.Duration

Min returns lowest event duration.

func (*HistogramSnapshot) P50

func (h *HistogramSnapshot) P50() time.Duration

P50 returns event duration nth percentiles.

func (*HistogramSnapshot) P75

func (h *HistogramSnapshot) P75() time.Duration

P75 returns event duration nth percentiles.

func (*HistogramSnapshot) P95

func (h *HistogramSnapshot) P95() time.Duration

P95 returns event duration nth percentiles.

func (*HistogramSnapshot) P99

func (h *HistogramSnapshot) P99() time.Duration

P99 returns event duration nth percentiles.

func (*HistogramSnapshot) P999

func (h *HistogramSnapshot) P999() time.Duration

P999 returns event duration nth percentiles.

func (*HistogramSnapshot) Range

func (h *HistogramSnapshot) Range() time.Duration

Range range returns event duration range (Max-Min).

func (*HistogramSnapshot) Reset

func (h *HistogramSnapshot) Reset()

Reset clears the histogram and its sample.

func (*HistogramSnapshot) SetWallTime

func (h *HistogramSnapshot) SetWallTime(t time.Duration)

SetWallTime panics

func (*HistogramSnapshot) Short5p

func (h *HistogramSnapshot) Short5p() time.Duration

Short5p returns average of the shortest 5% event durations.

func (*HistogramSnapshot) Snapshot

func (h *HistogramSnapshot) Snapshot() Histogram

Snapshot returns the snapshot.

func (*HistogramSnapshot) StdDev

func (h *HistogramSnapshot) StdDev() time.Duration

StdDev returns standard deviation.

type Metrics

type Metrics 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{}

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

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

Metrics A Metrics holds registry 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 Metrics API as appropriate.

func NewMetrics

func NewMetrics() Metrics

NewMetrics new metrics create a new registry.

type Sample

type Sample interface {
	Reset()
	// Count() uint64
	Cumulative() time.Duration // Cumulative time of all sampled events.
	HMean() time.Duration      // Event duration harmonic mean.
	Avg() time.Duration        // Event duration average.
	P50() time.Duration        // Event duration nth percentiles.
	P75() time.Duration
	P95() time.Duration
	P99() time.Duration
	P999() time.Duration
	Long5p() time.Duration  // Average of the longest 5% event durations.
	Short5p() time.Duration // Average of the shortest 5% event durations.
	Max() time.Duration     // Highest event duration.
	Min() time.Duration     // Lowest event duration.
	StdDev() time.Duration  // Standard deviation.
	Range() time.Duration   // Event duration range (Max-Min).
	AddTime(time.Duration)
	SetWallTime(time.Duration)
	Snapshot() Sample
}

Sample a stream.

type SampleSnapshot

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

SampleSnapshot is a read-only copy of another Sample.

func NewSampleSnapshot

func NewSampleSnapshot(count uint64, samples int) *SampleSnapshot

NewSampleSnapshot returns a read-only copy of the sample.

func (*SampleSnapshot) AddTime

func (*SampleSnapshot) AddTime(time.Duration)

AddTime panics.

func (*SampleSnapshot) Avg

func (s *SampleSnapshot) Avg() time.Duration

Avg returns average of number of events recorded.

func (*SampleSnapshot) Cumulative

func (s *SampleSnapshot) Cumulative() time.Duration

Cumulative returns cumulative time of all sampled events.

func (*SampleSnapshot) HMean

func (s *SampleSnapshot) HMean() time.Duration

HMean returns event duration harmonic mean.

func (*SampleSnapshot) Long5p

func (s *SampleSnapshot) Long5p() time.Duration

Long5p returns average of the longest 5% event durations.

func (*SampleSnapshot) Max

func (s *SampleSnapshot) Max() time.Duration

Max returns highest event duration.

func (*SampleSnapshot) Min

func (s *SampleSnapshot) Min() time.Duration

Min returns lowest event duration.

func (*SampleSnapshot) P50

func (s *SampleSnapshot) P50() time.Duration

P50 returns event duration nth percentiles.

func (*SampleSnapshot) P75

func (s *SampleSnapshot) P75() time.Duration

P75 returns event duration nth percentiles.

func (*SampleSnapshot) P95

func (s *SampleSnapshot) P95() time.Duration

P95 returns event duration nth percentiles.

func (*SampleSnapshot) P99

func (s *SampleSnapshot) P99() time.Duration

P99 returns event duration nth percentiles.

func (*SampleSnapshot) P999

func (s *SampleSnapshot) P999() time.Duration

P999 returns event duration nth percentiles.

func (*SampleSnapshot) Range

func (s *SampleSnapshot) Range() time.Duration

Range returns event duration range (Max-Min).

func (*SampleSnapshot) Reset

func (*SampleSnapshot) Reset()

Reset panics.

func (*SampleSnapshot) SetWallTime

func (*SampleSnapshot) SetWallTime(time.Duration)

SetWallTime panics.

func (*SampleSnapshot) Short5p

func (s *SampleSnapshot) Short5p() time.Duration

Short5p returns average of the shortest 5% event durations.

func (*SampleSnapshot) Snapshot

func (s *SampleSnapshot) Snapshot() Sample

Snapshot returns the snapshot.

func (*SampleSnapshot) StdDev

func (s *SampleSnapshot) StdDev() time.Duration

StdDev returns standard deviation.

type StandardMetrics

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

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

func (*StandardMetrics) GetOrRegister

func (m *StandardMetrics) GetOrRegister(name string, i interface{}) interface{}

GetOrRegister 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 (*StandardMetrics) Unregister

func (m *StandardMetrics) Unregister(name string)

Unregister the metric with the given name.

func (*StandardMetrics) UnregisterAll

func (m *StandardMetrics) UnregisterAll()

UnregisterAll unregisters all metrics. (Mostly for testing.)

type Stoppable

type Stoppable interface {
	Stop()
}

Stoppable defines the metrics which has to be stopped.

type TimeSeries

type TimeSeries interface {
	Cumulative() time.Duration // Cumulative time of all sampled events.
	HMean() time.Duration      // Event duration harmonic mean.
	Avg() time.Duration        // Event duration average.
	P50() time.Duration        // Event duration nth percentiles.
	P75() time.Duration
	P95() time.Duration
	P99() time.Duration
	P999() time.Duration
	Long5p() time.Duration  // Average of the longest 5% event durations.
	Short5p() time.Duration // Average of the shortest 5% event durations.
	Max() time.Duration     // Highest event duration.
	Min() time.Duration     // Lowest event duration.
	StdDev() time.Duration  // Standard deviation.
	Range() time.Duration   // Event duration range (Max-Min).
	Time(func())
	AddTime(time.Duration)
	SetWallTime(time.Duration)
	Snapshot() TimeSeries
}

TimeSeries capture the duration and rate of events.

func GetOrRegisterTimeSeries

func GetOrRegisterTimeSeries(name string, r Metrics) TimeSeries

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

func NewTimeSeries

func NewTimeSeries() TimeSeries

NewTimeSeries constructs a new StandardTimeSeries 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 TimeSeriesSnapshot

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

TimeSeriesSnapshot is a read-only copy of another Timer.

func (*TimeSeriesSnapshot) AddTime

func (*TimeSeriesSnapshot) AddTime(time.Duration)

AddTime panics.

func (*TimeSeriesSnapshot) Avg

func (t *TimeSeriesSnapshot) Avg() time.Duration

Avg returns average of number of events recorded.

func (*TimeSeriesSnapshot) Cumulative

func (t *TimeSeriesSnapshot) Cumulative() time.Duration

Cumulative returns cumulative time of all sampled events.

func (*TimeSeriesSnapshot) HMean

func (t *TimeSeriesSnapshot) HMean() time.Duration

HMean returns event duration harmonic mean.

func (*TimeSeriesSnapshot) Long5p

func (t *TimeSeriesSnapshot) Long5p() time.Duration

Long5p returns average of the longest 5% event durations.

func (*TimeSeriesSnapshot) Max

func (t *TimeSeriesSnapshot) Max() time.Duration

Max returns highest event duration.

func (*TimeSeriesSnapshot) Min

func (t *TimeSeriesSnapshot) Min() time.Duration

Min returns lowest event duration.

func (*TimeSeriesSnapshot) P50

func (t *TimeSeriesSnapshot) P50() time.Duration

P50 returns event duration nth percentiles.

func (*TimeSeriesSnapshot) P75

func (t *TimeSeriesSnapshot) P75() time.Duration

P75 returns event duration nth percentiles.

func (*TimeSeriesSnapshot) P95

func (t *TimeSeriesSnapshot) P95() time.Duration

P95 returns event duration nth percentiles.

func (*TimeSeriesSnapshot) P99

func (t *TimeSeriesSnapshot) P99() time.Duration

P99 returns event duration nth percentiles.

func (*TimeSeriesSnapshot) P999

func (t *TimeSeriesSnapshot) P999() time.Duration

P999 returns event duration nth percentiles.

func (*TimeSeriesSnapshot) Range

func (t *TimeSeriesSnapshot) Range() time.Duration

Range returns event duration range (Max-Min).

func (*TimeSeriesSnapshot) SetWallTime

func (*TimeSeriesSnapshot) SetWallTime(time.Duration)

SetWallTime panics.

func (*TimeSeriesSnapshot) Short5p

func (t *TimeSeriesSnapshot) Short5p() time.Duration

Short5p returns average of the shortest 5% event durations.

func (*TimeSeriesSnapshot) Snapshot

func (t *TimeSeriesSnapshot) Snapshot() TimeSeries

Snapshot returns the snapshot.

func (*TimeSeriesSnapshot) StdDev

func (t *TimeSeriesSnapshot) StdDev() time.Duration

StdDev returns standard deviation.

func (*TimeSeriesSnapshot) Time

func (*TimeSeriesSnapshot) Time(func())

Time panics.

Jump to

Keyboard shortcuts

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