metrics

package
v0.78.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultGaugePollingInterval = 1 * time.Second

Variables

View Source
var MinuteDistributionBuckets = append(
	[]float64{
		0.01,
		0.025,
		0.05,
		0.1,
		0.25,
		0.5,
		1.0,
	},
	prometheus.LinearBuckets(5.0, 5.0, 12)...,
)

MinuteDistributionBuckets is a set of buckets that provide insight for both subsecond latency requests, as well as exceptionally long ones.

Functions

func GetTags

func GetTags(opts ...TagOption) []string

GetTags returns a slice of tags given a set of TagOptions

func NewMangoStatsCounter

func NewMangoStatsCounter(c Client, tags ...string) cache.StatsCounter

NewMangoStatsCounter provides an adapter for github.com/goburrow/cache.StatsCounter over this packages Client.

func Register added in v0.62.0

Register regsiters the provided prometheus collector, or returns the previously registered metric if it exists.

func RegisterClientCtor

func RegisterClientCtor(clientType string, ctr ClientCtor)

RegisterClientCtor registers a ClientCtor for the specified client type.

Types

type Client

type Client interface {
	// Count measures the count of a metric
	Count(name string, value int64, tags []string) error

	// Gauge measures a metric at a point in time
	Gauge(name string, value float64, tags []string) error

	// Timing measures the time of a metric.
	Timing(name string, value time.Duration, tags []string) error

	// Close closes the client and any underlying resources
	Close() error
}

Client is used for exporting metrics

func CreateClient

func CreateClient(clientType string, config *ClientConfig) (Client, error)

CreateClient creates a Client using the ClientCtor of the requested type, if one has been registered. If no constructor has been registered with the specified type, an error is thrown.

type ClientConfig

type ClientConfig struct {
	// Namespace is the prefix to be prepended to all client calls
	Namespace string
	// GlobalTags are tags that will be added to every metric
	GlobalTags []string
}

type ClientCtor

type ClientCtor func(config *ClientConfig) (Client, error)

A ClientCtor creates a metrics client using the provided config.

type ClientOption

type ClientOption func(o *ClientConfig)

func WithGlobalTags

func WithGlobalTags(tagOptions ...TagOption) ClientOption

WithGlobalTags configures the client to include a set of tags to all submitted metrics.

func WithNamespace

func WithNamespace(namespace string) ClientOption

WithNamespace configures the client to use the provided namespace.

type Gauge

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

Gauge measures a metric's value at a point in time

func NewGauge

func NewGauge(client Client, name string, f GaugeFunc, tagOptions ...TagOption) (*Gauge, error)

NewGauge returns a new Gauge that polls the value returned by f

func (*Gauge) Stop

func (g *Gauge) Stop()

Stop removes the gauge from being polled

type GaugeFunc

type GaugeFunc func() float64

GaugeFunc is used in a polling loop to get the metric's value. Processing here is expected to be fairly light weight since we use a single polling thread to process all gauges.

type Meter

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

Meter tracks a count of a metric

func NewMeter

func NewMeter(client Client, name string, tagOptions ...TagOption) (*Meter, error)

NewMeter returns a new meter

func (*Meter) Count

func (m *Meter) Count(value int64)

Count adds the provided value to the metric's count

func (*Meter) Decr

func (m *Meter) Decr()

Decr subtracts 1 from the metric's count

func (*Meter) Incr

func (m *Meter) Incr()

Incr adds 1 to the metric's count

type TagOption

type TagOption func() string

TagOption specifies a tag that should be added to a metric

func WithApp

func WithApp(appIdx int16) TagOption

WithAppTAg adds an "app" tag to a metric. This is typically used to indicate which app a metric pertains to.

func WithServiceTag

func WithServiceTag(serviceName string) TagOption

WithServiceTag adds a "service" tag to a metric. This is typically used to indicate which service a metric came from.

func WithTypeTag

func WithTypeTag(typeName string) TagOption

WithTypeTag adds a "type" tag to a metric. This is typically used to differentiate metrics from different implementations of an interface.

type Timer

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

Timer tracks the time a metric

func NewTimer

func NewTimer(client Client, name string, tagOptions ...TagOption) (*Timer, error)

NewTimer returns a new Timer

func (*Timer) AddTiming

func (t *Timer) AddTiming(value time.Duration, tags ...TagOption)

AddTiming emits a timing value that has already been observed

func (*Timer) Time

func (t *Timer) Time(tags ...TagOption) *TimerContext

Time begins tracking a new datapoint. Use TimerContext.Stop on the returned context to record the time passed since calling Time

type TimerContext

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

TimerContext is the context for an in-flight datapoint

func (*TimerContext) Stop

func (tc *TimerContext) Stop()

Stop records the time since the context's creation if it hasn't already been stopped

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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