metrics

package
v0.41.2 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package metrics defines a concurrently-accessible metrics collector.

A *metrics.M value exports methods to track integer counters and maximum values. A metric has a caller-assigned string name that is not interpreted by the collector except to locate its stored value.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type M

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

An M collects counters and maximum value trackers. A nil *M is valid, and discards all metrics. The methods of an *M are safe for concurrent use by multiple goroutines.

func New

func New() *M

New creates a new, empty metrics collector.

func (*M) Count

func (m *M) Count(name string, n int64)

Count adds n to the current value of the counter named, defining the counter if it does not already exist.

func (*M) CountAndSetMax

func (m *M) CountAndSetMax(name string, n int64)

CountAndSetMax adds n to the current value of the counter named, and also updates a max value tracker with the same name in a single step.

func (*M) EditLabel added in v0.26.1

func (m *M) EditLabel(name string, edit func(interface{}) interface{})

EditLabel calls edit with the current value of the specified label. The value returned by edit replaces the contents of the label. If edit returns nil, the label is removed from the set. If the label did not exist, the argument to edit is nil.

func (*M) SetLabel

func (m *M) SetLabel(name string, value interface{})

SetLabel sets the specified label to value. If value == nil the label is removed from the set.

As a special case, if value has the concrete type

func() interface{}

then the value of the label is obtained by calling that function.

func (*M) SetMaxValue

func (m *M) SetMaxValue(name string, n int64)

SetMaxValue sets the maximum value metric named to the greater of n and its current value, defining the value if it does not already exist.

func (*M) Snapshot

func (m *M) Snapshot(snap Snapshot)

Snapshot copies an atomic snapshot of the collected metrics into the non-nil fields of the provided snapshot value. Only the fields of snap that are not nil are snapshotted.

type Snapshot

type Snapshot struct {
	Counter  map[string]int64
	MaxValue map[string]int64
	Label    map[string]interface{}
}

A Snapshot represents a point-in-time snapshot of a metrics collector. The fields of this type are filled in by the Snapshot method of *M.

Jump to

Keyboard shortcuts

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