metrics

package
v4.27.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReverseLabelledPath

func ReverseLabelledPath(path string) (name string, tagNames, tagValues []string)

ReverseLabelledPath extracts a name, tag names and tag values from a labelled metric name.

Types

type Config

type Config struct {
	Type    string `json:"type" yaml:"type"`
	Mapping string `json:"mapping" yaml:"mapping"`
	Plugin  any    `json:"plugin,omitempty" yaml:"plugin,omitempty"`
}

Config is the all encompassing configuration struct for all metric output types.

func FromAny added in v4.25.0

func FromAny(prov docs.Provider, value any) (conf Config, err error)

func NewConfig

func NewConfig() Config

NewConfig returns a configuration struct fully populated with default values.

type DudStat

type DudStat struct{}

DudStat implements the Stat interface but doesn't actual do anything.

func (DudStat) Decr

func (d DudStat) Decr(count int64)

Decr does nothing.

func (DudStat) DecrFloat64 added in v4.23.0

func (d DudStat) DecrFloat64(count float64)

DecrFloat64 does nothing

func (DudStat) Incr

func (d DudStat) Incr(count int64)

Incr does nothing.

func (DudStat) IncrFloat64 added in v4.23.0

func (d DudStat) IncrFloat64(count float64)

IncrFloat64 does nothing

func (DudStat) Set

func (d DudStat) Set(value int64)

Set does nothing.

func (DudStat) SetFloat64 added in v4.23.0

func (d DudStat) SetFloat64(value float64)

SetFloat64 does nothing

func (DudStat) Timing

func (d DudStat) Timing(delta int64)

Timing does nothing.

type DudType

type DudType struct {
	ID int
}

DudType implements the Type interface but doesn't actual do anything.

func (DudType) Close

func (d DudType) Close() error

Close does nothing.

func (DudType) GetCounter

func (d DudType) GetCounter(path string) StatCounter

GetCounter returns a DudStat.

func (DudType) GetCounterVec

func (d DudType) GetCounterVec(path string, n ...string) StatCounterVec

GetCounterVec returns a DudStat.

func (DudType) GetGauge

func (d DudType) GetGauge(path string) StatGauge

GetGauge returns a DudStat.

func (DudType) GetGaugeVec

func (d DudType) GetGaugeVec(path string, n ...string) StatGaugeVec

GetGaugeVec returns a DudStat.

func (DudType) GetTimer

func (d DudType) GetTimer(path string) StatTimer

GetTimer returns a DudStat.

func (DudType) GetTimerVec

func (d DudType) GetTimerVec(path string, n ...string) StatTimerVec

GetTimerVec returns a DudStat.

func (DudType) HandlerFunc

func (d DudType) HandlerFunc() http.HandlerFunc

HandlerFunc returns nil.

type Local

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

Local is a metrics aggregator that stores metrics locally.

func NewLocal

func NewLocal() *Local

NewLocal creates and returns a new Local aggregator.

func (*Local) Close

func (l *Local) Close() error

Close stops the Local object from aggregating metrics and cleans up resources.

func (*Local) FlushCounters

func (l *Local) FlushCounters() map[string]int64

FlushCounters returns a map of the current state of the metrics paths to counters and then resets the counters to 0.

func (*Local) FlushTimings

func (l *Local) FlushTimings() map[string]metrics.Timer

FlushTimings returns a map of the current state of the metrics paths to timers and then resets the timers to 0.

func (*Local) GetCounter

func (l *Local) GetCounter(path string) StatCounter

GetCounter returns a stat counter object for a path.

func (*Local) GetCounterVec

func (l *Local) GetCounterVec(path string, k ...string) StatCounterVec

GetCounterVec returns a stat counter object for a path and records the labels and values.

func (*Local) GetCounters

func (l *Local) GetCounters() map[string]int64

GetCounters returns a map of metric paths to counters.

func (*Local) GetGauge

func (l *Local) GetGauge(path string) StatGauge

GetGauge returns a stat gauge object for a path.

func (*Local) GetGaugeVec

func (l *Local) GetGaugeVec(path string, k ...string) StatGaugeVec

GetGaugeVec returns a stat timer object for a path with the labels discarded.

func (*Local) GetTimer

func (l *Local) GetTimer(path string) StatTimer

