metrics

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: MIT Imports: 9 Imported by: 2

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.

func (*Gauge) Set

func (g *Gauge) Set(value float64)

Set allows setting the gauge to an arbitrary value.

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.

func NewLabel

func NewLabel(name, value string) Label

NewLabel creates a new label using the given name and value.

type Observer

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

Observer represent a definition of a cyclic metric observation process.

func (*Observer) Observe

func (o *Observer) Observe(
	ctx context.Context,
	tick time.Duration,
)

Observe triggers 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 NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new metrics registry.

func (*Registry) EnableServer

func (r *Registry) EnableServer(port int)

EnableServer enables the metrics server on the given port. Data will be exposed on `/metrics` path.

func (*Registry) NewGauge

func (r *Registry) NewGauge(
	name string,
	labels ...Label,
) (*Gauge, error)

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.

func (*Registry) NewInfo

func (r *Registry) NewInfo(
	name string,
	labels []Label,
) (*Info, error)

NewInfo creates and registers a new info metric which will be exposed through the metrics server. In case a metric already exists, an error will be returned.

Jump to

Keyboard shortcuts

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