metrics

package
v1.5.9 Latest Latest
Warning

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

Go to latest
Published: May 16, 2018 License: MIT Imports: 19 Imported by: 0

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

View Source
const DefaultNames = "{{clean .Service}}.{{clean .Host}}.{{clean .Path}}.{{clean .TargetURL.Host}}"

DefaultNames contains the default template for route metric names.

View Source
const DefaultPrefix = "{{clean .Hostname}}.{{clean .Exec}}"

DefaulPrefix contains the default template for metrics prefix.

Variables

This section is empty.

Functions

func TargetName

func TargetName(service, host, path string, targetURL *url.URL) (string, error)

TargetName returns the metrics name from the given parameters.

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 (t NoopTimer) Percentile(nth float64) float64

func (NoopTimer) Rate1 added in v1.3.1

func (t NoopTimer) Rate1() float64

func (NoopTimer) Update added in v1.4.1

func (t NoopTimer) Update(time.Duration)

func (NoopTimer) UpdateSince added in v1.3.1

func (t NoopTimer) UpdateSince(time.Time)

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.

func NewRegistry added in v1.3.1

func NewRegistry(cfg config.Metrics) (r Registry, err error)

NewRegistry creates a new metrics registry.

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.

Jump to

Keyboard shortcuts

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