metrics

package
v0.0.0-...-49e5460 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2019 License: MIT Imports: 13 Imported by: 0

README

metrics

Things we want

  • labels: registry and metric level
  • FAST (avoid locking where possible)
  • interfaces -* make it easy for people to implement their own metric type
  • namespaced metrics (something like a registry)
  • pluggable (use with graphite, prom, etc.)
  • register AND unregister metrics

Types of metrics

  • counter
  • gauge
  • run func X to get the value: useful for things like "time since start"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MergeMetricPoint

func MergeMetricPoint(ctx context.Context, m Metric, c Collectable, out chan<- MetricPoint) error

Merge all data from `Metric` to every MetricPoint returned from `Collectable`

func StreamMetricDescs

func StreamMetricDescs(ctx context.Context, c Collectable, out chan<- MetricDesc, transformations []MetricDescTransformation) error

func StreamMetricPoints

func StreamMetricPoints(ctx context.Context, c Collectable, out chan<- MetricPoint, transformations []MetricPointTransformation) error

Types

type Collectable

type Collectable interface {
	Describe(context.Context, chan<- MetricDesc) error
	Collect(context.Context, chan<- MetricPoint) error
}

Collectable is an interface that defines how to collect metrics

func NewCounter

func NewCounter() Collectable

func NewGauge

func NewGauge() Collectable

func NewTimeSince

func NewTimeSince() Collectable

TimeSince will report the delta from time.Now() and the previous time observed

type CollectableArray

type CollectableArray struct {
	// Base name + labelset to apply to all sub-metrics
	Metric

	// Function to create a new Value
	Creator CollectableCreator

	// Keys of all the labels allowed for metrics in this array
	LabelKeys []string
	// contains filtered or unexported fields
}

Store an array of metrics.

func NewCollectableArray

func NewCollectableArray(m Metric, c CollectableCreator, l []string) *CollectableArray

func (*CollectableArray) Collect

func (m *CollectableArray) Collect(ctx context.Context, c chan<- MetricPoint) error

func (*CollectableArray) CounterWithValues

func (m *CollectableArray) CounterWithValues(vals ...string) CounterType

func (*CollectableArray) Describe

func (m *CollectableArray) Describe(ctx context.Context, c chan<- MetricDesc) error

func (*CollectableArray) GaugeWithValues

func (m *CollectableArray) GaugeWithValues(vals ...string) GaugeType

func (*CollectableArray) ObserveWithValues

func (m *CollectableArray) ObserveWithValues(vals ...string) ObserveType

func (*CollectableArray) Remove

func (m *CollectableArray) Remove(vals ...string)

func (*CollectableArray) WithValues

func (m *CollectableArray) WithValues(vals ...string) Collectable

Access it by the slice of values

type CollectableCreator

type CollectableCreator func() Collectable

func NewTDigestCreator

func NewTDigestCreator(quantiles []float64) CollectableCreator

type Counter

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

func (*Counter) Collect

func (c *Counter) Collect(ctx context.Context, ch chan<- MetricPoint) error

func (*Counter) Describe

func (c *Counter) Describe(ctx context.Context, ch chan<- MetricDesc) error

func (*Counter) Inc

func (c *Counter) Inc(i uint64)

type CounterArray

type CounterArray struct {
	*CollectableArray
}

func NewCounterArray

func NewCounterArray(m Metric, l []string) *CounterArray

type specific array collectable

func NewCustomCounterArray

func NewCustomCounterArray(m Metric, c CollectableCreator, l []string) (*CounterArray, error)

type specific array collectable

func (*CounterArray) WithValues

func (g *CounterArray) WithValues(vals ...string) CounterType

type CounterType

type CounterType interface {
	Inc(uint64)
}

A few interfaces for user interraction with metrics. The goal here is to create a more user-friendly interface for the Array types

type FunctionCollectable

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

func NewFunctionCollectable

func NewFunctionCollectable(f func() float64) *FunctionCollectable

func (*FunctionCollectable) Collect

func (f *FunctionCollectable) Collect(ctx context.Context, ch chan<- MetricPoint) error

func (*FunctionCollectable) Describe

func (f *FunctionCollectable) Describe(ctx context.Context, ch chan<- MetricDesc) error

type Gauge

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

func (*Gauge) Add

func (c *Gauge) Add(i float64)

func (*Gauge) Collect

func (c *Gauge) Collect(ctx context.Context, ch chan<- MetricPoint) error

func (*Gauge) Describe

func (c *Gauge) Describe(ctx context.Context, ch chan<- MetricDesc) error

func (*Gauge) Set

func (c *Gauge) Set(i float64)

type GaugeArray

type GaugeArray struct {
	*CollectableArray
}

func NewCustomGaugeArray

func NewCustomGaugeArray(m Metric, c CollectableCreator, l []string) (*GaugeArray, error)

type specific array collectable

func NewGaugeArray

func NewGaugeArray(m Metric, l []string) *GaugeArray

type specific array collectable

func (*GaugeArray) WithValues

func (g *GaugeArray) WithValues(vals ...string) GaugeType

type GaugeType

type GaugeType interface {
	Add(float64)
	Set(float64)
}

type LabelSet

type LabelSet map[string]string

func MergeLabels

func MergeLabels(m LabelSet, k []string, v []string) LabelSet

func MergeLabelsDirect

func MergeLabelsDirect(m LabelSet, o LabelSet) LabelSet

func (LabelSet) String

func (l LabelSet) String() string

type Metric

type Metric struct {
	Name   string // TODO: remove from here?
	Labels LabelSet
	Help   string
}

