metric

package
v0.0.0-...-23e6066 Latest Latest
Warning

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

Go to latest
Published: May 3, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package metric provides primitives for collecting metrics.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNameInUse indicates that another metric is already defined for
	// the given name.
	ErrNameInUse = errors.New("metric name already in use")

	// ErrInitializationDone indicates that the caller tried to create a
	// new metric after initialization.
	ErrInitializationDone = errors.New("metric cannot be created after initialization is complete")
)

Functions

func Disable

func Disable()

Disable sends an empty metric registration event over the event channel, disabling metric collection.

Precondition:

  • All metrics are registered.
  • Initialize/Disable has not been called.

func EmitMetricUpdate

func EmitMetricUpdate()

EmitMetricUpdate emits a MetricUpdate over the event channel.

Only metrics that have changed since the last call are emitted.

EmitMetricUpdate is thread-safe.

Preconditions:

  • Initialize has been called.

func Initialize

func Initialize()

Initialize sends a metric registration event over the event channel.

Precondition:

  • All metrics are registered.
  • Initialize/Disable has not been called.

Types

type Uint64Metric

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

Uint64Metric encapsulates a uint64 that represents some kind of metric to be monitored.

All metrics must be cumulative, meaning that their values will only increase over time.

Metrics are not saved across save/restore and thus reset to zero on restore.

TODO: Support non-cumulative metrics. TODO: Support metric fields.

func MustCreateNewUint64Metric

func MustCreateNewUint64Metric(name string, sync bool, description string) *Uint64Metric

MustCreateNewUint64Metric calls NewUint64Metric and panics if it returns an error.

func NewUint64Metric

func NewUint64Metric(name string, sync bool, description string) (*Uint64Metric, error)

NewUint64Metric creates a new metric with the given name.

Metrics must be statically defined (i.e., at startup). NewUint64Metric will return an error if called after Initialized.

Preconditions:

  • name must be globally unique.
  • Initialize/Disable have not been called.

func (*Uint64Metric) Increment

func (m *Uint64Metric) Increment()

Increment increments the metric by 1.

func (*Uint64Metric) IncrementBy

func (m *Uint64Metric) IncrementBy(v uint64)

IncrementBy increments the metric by v.

func (*Uint64Metric) Value

func (m *Uint64Metric) Value() uint64

Value returns the current value of the metric.

Jump to

Keyboard shortcuts

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