package metrics
import "github.com/influxdata/influxdb/pkg/metrics"
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
- func NewContextWithGroup(ctx context.Context, c *Group) context.Context
- func WithGroup(gid GID) descOption
- type Counter
- func (c *Counter) Add(d int64)
- func (c *Counter) Name() string
- func (c *Counter) String() string
- func (c *Counter) Value() int64
- type GID
- type Group
- func GroupFromContext(ctx context.Context) *Group
- func NewGroup(gid GID) *Group
- func (g *Group) ForEach(fn func(v Metric))
- func (g *Group) GetCounter(id ID) *Counter
- func (g *Group) GetTimer(id ID) *Timer
- func (g *Group) Name() string
- type ID
- func MustRegisterCounter(name string, opts ...descOption) ID
- func MustRegisterTimer(name string, opts ...descOption) ID
- type Metric
- type Registry
- func NewRegistry() *Registry
- func (r *Registry) MustRegisterCounter(name string, opts ...descOption) ID
- func (r *Registry) MustRegisterGroup(name string) GID
- func (r *Registry) MustRegisterTimer(name string, opts ...descOption) ID
- func (r *Registry) NewGroup(gid GID) *Group
- type Timer
Constants ¶
const ( // DefaultGroup is the identifier for the default group. DefaultGroup = GID(0) )
Functions ¶
func NewContextWithGroup ¶
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 ¶
Add atomically adds d to the counter.
func (*Counter) Name ¶
Name identifies the name of the counter.
func (*Counter) String ¶
String returns a string representation using the name and value of the counter.
func (*Counter) Value ¶
Value atomically returns the current value of the counter.
type GID ¶
type GID uint32
func MustRegisterGroup ¶
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 ¶
GroupFromContext returns the Group associated with ctx or nil if no Group has been assigned.
func NewGroup ¶
NewGroup returns a new measurement group from the default registry.
NewGroup is safe to call from multiple goroutines.
func (*Group) ForEach ¶
ForEach calls fn for all measurements of the group.
func (*Group) GetCounter ¶
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 ¶
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 ¶
Name returns the name of the group.
type ID ¶
type ID uint64
func MustRegisterCounter ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
The timer type is used to store a duration.
func (*Timer) Name ¶
Name returns the name of the timer.
func (*Timer) 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 ¶
Update sets the timer value to d.
func (*Timer) UpdateSince ¶
UpdateSince sets the timer value to the difference between since and the current time.
func (*Timer) Value ¶
Value atomically returns the value of the timer.
Source Files ¶
context.go counter.go default_registry.go descriptors.go doc.go group.go group_registry.go registry.go timer.go
- Version
- v1.12.0 (latest)
- Published
- Apr 8, 2025
- Platform
- linux/amd64
- Imports
- 6 packages
- Last checked
- 2 days ago –
Tools for package owners.