GetTimer returns a stat timer object for a path.

func (*Local) GetTimerVec

func (l *Local) GetTimerVec(path string, k ...string) StatTimerVec

GetTimerVec returns a stat timer object for a path with the labels and values.

func (*Local) GetTimings

func (l *Local) GetTimings() map[string]metrics.Timer

GetTimings returns a map of metric paths to timers.

func (*Local) HandlerFunc

func (l *Local) HandlerFunc() http.HandlerFunc

HandlerFunc returns nil.

type LocalStat

type LocalStat struct {
	Value *int64
}

LocalStat is a representation of a single metric stat. Interactions with this stat are thread safe.

func (*LocalStat) Decr

func (l *LocalStat) Decr(count int64)

Decr decrements a metric by an amount.

func (*LocalStat) DecrFloat64 added in v4.23.0

func (l *LocalStat) DecrFloat64(count float64)

func (*LocalStat) Incr

func (l *LocalStat) Incr(count int64)

Incr increments a metric by an int64 amount.

func (*LocalStat) IncrFloat64 added in v4.23.0

func (l *LocalStat) IncrFloat64(count float64)

func (*LocalStat) Set

func (l *LocalStat) Set(value int64)

Set sets a gauge metric.

func (*LocalStat) SetFloat64 added in v4.23.0

func (l *LocalStat) SetFloat64(value float64)

type LocalTiming

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

LocalTiming is a representation of a single metric timing.

func (*LocalTiming) Timing

func (l *LocalTiming) Timing(delta int64)

Timing sets a timing metric.

type Mapping

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

Mapping is a compiled Bloblang mapping used to rewrite metrics.

func NewMapping

func NewMapping(mapping string, logger log.Modular) (*Mapping, error)

NewMapping parses a Bloblang mapping and returns a metrics mapping.

func (*Mapping) WithStaticVars added in v4.1.0

func (m *Mapping) WithStaticVars(kvs map[string]any) *Mapping

WithStaticVars adds a map of key/value pairs to the static variables of the metrics mapping. These are variables that will be made available to each invocation of the metrics mapping.

type Namespaced

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

Namespaced wraps a child metrics exporter and exposes a Type API that adds namespacing labels and name prefixes to new.

func NewNamespaced

func NewNamespaced(child Type) *Namespaced

NewNamespaced wraps a metrics exporter and adds prefixes and custom labels.

func Noop

func Noop() *Namespaced

Noop returns a namespaced metrics aggregator with a noop child.

func (*Namespaced) Child

func (n *Namespaced) Child() Type

Child returns the underlying metrics type.

func (*Namespaced) Close

func (n *Namespaced) Close() error

Close stops aggregating stats and cleans up resources.

func (*Namespaced) GetCounter

func (n *Namespaced) GetCounter(path string) StatCounter

GetCounter returns an editable counter stat for a given path.

func (*Namespaced) GetCounterVec

func (n *Namespaced) GetCounterVec(path string, labelNames ...string) StatCounterVec

GetCounterVec returns an editable counter stat for a given path with labels, these labels must be consistent with any other metrics registered on the same path.

func (*Namespaced) GetGauge

func (n *Namespaced) GetGauge(path string) StatGauge

GetGauge returns an editable gauge stat for a given path.

func (*Namespaced) GetGaugeVec

func (n *Namespaced) GetGaugeVec(path string, labelNames ...string) StatGaugeVec

GetGaugeVec returns an editable gauge stat for a given path with labels, these labels must be consistent with any other metrics registered on the same path.

func (*Namespaced) GetTimer

func (n *Namespaced) GetTimer(path string) StatTimer

GetTimer returns an editable timer stat for a given path.

func (*Namespaced) GetTimerVec

func (n *Namespaced) GetTimerVec(path string, labelNames ...string) StatTimerVec

GetTimerVec returns an editable timer stat for a given path with labels, these labels must be consistent with any other metrics registered on the same path.

func (*Namespaced) HandlerFunc

func (n *Namespaced) HandlerFunc() http.HandlerFunc

HandlerFunc returns the http handler of the child.

func (*Namespaced) WithLabels

func (n *Namespaced) WithLabels(labels ...string) *Namespaced

