metrics

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package metrics provides basic metrics collection (counters, timers, gauges).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

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

Counter is a monotonically increasing counter.

func (*Counter) Add

func (c *Counter) Add(n int64)

Add adds n to the counter.

func (*Counter) Inc

func (c *Counter) Inc()

Inc increments the counter by 1.

func (*Counter) Value

func (c *Counter) Value() int64

Value returns the current value.

type Gauge

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

Gauge is a value that can go up and down.

func (*Gauge) Dec

func (g *Gauge) Dec()

Dec decrements the gauge by 1.

func (*Gauge) Inc

func (g *Gauge) Inc()

Inc increments the gauge by 1.

func (*Gauge) Set

func (g *Gauge) Set(v int64)

Set sets the gauge value.

func (*Gauge) Value

func (g *Gauge) Value() int64

Value returns the current value.

type Registry

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

Registry manages named metrics.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new metrics registry.

func (*Registry) Counter

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

Counter returns or creates a counter.

func (*Registry) Format

func (r *Registry) Format() string

Format returns a formatted string of all metrics.

func (*Registry) Gauge

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

Gauge returns or creates a gauge.

func (*Registry) Snapshot

func (r *Registry) Snapshot() map[string]interface{}

Snapshot returns a snapshot of all metrics.

func (*Registry) Timer

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

Timer returns or creates a timer.

type Timer

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

Timer tracks timing information.

func NewTimer

func NewTimer() *Timer

NewTimer creates a new timer.

func (*Timer) Record

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

Record records a duration.

func (*Timer) Stats

func (t *Timer) Stats() TimerStats

Stats returns timer statistics.

func (*Timer) Time

func (t *Timer) Time(fn func()) time.Duration

Time executes fn and records its duration.

type TimerStats

type TimerStats struct {
	Count int64         `json:"count"`
	Total time.Duration `json:"total"`
	Mean  time.Duration `json:"mean"`
	Min   time.Duration `json:"min"`
	Max   time.Duration `json:"max"`
}

TimerStats represents timer statistics.

Jump to

Keyboard shortcuts

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