Documentation ¶
Overview ¶
Package `metrics` provides some tools useful for gathering and exposing system metrics for external monitoring tools.
Currently, this package is intended to use with Prometheus but can be easily extended if needed. Also, not all Prometheus metric types are implemented.
Following specifications were used as reference: - https://prometheus.io/docs/instrumenting/writing_clientlibs/ - https://prometheus.io/docs/instrumenting/exposition_formats/
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Gauge ¶
type Gauge struct {
// contains filtered or unexported fields
}
Gauge is a metric type that represents a single numerical value that can arbitrarily go up and down.
type Info ¶
type Info struct {
// contains filtered or unexported fields
}
Info is a metric type that represents a constant information that cannot change in the time.
type Label ¶
type Label struct {
// contains filtered or unexported fields
}
Label represents an arbitrary information attached to the metrics.
type Observer ¶
type Observer struct {
// contains filtered or unexported fields
}
Observer represent a definition of a cyclic metric observation process.
type ObserverInput ¶
type ObserverInput func() float64
ObserverInput defines a source of metric data.
type ObserverOutput ¶
type ObserverOutput interface {
Set(value float64)
}
ObserverOutput defines a destination of collected metric data.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry performs all management of metrics. Specifically, it allows to registering new metrics and exposing them through the metrics server.
func (*Registry) EnableServer ¶
EnableServer enables the metrics server on the given port. Data will be exposed on `/metrics` path.
func (*Registry) NewGauge ¶
NewGauge creates and registers a new gauge metric which will be exposed through the metrics server. In case a metric already exists, an error will be returned.
func (*Registry) NewGaugeObserver ¶
func (r *Registry) NewGaugeObserver( name string, input ObserverInput, labels ...Label, ) (*Observer, error)
NewGaugeObserver creates and registers a gauge just like `NewGauge` method and wrap it with a ready to use observer of the provided input. This allows to easily create self-refreshing metrics.