WithLabels returns a namespaced metrics exporter with a new set of labels, which are added to any prior labels.

func (*Namespaced) WithMapping

func (n *Namespaced) WithMapping(m *Mapping) *Namespaced

WithMapping returns a namespaced metrics exporter with a new mapping. Mappings are applied _before_ the prefix and static labels are applied. Mappings already added are executed after this new mapping.

func (*Namespaced) WithStats

func (n *Namespaced) WithStats(s Type) *Namespaced

WithStats returns a namespaced metrics exporter with a different stats implementation.

type StatCounter

type StatCounter interface {
	// Incr increments a counter by an integer amount.
	Incr(count int64)

	// IncrFloat64 increments a counter by a decimal amount.
	IncrFloat64(count float64)
}

StatCounter is a representation of a single counter metric stat. Interactions with this stat are thread safe.

type StatCounterVec

type StatCounterVec interface {
	// With returns a StatCounter with a set of label values.
	With(labelValues ...string) StatCounter
}

StatCounterVec creates StatCounters with dynamic labels.

func FakeCounterVec

func FakeCounterVec(f func(...string) StatCounter) StatCounterVec

FakeCounterVec returns a counter vec implementation that ignores labels.

type StatGauge

type StatGauge interface {
	// Set sets the integer value of a gauge metric.
	Set(value int64)

	// Incr increments with an integer value a gauge by an amount.
	Incr(count int64)

	// Decr decrements a gauge by an integer amount.
	Decr(count int64)

	// SetFloat64 sets the value of a gauge metric.
	SetFloat64(value float64)

	// IncrFloat64 increments a gauge by an amount.
	IncrFloat64(count float64)

	// DecrFloat64 decrements a gauge by an amount.
	DecrFloat64(count float64)
}

StatGauge is a representation of a single gauge metric stat. Interactions with this stat are thread safe.

type StatGaugeVec

type StatGaugeVec interface {
	// With returns a StatGauge with a set of label values.
	With(labelValues ...string) StatGauge
}

StatGaugeVec creates StatGauges with dynamic labels.

func FakeGaugeVec

func FakeGaugeVec(f func(...string) StatGauge) StatGaugeVec

FakeGaugeVec returns a gauge vec implementation that ignores labels.

type StatTimer

type StatTimer interface {
	// Timing sets a timing metric.
	Timing(delta int64)
}

StatTimer is a representation of a single timer metric stat, timing values should be presented in nanoseconds for consistency. Interactions with this stat are thread safe.

type StatTimerVec

type StatTimerVec interface {
	// With returns a StatTimer with a set of label values.
	With(labelValues ...string) StatTimer
}

StatTimerVec creates StatTimers with dynamic labels.

func FakeTimerVec

func FakeTimerVec(f func(...string) StatTimer) StatTimerVec

FakeTimerVec returns a timer vec implementation that ignores labels.

type Type

type Type interface {
	// GetCounter returns an editable counter stat for a given path.
	GetCounter(path string) StatCounter

	// GetCounterVec returns an editable counter stat for a given path with labels,
	// these labels must be consistent with any other metrics registered on the
	// same path.
	GetCounterVec(path string, labelNames ...string) StatCounterVec

	// GetTimer returns an editable timer stat for a given path.
	GetTimer(path string) StatTimer

	// GetTimerVec returns an editable timer stat for a given path with labels,
	// these labels must be consistent with any other metrics registered on the
	// same path.
	GetTimerVec(path string, labelNames ...string) StatTimerVec

	// GetGauge returns an editable gauge stat for a given path.
	GetGauge(path string) StatGauge

	// GetGaugeVec returns an editable gauge stat for a given path with labels,
	// these labels must be consistent with any other metrics registered on the
	// same path.
	GetGaugeVec(path string, labelNames ...string) StatGaugeVec

	// HandlerFunc returns an optional HTTP request handler that exposes metrics
	// from the implementation. If nil is returned then no endpoint will be
	// registered.
	HandlerFunc() http.HandlerFunc

	// Close stops aggregating stats and cleans up resources.
	Close() error
}

Type is an interface for metrics aggregation.

func Combine

func Combine(t1, t2 Type) Type

Combine returns a Type implementation that feeds metrics into two underlying Type implementations.

Jump to

Keyboard shortcuts

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