metrics

package
v0.0.0-...-06766a3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package metrics provides thread-safe metric primitives for collecting application telemetry data including counters, gauges, and histograms.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BucketSnapshot

type BucketSnapshot struct {
	UpperBound float64
	Count      uint64
}

type Counter

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

func (*Counter) Add

func (m *Counter) Add(value uint64) uint64

func (*Counter) Inc

func (m *Counter) Inc() uint64

func (*Counter) Load

func (m *Counter) Load() uint64

type Gauge

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

func (*Gauge) Load

func (m *Gauge) Load() float64

func (*Gauge) Store

func (m *Gauge) Store(value float64)

type Histogram

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

func NewHistogram

func NewHistogram(bounds []float64) *Histogram

func (*Histogram) Observe

func (m *Histogram) Observe(value float64)

Observe records a new value. Complexity: O(log N) for search + O(1) for atomic write.

func (*Histogram) Snapshot

func (m *Histogram) Snapshot() []BucketSnapshot

Snapshot returns a snapshot of the histogram buckets.

type Labels

type Labels map[string]string

func (Labels) Clone

func (a Labels) Clone() Labels

func (Labels) Equals

func (a Labels) Equals(b Labels) bool

type Metric

type Metric[T any] struct {
	ID    MetricID
	Value T
}

type MetricID

type MetricID struct {
	Name   string
	Labels Labels
}

func (MetricID) Clone

func (a MetricID) Clone() MetricID

func (MetricID) Equals

func (a MetricID) Equals(b MetricID) bool

type MetricMap

type MetricMap[T any] struct {
	// contains filtered or unexported fields
}

MetricMap is a concurrent-safe hash-addressed collection of metrics.

It maps a composite label set to a single metric instance using FNV-1a hashing with collision handling. The hash function and storage layout are internal implementation details.

func NewMetricMap

func NewMetricMap[T any]() *MetricMap[T]

func (*MetricMap[T]) GetOrCreate

func (m *MetricMap[T]) GetOrCreate(id MetricID, create func() T) T

GetOrCreate returns the metric for the given label list, creating it via create if it does not yet exist.

func (*MetricMap[T]) Metrics

func (m *MetricMap[T]) Metrics() []Metric[T]

Metrics returns a slice of references of all stored metrics.

Jump to

Keyboard shortcuts

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