metric

package
v0.0.0-...-ff2c174 Latest Latest
Warning

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

Go to latest
Published: May 9, 2021 License: Apache-2.0, MIT Imports: 8 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")

	// WeirdnessMetric is a metric with fields created to track the number
	// of weird occurrences such as time fallback, partial_result and
	// vsyscall count.
	WeirdnessMetric *Uint64Metric
)

Functions

func CreateSentryMetrics

func CreateSentryMetrics()

CreateSentryMetrics creates the sentry metrics during kernel initialization.

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.

func MustRegisterCustomUint64Metric

func MustRegisterCustomUint64Metric(name string, cumulative, sync bool, description string, value func(...string) uint64, fields ...Field)

MustRegisterCustomUint64Metric calls RegisterCustomUint64Metric for metrics without fields and panics if it returns an error.

func RegisterCustomUint64Metric

func RegisterCustomUint64Metric(name string, cumulative, sync bool, units pb.MetricMetadata_Units, description string, value func(...string) uint64, fields ...Field) error

RegisterCustomUint64Metric registers a metric with the given name.

Register must only be called at init and will return and error if called after Initialized.

Preconditions: * name must be globally unique. * Initialize/Disable have not been called. * value is expected to accept exactly len(fields) arguments.

Types

type Field

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

Field contains the field name and allowed values for the metric which is used in registration of the metric.

type Uint64Metric

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

Uint64Metric encapsulates a uint64 that represents some kind of metric to be monitored. We currently support metrics with at most one field.

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

TODO(b/67298427): Support metric fields.

func MustCreateNewUint64Metric

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

MustCreateNewUint64Metric calls NewUint64Metric and panics if it returns an error.

func MustCreateNewUint64NanosecondsMetric

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

MustCreateNewUint64NanosecondsMetric calls NewUint64Metric and panics if it returns an error.

func NewUint64Metric

func NewUint64Metric(name string, sync bool, units pb.MetricMetadata_Units, description string, fields ...Field) (*Uint64Metric, error)

NewUint64Metric creates and registers a new cumulative metric with the given name.

Metrics must be statically defined (i.e., at init).

func (*Uint64Metric) Increment

func (m *Uint64Metric) Increment(fieldValues ...string)

Increment increments the metric field by 1.

func (*Uint64Metric) IncrementBy

func (m *Uint64Metric) IncrementBy(v uint64, fieldValues ...string)

IncrementBy increments the metric by v.

func (*Uint64Metric) Value

func (m *Uint64Metric) Value(fieldValues ...string) uint64

Value returns the current value of the metric for the given set of fields.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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