metrics

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Duration

func Duration(sink Sink, name string, start time.Time, tags ...Tag)

Duration records elapsed time since start as a timer observation (ms).

func Shutdown

func Shutdown()

Shutdown closes the global Emitter.

Types

type FanoutSink

type FanoutSink []Sink

FanoutSink fans out every emission to all constituent sinks.

func (FanoutSink) Close

func (f FanoutSink) Close() error

func (FanoutSink) Counter

func (f FanoutSink) Counter(name string, val float32, tags ...Tag)

func (FanoutSink) Gauge

func (f FanoutSink) Gauge(name string, val float32, tags ...Tag)

func (FanoutSink) Rate

func (f FanoutSink) Rate(name string, val float32, tags ...Tag)

func (FanoutSink) Store

func (f FanoutSink) Store(name string, val float32, tags ...Tag)

func (FanoutSink) Timer

func (f FanoutSink) Timer(name string, val float32, tags ...Tag)

type GoMetricsSink

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

GoMetricsSink wraps the hashicorp/go-metrics global instance, giving access to all open-source backends (StatsD, Statsite, Prometheus, Circonus, DogStatsD, Stackdriver) through a single Sink.

func NewGoMetricsSink

func NewGoMetricsSink(serviceName string, disableHostname bool, fanout goMetrics.FanoutSink) (*GoMetricsSink, error)

NewGoMetricsSink creates the hashicorp/go-metrics global instance from the supplied fanout sinks and config.

func (*GoMetricsSink) Close

func (g *GoMetricsSink) Close() error

func (*GoMetricsSink) Counter

func (g *GoMetricsSink) Counter(name string, val float32, tags ...Tag)

func (*GoMetricsSink) Gauge

func (g *GoMetricsSink) Gauge(name string, val float32, tags ...Tag)

func (*GoMetricsSink) PrometheusEnabled

func (g *GoMetricsSink) PrometheusEnabled() bool

PrometheusEnabled reports whether a Prometheus sink was configured.

func (*GoMetricsSink) Rate

func (g *GoMetricsSink) Rate(name string, val float32, tags ...Tag)

func (*GoMetricsSink) Store

func (g *GoMetricsSink) Store(name string, val float32, tags ...Tag)

func (*GoMetricsSink) Timer

func (g *GoMetricsSink) Timer(name string, val float32, tags ...Tag)

type NoopSink

type NoopSink struct{}

NoopSink discards all emissions.

func (NoopSink) Close

func (NoopSink) Close() error

func (NoopSink) Counter

func (NoopSink) Counter(string, float32, ...Tag)

func (NoopSink) Gauge

func (NoopSink) Gauge(string, float32, ...Tag)

func (NoopSink) Rate

func (NoopSink) Rate(string, float32, ...Tag)

func (NoopSink) Store

func (NoopSink) Store(string, float32, ...Tag)

func (NoopSink) Timer

func (NoopSink) Timer(string, float32, ...Tag)

type Sink

type Sink interface {
	Counter(name string, val float32, tags ...Tag)
	Gauge(name string, val float32, tags ...Tag)
	Timer(name string, val float32, tags ...Tag)
	// Store records an arbitrary numeric observation.
	// Backends that lack a native store type should delegate to Gauge.
	Store(name string, val float32, tags ...Tag)
	// Rate records a rate observation.
	// Backends that lack a native rate type should delegate to Counter.
	Rate(name string, val float32, tags ...Tag)
	Close() error
}

Sink is the interface that every metrics backend must implement. Name is a dot-separated metric path (e.g. "console.request.count").

var Emitter Sink = NoopSink{}

Emitter is the package-level default Sink. It is set by Setup and read by call sites throughout the application.

func Setup

func Setup(cfg *config.Config) (Sink, http.Handler, error)

Setup initialises the metrics subsystem from cfg.Metrics, creates all configured backend sinks, and sets the package-level Emitter. Returns the Sink and a Prometheus HTTP handler (or nil).

type Tag

type Tag struct {
	Name  string
	Value string
}

Tag is a key-value pair attached to a metric emission.

func T

func T(name, value string) Tag

T is a shorthand for constructing a Tag.

Jump to

Keyboard shortcuts

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