metrics

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type Counter

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

Counter is a monotonically increasing counter.

func NewCounter

func NewCounter(name string) *Counter

func (*Counter) Inc

func (c *Counter) Inc()

func (*Counter) IncBy

func (c *Counter) IncBy(delta int64)

func (*Counter) Name

func (c *Counter) Name() string

func (*Counter) Reset

func (c *Counter) Reset()

func (*Counter) SnapshotValue

func (c *Counter) SnapshotValue() any

func (*Counter) Value

func (c *Counter) Value() int64

type Gauge

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

Gauge is a settable signed value.

func NewGauge

func NewGauge(name string) *Gauge

func (*Gauge) Dec

func (g *Gauge) Dec(n int64)

func (*Gauge) Inc

func (g *Gauge) Inc(n int64)

func (*Gauge) Name

func (g *Gauge) Name() string

func (*Gauge) Set

func (g *Gauge) Set(v int64)

func (*Gauge) SnapshotValue

func (g *Gauge) SnapshotValue() any

func (*Gauge) Value

func (g *Gauge) Value() int64

type Histogram

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

Histogram records the distribution of durations into fixed upper-bound buckets.

func NewHistogram

func NewHistogram(name string, buckets []time.Duration) *Histogram

func (*Histogram) Name

func (h *Histogram) Name() string

func (*Histogram) Observe

func (h *Histogram) Observe(d time.Duration)

Observe records d, incrementing every bucket whose upper bound >= d.

func (*Histogram) Percentile

func (h *Histogram) Percentile(q float64) time.Duration

Percentile returns the approximate duration at quantile q (0..1).

func (*Histogram) Reset

func (h *Histogram) Reset()

func (*Histogram) Snapshot

func (h *Histogram) Snapshot() HistogramSnapshot

func (*Histogram) SnapshotValue

func (h *Histogram) SnapshotValue() any

type HistogramSnapshot

type HistogramSnapshot struct {
	Name    string           `json:"name"`
	Count   int64            `json:"count"`
	Sum     time.Duration    `json:"sum"`
	Min     time.Duration    `json:"min"`
	Max     time.Duration    `json:"max"`
	Avg     time.Duration    `json:"avg"`
	Buckets map[string]int64 `json:"buckets"` // upper bound -> cumulative count
}

type Metric

type Metric interface {
	Name() string
	SnapshotValue() any
}

Metric is implemented by all registry instruments.

type Registry

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

Registry is a named collection of metrics.

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Counter

func (r *Registry) Counter(name string) *Counter

Counter returns the Counter by name, creating it if absent.

func (*Registry) Gauge

func (r *Registry) Gauge(name string) *Gauge

Gauge returns the Gauge by name, creating it if absent.

func (*Registry) Get

func (r *Registry) Get(name string) (Metric, bool)

func (*Registry) Histogram

func (r *Registry) Histogram(name string) *Histogram

Histogram returns the Histogram by name, creating it with default buckets if absent. For custom buckets, build with NewHistogram and pass to Register.

func (*Registry) Names

func (r *Registry) Names() []string

Names returns the sorted names of all registered metrics.

func (*Registry) Register

func (r *Registry) Register(m Metric)

Register stores m under its name, replacing any prior metric with that name.

func (*Registry) Snapshot

func (r *Registry) Snapshot() map[string]any

Snapshot returns name -> snapshot value for every registered metric.

Jump to

Keyboard shortcuts

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