metrics

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func N

func N(namespace, subsystem, name string) string

N produces name of the metric.

func Time

func Time(t time.Time) float64

Time turns time into float64 accepted by metric.

Types

type Label

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

Label defines the metric label.

func L

func L(name, value string) Label

L produces label for metric.

type Set

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

Set is the wrapper around metric set, adding standard labels to all the metrics.

func NewSet

func NewSet() *Set

NewSet creates new metric set.

func (*Set) AddLabels

func (s *Set) AddLabels(labels ...Label)

AddLabels defines labels which are added to all the metrics in the set.

func (*Set) GetOrCreateCounter

func (s *Set) GetOrCreateCounter(name string, labels ...Label) *metrics.Counter

GetOrCreateCounter returns registered counter in s with the given name or creates new counter if s doesn't contain counter with the given name.

name must be valid Prometheus-compatible metric with possible labels. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

The returned counter is safe to use from concurrent goroutines.

Performance tip: prefer NewCounter instead of GetOrCreateCounter.

func (*Set) GetOrCreateFloatCounter

func (s *Set) GetOrCreateFloatCounter(name string, labels ...Label) *metrics.FloatCounter

GetOrCreateFloatCounter returns registered FloatCounter in s with the given name or creates new FloatCounter if s doesn't contain FloatCounter with the given name.

name must be valid Prometheus-compatible metric with possible labels. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

The returned FloatCounter is safe to use from concurrent goroutines.

Performance tip: prefer NewFloatCounter instead of GetOrCreateFloatCounter.

func (*Set) GetOrCreateGauge

func (s *Set) GetOrCreateGauge(name string, labels ...Label) *metrics.Gauge

GetOrCreateGauge returns registered gauge with the given name in s or creates new gauge if s doesn't contain gauge with the given name.

name must be valid Prometheus-compatible metric with possible labels. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

The returned gauge is safe to use from concurrent goroutines.

Performance tip: prefer NewGauge instead of GetOrCreateGauge.

func (*Set) GetOrCreateHistogram

func (s *Set) GetOrCreateHistogram(name string, labels ...Label) *metrics.Histogram

GetOrCreateHistogram returns registered histogram in s with the given name or creates new histogram if s doesn't contain histogram with the given name.

name must be valid Prometheus-compatible metric with possible labels. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

The returned histogram is safe to use from concurrent goroutines.

Performance tip: prefer NewHistogram instead of GetOrCreateHistogram.

func (*Set) GetOrCreatePrometheusHistogram

func (s *Set) GetOrCreatePrometheusHistogram(name string, labels ...Label) *metrics.PrometheusHistogram

GetOrCreatePrometheusHistogram returns registered prometheus histogram in s with the given name or creates new histogram if s doesn't contain histogram with the given name.

name must be valid Prometheus-compatible metric with possible labels. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

The returned histogram is safe to use from concurrent goroutines.

Performance tip: prefer NewPrometheusHistogram instead of GetOrCreatePrometheusHistogram.

func (*Set) GetOrCreatePrometheusHistogramExt

func (s *Set) GetOrCreatePrometheusHistogramExt(
	name string,
	upperBounds []float64,
	labels ...Label,
) *metrics.PrometheusHistogram

GetOrCreatePrometheusHistogramExt returns registered prometheus histogram in s with the given name or creates new histogram if s doesn't contain histogram with the given name.

name must be valid Prometheus-compatible metric with possible labels. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

The returned histogram is safe to use from concurrent goroutines.

Performance tip: prefer NewPrometheusHistogramExt instead of GetOrCreatePrometheusHistogramExt.

func (*Set) GetOrCreateSummary

func (s *Set) GetOrCreateSummary(name string, labels ...Label) *metrics.Summary

GetOrCreateSummary returns registered summary with the given name in s or creates new summary if s doesn't contain summary with the given name.

name must be valid Prometheus-compatible metric with possible labels. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

The returned summary is safe to use from concurrent goroutines.

Performance tip: prefer NewSummary instead of GetOrCreateSummary.

func (*Set) GetOrCreateSummaryExt

func (s *Set) GetOrCreateSummaryExt(
	name string,
	window time.Duration,
	quantiles []float64,
	labels ...Label,
) *metrics.Summary

GetOrCreateSummaryExt returns registered summary with the given name, window and quantiles in s or creates new summary if s doesn't contain summary with the given name.

name must be valid Prometheus-compatible metric with possible labels. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

The returned summary is safe to use from concurrent goroutines.

Performance tip: prefer NewSummaryExt instead of GetOrCreateSummaryExt.

func (*Set) NewCounter

func (s *Set) NewCounter(name string, labels ...Label) *metrics.Counter

NewCounter registers and returns new counter with the given name in the s.

name must be valid Prometheus-compatible metric with possible labels. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

The returned counter is safe to use from concurrent goroutines.

func (*Set) NewFloatCounter

func (s *Set) NewFloatCounter(name string, labels ...Label) *metrics.FloatCounter

NewFloatCounter registers and returns new FloatCounter with the given name in the s.

name must be valid Prometheus-compatible metric with possible labels. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

The returned FloatCounter is safe to use from concurrent goroutines.

func (*Set) NewGauge

func (s *Set) NewGauge(name string, labels ...Label) *metrics.Gauge

NewGauge registers and returns gauge with the given name in s, which calls f to obtain gauge value.

name must be valid Prometheus-compatible metric with possible labels. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

f must be safe for concurrent calls.

The returned gauge is safe to use from concurrent goroutines.

func (*Set) NewHistogram

func (s *Set) NewHistogram(name string, labels ...Label) *metrics.Histogram

NewHistogram creates and returns new histogram in s with the given name.

name must be valid Prometheus-compatible metric with possible labels. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

The returned histogram is safe to use from concurrent goroutines.

func (*Set) NewPrometheusHistogram

func (s *Set) NewPrometheusHistogram(name string, labels ...Label) *metrics.PrometheusHistogram

NewPrometheusHistogram creates and returns new PrometheusHistogram in s with the given name and PrometheusHistogramDefaultBuckets.

name must be valid Prometheus-compatible metric with possible labels. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

The returned histogram is safe to use from concurrent goroutines.

func (*Set) NewPrometheusHistogramExt

func (s *Set) NewPrometheusHistogramExt(
	name string,
	upperBounds []float64,
	labels ...Label,
) *metrics.PrometheusHistogram

NewPrometheusHistogramExt creates and returns new PrometheusHistogram in s with the given name and upperBounds.

name must be valid Prometheus-compatible metric with possible labels. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

The returned histogram is safe to use from concurrent goroutines.

func (*Set) NewSummary

func (s *Set) NewSummary(name string, labels ...Label) *metrics.Summary

NewSummary creates and returns new summary with the given name in s.

name must be valid Prometheus-compatible metric with possible labels. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

The returned summary is safe to use from concurrent goroutines.

func (*Set) NewSummaryExt

func (s *Set) NewSummaryExt(name string, window time.Duration, quantiles []float64, labels ...Label) *metrics.Summary

NewSummaryExt creates and returns new summary in s with the given name, window and quantiles.

name must be valid Prometheus-compatible metric with possible labels. For instance,

  • foo
  • foo{bar="baz"}
  • foo{bar="baz",aaa="b"}

The returned summary is safe to use from concurrent goroutines.

func (*Set) WritePrometheus

func (s *Set) WritePrometheus(w io.Writer)

WritePrometheus writes all the metrics from s to w in Prometheus format.

Jump to

Keyboard shortcuts

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