Documentation ¶
Overview ¶
Package metric provides primitives for collecting metrics.
Index ¶
- Variables
- func Disable()
- func EmitMetricUpdate()
- func Initialize()
- func MustRegisterCustomUint64Metric(name string, cumulative, sync bool, description string, value func() uint64)
- func RegisterCustomUint64Metric(name string, cumulative, sync bool, units pb.MetricMetadata_Units, ...) error
- type Uint64Metric
- func MustCreateNewUint64Metric(name string, sync bool, description string) *Uint64Metric
- func MustCreateNewUint64NanosecondsMetric(name string, sync bool, description string) *Uint64Metric
- func NewUint64Metric(name string, sync bool, units pb.MetricMetadata_Units, description string) (*Uint64Metric, error)
Constants ¶
This section is empty.
Variables ¶
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.
func MustRegisterCustomUint64Metric ¶
func MustRegisterCustomUint64Metric(name string, cumulative, sync bool, description string, value func() uint64)
MustRegisterCustomUint64Metric calls RegisterCustomUint64Metric and panics if it returns an error.
func RegisterCustomUint64Metric ¶
func RegisterCustomUint64Metric(name string, cumulative, sync bool, units pb.MetricMetadata_Units, description string, value func() uint64) 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.
Types ¶
type Uint64Metric ¶
type Uint64Metric struct {
// contains filtered or unexported fields
}
Uint64Metric encapsulates a uint64 that represents some kind of metric to be monitored.
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) *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) (*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()
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.