metrics

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package metrics provides various measurements that are safe for concurrent access.

Measurements are arranged into groups that are efficient to create and access.

Index

Constants

View Source
const (
	// DefaultGroup is the identifier for the default group.
	DefaultGroup = GID(0)
)

Variables

This section is empty.

Functions

func NewContextWithGroup

func NewContextWithGroup(ctx context.Context, c *Group) context.Context

NewContextWithGroup returns a new context with the given Group added.

func WithGroup

func WithGroup(gid GID) descOption

WithGroup assigns the associated measurement to the group identified by gid originally returned from MustRegisterGroup.

Types

type Counter

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

The Counter type represents a numeric counter that is safe to use from concurrent goroutines.

func (*Counter) Add

func (c *Counter) Add(d int64)

Add atomically adds d to the counter.

func (*Counter) Name

func (c *Counter) Name() string

Name identifies the name of the counter.

func (*Counter) String

func (c *Counter) String() string

String returns a string representation using the name and value of the counter.

func (*Counter) Value

func (c *Counter) Value() int64

Value atomically returns the current value of the counter.

type GID

type GID uint32

func MustRegisterGroup

func MustRegisterGroup(name string) GID

MustRegisterGroup registers a new group using the specified name. If the group name is not unique, MustRegisterGroup will panic.

MustRegisterGroup is not safe to call from multiple goroutines.

type Group

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

The Group type represents an instance of a set of measurements that are used for instrumenting a specific request.

func GroupFromContext

func GroupFromContext(ctx context.Context) *Group

GroupFromContext returns the Group associated with ctx or nil if no Group has been assigned.

func NewGroup

func NewGroup(gid GID) *Group

NewGroup returns a new measurement group from the default registry.

NewGroup is safe to call from multiple goroutines.

func (*Group) ForEach

func (g *Group) ForEach(fn func(v Metric))

ForEach calls fn for all measurements of the group.

func (*Group) GetCounter

func (g *Group) GetCounter(id ID) *Counter

GetCounter returns the counter identified by the id that was returned by MustRegisterCounter for the same group. Using an id from a different group will result in undefined behavior.

func (*Group) GetTimer

func (g *Group) GetTimer(id ID) *Timer

GetTimer returns the timer identified by the id that was returned by MustRegisterTimer for the same group. Using an id from a different group will result in undefined behavior.

func (*Group) Name

func (g *Group) Name() string

Name returns the name of the group.

type ID

type ID uint64

func MustRegisterCounter

func MustRegisterCounter(name string, opts ...descOption) ID

MustRegisterCounter registers a new counter metric with the default registry using the provided descriptor. If the metric name is not unique, MustRegisterCounter will panic.

MustRegisterCounter is not safe to call from multiple goroutines.

func MustRegisterTimer

func MustRegisterTimer(name string, opts ...descOption) ID

MustRegisterTimer registers a new timer metric with the default registry using the provided descriptor. If the metric name is not unique, MustRegisterTimer will panic.

MustRegisterTimer is not safe to call from multiple goroutines.

type Metric

type Metric interface {
	Name() string
}

The Metric type defines a Name

type Registry

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

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new Registry with a single group identified by DefaultGroup.

func (*Registry) MustRegisterCounter

func (r *Registry) MustRegisterCounter(name string, opts ...descOption) ID

MustRegisterCounter registers a new counter metric using the provided descriptor. If the metric name is not unique within the group, MustRegisterCounter will panic.

MustRegisterCounter is not safe to call from concurrent goroutines.

func (*Registry) MustRegisterGroup

func (r *Registry) MustRegisterGroup(name string) GID

MustRegisterGroup registers a new group and panics if a group already exists with the same name.

MustRegisterGroup is not safe to call from concurrent goroutines.

func (*Registry) MustRegisterTimer

func (r *Registry) MustRegisterTimer(name string, opts ...descOption) ID

MustRegisterTimer registers a new timer metric using the provided descriptor. If the metric name is not unique within the group, MustRegisterTimer will panic.

MustRegisterTimer is not safe to call from concurrent goroutines.

func (*Registry) NewGroup

func (r *Registry) NewGroup(gid GID) *Group

type Timer

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

The timer type is used to store a duration.

func (*Timer) Name

func (t *Timer) Name() string

Name returns the name of the timer.

func (*Timer) String

func (t *Timer) String() string

String returns a string representation using the name and value of the timer.

func (*Timer) Time

func (t *Timer) Time(f func())

Time updates the timer to the duration it takes to call f.

func (*Timer) Update

func (t *Timer) Update(d time.Duration)

Update sets the timer value to d.

func (*Timer) UpdateSince

func (t *Timer) UpdateSince(since time.Time)

UpdateSince sets the timer value to the difference between since and the current time.

func (*Timer) Value

func (t *Timer) Value() time.Duration

Value atomically returns the value of the timer.

Jump to

Keyboard shortcuts

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