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

prometheus

package
v5.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultBuckets = []stats.Value{
	stats.ValueOf(0.005),
	stats.ValueOf(0.01),
	stats.ValueOf(0.025),
	stats.ValueOf(0.05),
	stats.ValueOf(0.1),
	stats.ValueOf(0.25),
	stats.ValueOf(0.5),
	stats.ValueOf(1.0),
	stats.ValueOf(2.5),
	stats.ValueOf(5.0),
	stats.ValueOf(10.0),
}

DefaultBuckets is the bucket set used for histograms that have no boundaries registered in stats.Buckets or in Handler.Buckets.

The boundaries are the ones used by the reference Prometheus client, chosen for request latencies measured in seconds. stats.Duration values are converted to seconds before bucketing, so timing histograms land on this range without configuration.

They are a starting point, not a substitute for choosing boundaries: a bucketed percentile is only as accurate as the bucket it falls in, and a histogram whose values sit outside this range lands entirely in the +Inf bucket. Register real boundaries with Engine.SetBuckets wherever p99 accuracy matters.

Programs may replace this during initialization, before any measure is handled.

View Source
var DefaultHandler = &Handler{
	TrimPrefix: stats.DefaultEngine.Prefix,
}

DefaultHandler is a prometheus handler configured to trim the default metric namespace off of metrics that it handles.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// Setting this field will trim this prefix from metric namespaces of the
	// metrics received by this handler.
	//
	// Unlike statsd-like systems, it is common for prometheus metrics to not
	// be prefixed and instead use labels to identify which service or group
	// of services the metrics are coming from. The intent of this field is to
	// provide support for this use case.
	//
	// Note that trimming only applies to the metric namespace, the metric
	// name will always be left untouched.
	//
	// If empty, no prefix trimming is done.
	TrimPrefix string

	// MetricTimeout defines how long the handler exposes metrics that aren't
	// receiving updates.
	//
	// The default is to use a 2 minutes metric timeout.
	MetricTimeout time.Duration

	// Buckets is the registry of histogram buckets used by the handler,
	// If nil, stats.Buckets is used instead.
	//
	// Histograms with no entry in the registry fall back to DefaultBuckets.
	Buckets stats.HistogramBuckets
	// contains filtered or unexported fields
}

Handler is a type that bridges the stats API to a prometheus-compatible HTTP endpoint.

Typically, a program creates one Handler, registers it to the stats package, and adds it to the muxer used by the application under the /metrics path.

Histograms with no buckets registered in Buckets — or in stats.Buckets when that field is nil — are published with DefaultBuckets rather than with no bucket series at all.

func (*Handler) HandleMeasures

func (h *Handler) HandleMeasures(mtime time.Time, measures ...stats.Measure)

HandleMeasures satisfies the stats.Handler interface.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(res http.ResponseWriter, req *http.Request)

ServeHTTP satisfies the http.Handler interface.

func (*Handler) WriteStats

func (h *Handler) WriteStats(w io.Writer)

WriteStats accepts a writer and pushes metrics (one at a time) to it. An example could be if you just want to print all the metrics on to Stdout It will not call flush. Make sure the Close and Flush are handled at the caller.

Jump to

Keyboard shortcuts

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