Help us shape the future of Go! Take the 2026 Go Developer Survey

metrics

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrometheusHandler added in v1.0.1

func PrometheusHandler() http.Handler

PrometheusHandler returns a standard /metrics http.Handler if the Prometheus client is linked; otherwise returns http.NotFoundHandler. This indirection avoids hard dependency on the Prometheus client.

Types

type Labels

type Labels map[string]string

Labels is a simple key:value map for metric dimensions.

type MetricsRecorder

type MetricsRecorder interface {
	IncCounter(name string, labels Labels)
	ObserveHistogram(name string, value float64, labels Labels)
}

MetricsRecorder captures counters and histograms.

type Middleware

type Middleware struct {
	M MetricsRecorder
}

Middleware instruments HTTP traffic using a provided recorder.

func New

New constructs a metrics middleware.

func (*Middleware) Handler

func (mw *Middleware) Handler(next http.Handler) http.Handler

Handler wraps the next handler to record counters and duration.

func (*Middleware) HandlerFunc added in v1.0.1

func (mw *Middleware) HandlerFunc() func(http.Handler) http.Handler

HandlerFunc exposes middleware as a plain function for router use.

func (*Middleware) Middleware added in v1.0.2

func (mw *Middleware) Middleware() func(http.Handler) http.Handler

Middleware implements ports.Middleware by returning Handler.

type NoopMetrics

type NoopMetrics struct{}

NoopMetrics is the default. Swap later for Prometheus, etc.

func (NoopMetrics) IncCounter

func (NoopMetrics) IncCounter(_ string, _ Labels)

func (NoopMetrics) ObserveHistogram

func (NoopMetrics) ObserveHistogram(_ string, _ float64, _ Labels)

type PrometheusRecorder added in v1.0.1

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

PrometheusRecorder implements MetricsRecorder using Prometheus client. This is a minimal adapter; applications can supply their own recorder.

func NewPrometheusRecorder added in v1.0.1

func NewPrometheusRecorder(registerer prometheus.Registerer, buckets []float64) *PrometheusRecorder

NewPrometheusRecorder wires counters and histograms with standard names. Consumers may pass a custom registerer (e.g. for testing). When nil, the default Prometheus registerer is used.

func (*PrometheusRecorder) IncCounter added in v1.0.1

func (p *PrometheusRecorder) IncCounter(_ string, labels Labels)

func (*PrometheusRecorder) ObserveHistogram added in v1.0.1

func (p *PrometheusRecorder) ObserveHistogram(_ string, value float64, labels Labels)

Jump to

Keyboard shortcuts

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