clientinfo

package
v1.7.1-0...-bd36cd2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package clientinfo provides some tools useful for gathering and exposing system metrics and diagnostics 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 MetricObserver

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

MetricObserver represent a definition of a cyclic metric observation process.

func (*MetricObserver) Observe

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

Observe triggers a cyclic metric observation process.

type MetricObserverInput

type MetricObserverInput func() float64

MetricObserverInput defines a source of metric data.

type MetricObserverOutput

type MetricObserverOutput interface {
	Set(value float64)
}

MetricObserverOutput defines a destination of collected metric data.

type Registry

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

Registry performs all management of metrics and diagnostics. Specifically, it allows registering and exposing them through the HTTP server.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new client info registry.

func (*Registry) EnableServer

func (r *Registry) EnableServer(port int)

EnableServer enables the client info server on the given port. Data will be exposed on `/metrics` and `/diagnostics` paths.

func (*Registry) NewMetricGauge

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

NewMetricGauge 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) NewMetricGaugeObserver

func (r *Registry) NewMetricGaugeObserver(
	name string,
	input MetricObserverInput,
	labels ...Label,
) (*MetricObserver, error)

NewMetricGaugeObserver creates and registers a gauge just like `NewMetricGauge` method and wraps it with a ready to use observer of the provided input. This allows to easily create self-refreshing metrics.

func (*Registry) NewMetricInfo

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

NewMetricInfo 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.

func (*Registry) RegisterDiagnosticSource

func (r *Registry) RegisterDiagnosticSource(name string, source func() string)

RegisterDiagnosticSource registers diagnostics source callback with a given name. Name will be used as a key and callback result as a value in JSON object during composing diagnostics JSON. Note: function will override existing diagnostics source on attempt to register another one with the same name.

Jump to

Keyboard shortcuts

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