metrics

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

README

go-orb/metrics

This package is a PoC/WIP, there are no implentations yet.

Documentation

Overview

Package metrics provides a Wrapper around hashicorp/go-metrics.

Index

Constants

View Source
const ComponentType = "metrics"

ComponentType is the components name.

Variables

View Source
var (
	// DefaultMetricsPlugin is the default metrics plugin to use.
	DefaultMetricsPlugin = "memory"
	// DefaultConfigSection is the section key used in config files used to configure the metrics options.
	DefaultConfigSection = "metrics"
)

Plugins is the plugins container for registries.

Functions

This section is empty.

Types

type Config

type Config struct {
	Plugin string // Plugin sets the metrics sink plugin to use.

	Hostname             string          // Hostname to use. If not provided and EnableHostname, it will be os.Hostname
	EnableHostname       bool            // Hostname to use. If not provided and EnableHostname, it will be os.Hostname
	EnableHostnameLabel  bool            // Enable prefixing gauge values with hostname
	EnableRuntimeMetrics bool            // Enables profiling of runtime metrics (GC, Goroutines, Memory)
	EnableTypePrefix     bool            // Prefixes key with a type ("counter", "gauge", "timer")
	TimerGranularity     config.Duration // Granularity of timers.
	ProfileInterval      config.Duration // Interval to profile runtime metrics

	AllowedPrefixes []string // A list of metric prefixes to allow, with '.' as the separator
	BlockedPrefixes []string // A list of metric prefixes to block, with '.' as the separator
	AllowedLabels   []string // A list of metric labels to allow, with '.' as the separator
	BlockedLabels   []string // A list of metric labels to block, with '.' as the separator
	FilterDefault   bool     // Whether to allow metrics by default
}

Config contains the metrics config.

func NewConfig

func NewConfig(opts ...Option) *Config

NewConfig creates a new config with the defaults and applys opts on top.

type ConfigType

type ConfigType interface {
	// contains filtered or unexported methods
}

ConfigType is a wrapper for config, so we can pass it back to the this plugin handler.

type Label

type Label struct {
	Name  string
	Value string
}

Label is Metrics label.

type Metrics

type Metrics interface {
	types.Component

	SetGauge(key []string, val float32)                           // Set gauge key and value with 32 bit precision
	SetGaugeWithLabels(key []string, val float32, labels []Label) // Set gauge key and value with 32 bit precision
	SetPrecisionGauge(key []string, val float64)
	SetPrecisionGaugeWithLabels(key []string, val float64, labels []Label)
	EmitKey(key []string, val float32)
	IncrCounter(key []string, val float32)
	IncrCounterWithLabels(key []string, val float32, labels []Label)
	AddSample(key []string, val float32)
	AddSampleWithLabels(key []string, val float32, labels []Label)
	MeasureSince(key []string, start time.Time)
	MeasureSinceWithLabels(key []string, start time.Time, labels []Label)
	// UpdateFilter overwrites the existing filter with the given rules.
	UpdateFilter(allow, block []string)
	// UpdateFilterAndLabels overwrites the existing filter with the given rules.
	UpdateFilterAndLabels(allow, block, allowedLabels, blockedLabels []string)
	// Emits various runtime statsitics
	EmitRuntimeStats()
}

Metrics contains all hashicorp/go-metrics.Metrics methods we have found so far.

type Option

type Option func(ConfigType)

Option is a logger WithXXX Option.

type ProviderFunc

type ProviderFunc func(
	svcCtx *cli.ServiceContextWithConfig,
	logger log.Logger,
	opts ...Option,
) (Type, error)

ProviderFunc is provider function type is used to create a new metrics plugin.

type Type

type Type struct {
	Metrics
}

Type is the registry type it is returned when you use metrics.Provide which selects a registry to use based on the plugin configuration.

func Provide

func Provide(
	svcCtx *cli.ServiceContextWithConfig,
	components *types.Components,
	logger log.Logger,
	opts ...Option,
) (Type, error)

Provide is the metrics provider for wire. It parses the config from "configs", fetches the "Plugin" from the config and then forwards all it's arguments to the factory which it get's from "Plugins".

Jump to

Keyboard shortcuts

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