telemetry

package
v2.0.0-...-ca14b28 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FormatDefault    = ""
	FormatPrometheus = "prometheus"
	FormatText       = "text"
	ContentTypeText  = `text/plain; version=` + expfmt.TextVersion + `; charset=utf-8`

	MetricSinkInMem      = "mem"
	MetricSinkStatsd     = "statsd"
	MetricSinkDogsStatsd = "dogstatsd"
)

Metrics supported format types.

Variables

View Source
var GlobalLabels = []metrics.Label{} // nolint: ignore // false positive

GlobalLabels defines the set of global labels that will be applied to all metrics emitted using the telemetry package function wrappers.

Functions

func NewLabel

func NewLabel(name, value string) metrics.Label

NewLabel creates a new instance of Label with name and value

Types

type Config

type Config struct {
	// Prefixed with keys to separate services
	ServiceName string `mapstructure:"service-name" toml:"service-name" comment:"Prefixed with keys to separate services."`

	// Enabled enables the application telemetry functionality. When enabled,
	// an in-memory sink is also enabled by default. Operators may also enabled
	// other sinks such as Prometheus.
	Enabled bool `` /* 223-byte string literal not displayed */

	// Enable prefixing gauge values with hostname
	EnableHostname bool `mapstructure:"enable-hostname" toml:"enable-hostname" comment:"Enable prefixing gauge values with hostname."`

	// Enable adding hostname to labels
	EnableHostnameLabel bool `mapstructure:"enable-hostname-label" toml:"enable-hostname-label" comment:"Enable adding hostname to labels."`

	// Enable adding service to labels
	EnableServiceLabel bool `mapstructure:"enable-service-label" toml:"enable-service-label" comment:"Enable adding service to labels."`

	// PrometheusRetentionTime, when positive, enables a Prometheus metrics sink.
	// It defines the retention duration in seconds.
	PrometheusRetentionTime int64 `` /* 204-byte string literal not displayed */

	// GlobalLabels defines a global set of name/value label tuples applied to all
	// metrics emitted using the wrapper functions defined in telemetry package.
	//
	// Example:
	// [["chain_id", "cosmoshub-1"]]
	GlobalLabels [][]string `` /* 257-byte string literal not displayed */

	// MetricsSink defines the type of metrics backend to use.
	MetricsSink string `` /* 126-byte string literal not displayed */

	// StatsdAddr defines the address of a statsd server to send metrics to.
	// Only utilized if MetricsSink is set to "statsd" or "dogstatsd".
	StatsdAddr string `` /* 192-byte string literal not displayed */

	// DatadogHostname defines the hostname to use when emitting metrics to
	// Datadog. Only utilized if MetricsSink is set to "dogstatsd".
	DatadogHostname string `` /* 198-byte string literal not displayed */
}

type DisplayableSink

type DisplayableSink interface {
	DisplayMetrics(resp http.ResponseWriter, req *http.Request) (any, error)
}

DisplayableSink is an interface that defines a method for displaying metrics.

type GatherResponse

type GatherResponse struct {
	Metrics     []byte
	ContentType string
}

GatherResponse is the response type of registered metrics

type Metrics

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

Metrics defines a wrapper around application telemetry functionality. It allows metrics to be gathered at any point in time. When creating a Metrics object, internally, a global metrics is registered with a set of sinks as configured by the operator. In addition to the sinks, when a process gets a SIGUSR1, a dump of formatted recent metrics will be sent to STDERR.

func New

func New(cfg Config) (_ *Metrics, rerr error)

New creates a new instance of Metrics

func RegisterMetrics

func RegisterMetrics(r mux.Router, cfg Config) (*Metrics, error)

func (*Metrics) Gather

func (m *Metrics) Gather(format string) (GatherResponse, error)

Gather collects all registered metrics and returns a GatherResponse where the metrics are encoded depending on the type. Metrics are either encoded via Prometheus or JSON if in-memory.

Jump to

Keyboard shortcuts

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