Documentation ¶
Overview ¶
Package metrics provides functions for collecting and managing metrics through different metrics libraries.
Metrics library implementations must implement the Registry interface in the package.
Index ¶
Constants ¶
const DefaultNames = "{{clean .Service}}.{{clean .Host}}.{{clean .Path}}.{{clean .TargetURL.Host}}"
DefaultNames contains the default template for route metric names.
const DefaultPrefix = "{{clean .Hostname}}.{{clean .Exec}}"
DefaulPrefix contains the default template for metrics prefix.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Counter ¶ added in v1.3.1
type Counter interface { // Inc increases the counter value by 'n'. Inc(n int64) }
Counter defines a metric for counting events.
type NoopCounter ¶ added in v1.3.1
type NoopCounter struct{}
NoopCounter is a stub implementation of the Counter interface.
func (NoopCounter) Inc ¶ added in v1.3.1
func (c NoopCounter) Inc(n int64)
type NoopRegistry ¶ added in v1.3.1
type NoopRegistry struct{}
NoopRegistry is a stub implementation of the Registry interface.
func (NoopRegistry) GetCounter ¶ added in v1.3.1
func (p NoopRegistry) GetCounter(name string) Counter
func (NoopRegistry) GetTimer ¶ added in v1.3.1
func (p NoopRegistry) GetTimer(name string) Timer
func (NoopRegistry) Names ¶ added in v1.3.1
func (p NoopRegistry) Names() []string
func (NoopRegistry) Unregister ¶ added in v1.3.1
func (p NoopRegistry) Unregister(name string)
func (NoopRegistry) UnregisterAll ¶ added in v1.3.1
func (p NoopRegistry) UnregisterAll()
type NoopTimer ¶ added in v1.3.1
type NoopTimer struct{}
NoopTimer is a stub implementation of the Timer interface.
func (NoopTimer) Percentile ¶ added in v1.3.1
func (NoopTimer) UpdateSince ¶ added in v1.3.1
type Registry ¶ added in v1.3.1
type Registry interface { // Names returns the list of registered metrics acquired // through the GetXXX() functions. It should return them // sorted in alphabetical order. Names() []string // Unregister removes the registered metric and stops // reporting it to an external backend. Unregister(name string) // UnregisterAll removes all registered metrics and stops // reporting them to an external backend. UnregisterAll() // GetCounter returns a counter metric for the given name. // If the metric does not exist yet it should be created // otherwise the existing metric should be returned. GetCounter(name string) Counter // GetTimer returns a timer metric for the given name. // If the metric does not exist yet it should be created // otherwise the existing metric should be returned. GetTimer(name string) Timer }
Registry defines an interface for metrics values which can be implemented by different metrics libraries. An implementation must be safe to be used by multiple go routines.
var DefaultRegistry Registry = NoopRegistry{}
DefaultRegistry stores the metrics library provider.
type Timer ¶ added in v1.3.1
type Timer interface { // Percentile returns the nth percentile of the duration. Percentile(nth float64) float64 // Rate1 returns the 1min rate. Rate1() float64 // Update counts an event and records the duration. Update(time.Duration) // UpdateSince counts an event and records the duration // as the delta between 'start' and the function is called. UpdateSince(start time.Time) }
Timer defines a metric for counting and timing durations for events.