Documentation ¶
Overview ¶
Package prometheus exposes go-metrics into a Prometheus format.
Index ¶
- Constants
- Variables
- func Get(name string) interface{}
- func GetOrCreateGaugeFunc(s string, f func() float64) prometheus.GaugeFunc
- func GetOrCreateHistogram(s string) prometheus.Histogram
- func Handler(reg Registry) http.Handler
- func NewCounter(name string, help ...string) (prometheus.Counter, error)
- func NewGauge(name string, help ...string) (prometheus.Gauge, error)
- func NewGaugeFunc(name string, f func() float64, help ...string) (prometheus.GaugeFunc, error)
- func NewHistogram(name string, help ...string) (prometheus.Histogram, error)
- func NewSummary(name string, window time.Duration, quantiles map[float64]float64, ...) (prometheus.Summary, error)
- func Setup(address string, log log.Logger) *http.ServeMux
- type Counter
- type DuplicateMetric
- type Registry
- type Set
- func (s *Set) Collect(ch chan<- prometheus.Metric)
- func (s *Set) Describe(ch chan<- *prometheus.Desc)
- func (s *Set) GetOrCreateCounter(name string, help ...string) prometheus.Counter
- func (s *Set) GetOrCreateGauge(name string, help ...string) prometheus.Gauge
- func (s *Set) GetOrCreateGaugeFunc(name string, f func() float64, help ...string) prometheus.GaugeFunc
- func (s *Set) GetOrCreateHistogram(name string, help ...string) prometheus.Histogram
- func (s *Set) GetOrCreateSummary(name string, help ...string) prometheus.Summary
- func (s *Set) GetOrCreateSummaryExt(name string, window time.Duration, quantiles map[float64]float64, ...) prometheus.Summary
- func (s *Set) ListMetricNames() []string
- func (s *Set) NewCounter(name string, help ...string) (prometheus.Counter, error)
- func (s *Set) NewGauge(name string, help ...string) (prometheus.Gauge, error)
- func (s *Set) NewGaugeFunc(name string, f func() float64, help ...string) (prometheus.GaugeFunc, error)
- func (s *Set) NewHistogram(name string, help ...string) (prometheus.Histogram, error)
- func (s *Set) NewSummary(name string, help ...string) (prometheus.Summary, error)
- func (s *Set) UnregisterAllMetrics()
- func (s *Set) UnregisterMetric(name string) bool
- type StandardRegistry
- func (r *StandardRegistry) Each(f func(string, interface{}))
- func (r *StandardRegistry) Get(name string) interface{}
- func (r *StandardRegistry) GetOrRegister(name string, i interface{}) interface{}
- func (r *StandardRegistry) Register(name string, i interface{}) error
- func (r *StandardRegistry) Unregister(name string)
- func (r *StandardRegistry) UnregisterAll()
- type Stoppable
- type Summary
Constants ¶
const UsePrometheusClient = false
Variables ¶
var ( DefaultRegistry = NewRegistry() EphemeralRegistry = NewRegistry() AccountingRegistry = NewRegistry() // registry used in swarm )
var EnabledExpensive = false
Functions ¶
func Get ¶
func Get(name string) interface{}
Get the metric by the given name or nil if none is registered.
func GetOrCreateGaugeFunc ¶
func GetOrCreateGaugeFunc(s string, f func() float64) prometheus.GaugeFunc
func GetOrCreateHistogram ¶
func GetOrCreateHistogram(s string) prometheus.Histogram
func Handler ¶
Handler returns an HTTP handler which dump metrics in Prometheus format. Output format can be cheched here: https://o11y.tools/metricslint/
func NewCounter ¶
func NewCounter(name string, help ...string) (prometheus.Counter, error)
func NewGaugeFunc ¶
func NewHistogram ¶
func NewHistogram(name string, help ...string) (prometheus.Histogram, error)
func NewSummary ¶
func NewSummary(name string, window time.Duration, quantiles map[float64]float64, help ...string) (prometheus.Summary, error)
NewSummary 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.
Types ¶
type Counter ¶
func GetOrCreateCounter ¶
type DuplicateMetric ¶
type DuplicateMetric string
DuplicateMetric is the error returned by Registry.Register when a metric already exists. If you mean to Register that metric you must first Unregister the existing metric.
func (DuplicateMetric) Error ¶
func (err DuplicateMetric) Error() string
type Registry ¶
type Registry interface { // Call the given function for each registered metric. Each(func(string, interface{})) // Get the metric by the given name or nil if none is registered. Get(string) interface{} // Gets an existing metric or registers the given one. // The interface can be the metric to register if not found in registry, // or a function returning the metric for lazy instantiation. GetOrRegister(string, interface{}) interface{} // Register the given metric under the given name. Register(string, interface{}) error // Unregister the metric with the given name. Unregister(string) // Unregister all metrics. (Mostly for testing.) UnregisterAll() }
A Registry holds references to a set of metrics by name and can iterate over them, calling callback functions provided by the user.
This is an interface so as to encourage other structs to implement the Registry API as appropriate.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is a set of metrics.
Metrics belonging to a set are exported separately from global metrics.
Set.WritePrometheus must be called for exporting metrics from the set.
func NewSet ¶
func NewSet() *Set
NewSet creates new set of metrics.
Pass the set to RegisterSet() function in order to export its metrics via global WritePrometheus() call.
func (*Set) Collect ¶
func (s *Set) Collect(ch chan<- prometheus.Metric)
func (*Set) Describe ¶
func (s *Set) Describe(ch chan<- *prometheus.Desc)
func (*Set) GetOrCreateCounter ¶
func (s *Set) GetOrCreateCounter(name string, help ...string) prometheus.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) GetOrCreateGauge ¶
func (s *Set) GetOrCreateGauge(name string, help ...string) prometheus.Gauge
GetOrCreateGaugeFunc 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) GetOrCreateGaugeFunc ¶
func (s *Set) GetOrCreateGaugeFunc(name string, f func() float64, help ...string) prometheus.GaugeFunc
GetOrCreateGaugeFunc 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, help ...string) prometheus.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) GetOrCreateSummary ¶
func (s *Set) GetOrCreateSummary(name string, help ...string) prometheus.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 map[float64]float64, help ...string) prometheus.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) ListMetricNames ¶
ListMetricNames returns sorted list of all the metrics in s.
func (*Set) NewCounter ¶
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) NewGauge ¶
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) NewGaugeFunc ¶
func (s *Set) NewGaugeFunc(name string, f func() float64, help ...string) (prometheus.GaugeFunc, error)
NewGaugeFunc 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 ¶
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) NewSummary ¶
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) UnregisterAllMetrics ¶
func (s *Set) UnregisterAllMetrics()
UnregisterAllMetrics de-registers all metrics registered in s.
func (*Set) UnregisterMetric ¶
UnregisterMetric removes metric with the given name from s.
True is returned if the metric has been removed. False is returned if the given metric is missing in s.
type StandardRegistry ¶
type StandardRegistry struct {
// contains filtered or unexported fields
}
The standard implementation of a Registry is a mutex-protected map of names to metrics.
func (*StandardRegistry) Each ¶
func (r *StandardRegistry) Each(f func(string, interface{}))
Call the given function for each registered metric.
func (*StandardRegistry) Get ¶
func (r *StandardRegistry) Get(name string) interface{}
Get the metric by the given name or nil if none is registered.
func (*StandardRegistry) GetOrRegister ¶
func (r *StandardRegistry) GetOrRegister(name string, i interface{}) interface{}
Gets an existing metric or creates and registers a new one. Threadsafe alternative to calling Get and Register on failure. The interface can be the metric to register if not found in registry, or a function returning the metric for lazy instantiation.
func (*StandardRegistry) Register ¶
func (r *StandardRegistry) Register(name string, i interface{}) error
Register the given metric under the given name. Returns a DuplicateMetric if a metric by the given name is already registered.
func (*StandardRegistry) Unregister ¶
func (r *StandardRegistry) Unregister(name string)
Unregister the metric with the given name.
func (*StandardRegistry) UnregisterAll ¶
func (r *StandardRegistry) UnregisterAll()
Unregister all metrics. (Mostly for testing.)