A metric is defined as (1) name and (2) labelset

func (Metric) String

func (m Metric) String() string

TODO: nicely layout the m.Labels (instead of the go print out)

type MetricDesc

type MetricDesc struct {
	Name   string
	Prefix bool
}

Description of metrics

type MetricDescRegistry

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

TODO: make these mergeable

func NewMetricDescRegistry

func NewMetricDescRegistry() *MetricDescRegistry

TODO: better name, we don't want to call this a registry since this doesn't implement the Registry interface

func (*MetricDescRegistry) AddOrError

func (n *MetricDescRegistry) AddOrError(ds []MetricDesc) error

func (*MetricDescRegistry) Contains

func (n *MetricDescRegistry) Contains(name string) bool

func (*MetricDescRegistry) List

func (n *MetricDescRegistry) List() []MetricDesc

func (*MetricDescRegistry) Remove

func (n *MetricDescRegistry) Remove(ds []MetricDesc)

type MetricDescTransformation

type MetricDescTransformation func(*MetricDesc) (bool, error)

type MetricPoint

type MetricPoint struct {
	Metric
	// Actual value
	Value Value
	// Time associated with this value (if not defined "now" is intended)
	Time time.Time
}

Represent a snapshot of a metric at a specific point in time

func CollectOne

func CollectOne(ctx context.Context, c Collectable) MetricPoint

CollectOne will get a single MetricPoint from a Collectable c

func CollectPoints

func CollectPoints(ctx context.Context, c Collectable) ([]MetricPoint, error)

func (*MetricPoint) String

func (m *MetricPoint) String() string

type MetricPointTransformation

type MetricPointTransformation func(*MetricPoint) (bool, error)

Return bool (to send) and error

type NamespaceRegistry

type NamespaceRegistry struct {
	Namespace string
	// contains filtered or unexported fields
}

func NewNamespaceRegistry

func NewNamespaceRegistry(n string) *NamespaceRegistry

func (*NamespaceRegistry) Collect

func (n *NamespaceRegistry) Collect(ctx context.Context, points chan<- MetricPoint) error

Collect simply calls collect on all the collectables in this registry adding its namespace as a prefix to the name

func (*NamespaceRegistry) Describe

func (n *NamespaceRegistry) Describe(ctx context.Context, c chan<- MetricDesc) error

func (*NamespaceRegistry) Each

func (n *NamespaceRegistry) Each(ctx context.Context, eachFunc RegistryEachFunc) error

func (*NamespaceRegistry) Register

func (n *NamespaceRegistry) Register(c Collectable) error

func (*NamespaceRegistry) Unregister

func (n *NamespaceRegistry) Unregister(c Collectable) error

type ObserveArray

type ObserveArray struct {
	*CollectableArray
}

func NewCustomObserveArray

func NewCustomObserveArray(m Metric, c CollectableCreator, l []string) (*ObserveArray, error)

type specific array collectable

func (*ObserveArray) WithValues

func (g *ObserveArray) WithValues(vals ...string) ObserveType

type ObserveType

type ObserveType interface {
	Observe(float64)
}

type Registry

type Registry interface {
	// Registries need to be collectable
	Collectable

	Register(Collectable) error
	Unregister(Collectable) error

	// called for each metric in the registry, context for cancellation and a function
	// which takes the name of the collectable and the collectable itself
	Each(context.Context, RegistryEachFunc) error
}

Registry is a collection collectables with given names

type RegistryEachFunc

type RegistryEachFunc func(Collectable, *MetricDescRegistry) error

type SingleCollectable

type SingleCollectable struct {
	Metric
	Collectable
}

TODO: move

func (*SingleCollectable) Collect

func (s *SingleCollectable) Collect(ctx context.Context, c chan<- MetricPoint) error

func (*SingleCollectable) Describe

func (s *SingleCollectable) Describe(ctx context.Context, c chan<- MetricDesc) error

type TDigest

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

func NewTDigest

func NewTDigest(quantiles []float64) *TDigest

func (*TDigest) Collect

func (t *TDigest) Collect(ctx context.Context, c chan<- MetricPoint) error

func (*TDigest) Describe

func (t *TDigest) Describe(ctx context.Context, c chan<- MetricDesc) error

func (*TDigest) Observe

func (t *TDigest) Observe(v float64)

type TimeSince

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

Metric type that will both (1) time and (2) count observations

func (*TimeSince) Collect

func (t *TimeSince) Collect(ctx context.Context, c chan<- MetricPoint) error

func (*TimeSince) Describe

func (t *TimeSince) Describe(ctx context.Context, c chan<- MetricDesc) error

func (*TimeSince) Observe

func (t *TimeSince) Observe(v float64)

TODO: don't like this :/ I'd like to pass a time.Time -- but if we have to this isn't terrible

type Timer

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

Metric type that will both (1) time and (2) count observations

func NewTimer

func NewTimer() *Timer

func (*Timer) Collect

func (t *Timer) Collect(ctx context.Context, c chan<- MetricPoint) error

func (*Timer) Describe

func (t *Timer) Describe(ctx context.Context, c chan<- MetricDesc) error

func (*Timer) Observe

func (t *Timer) Observe(v float64)

TODO: don't like this :/ I'd like to pass a time.Duration -- but if we have to this isn't terrible

type Value

type Value float64

Value encapsulates a float64 value. The separate type is largely required to deal with go's json marshaling

func (Value) MarshalJSON

func (v Value) MarshalJSON() ([]byte, error)

func (*Value) UnmarshalJSON

func (v *Value) UnmarshalJSON(b []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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