collector

package
v1.0.0-alpha.13 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCollectFunc

func WithCollectFunc(collectFunc func() (metricValue float64, labelValues []string)) options.Option[Metric]

WithCollectFunc allows to define a function that will be called each time when prometheus will scrap the data. Should be used when metric value can be read at any time and we don't need to attach to an event.

func WithHelp

func WithHelp(help string) options.Option[Metric]

WithHelp sets the help text for the metric.

func WithInitFunc

func WithInitFunc(initFunc func()) options.Option[Metric]

WithInitFunc allows to define a function that will be called once when metric is created. Should be used instead of WithCollectFunc when metric value needs to be collected on event. With this type of collection we need to make sure that we call one of update methods of collector e.g.: Increment, Update.

func WithInitValueFunc

func WithInitValueFunc(initValueFunc func() (metricValue float64, labelValues []string)) options.Option[Metric]

WithInitValueFunc allows to set function that sets an initial value for a metric.

func WithLabels

func WithLabels(labels ...string) options.Option[Metric]

WithLabels allows to define labels for the metric, they will need to be passed in the same order to the Update.

func WithMetric

func WithMetric(metric *Metric) options.Option[Collection]

func WithPruningDelay

func WithPruningDelay(pruningDelay time.Duration) options.Option[Metric]

WithPruningDelay sets the delay after which the metric will be pruned from the prometheus registry. The pruning is label-aware: if the metric has labels, the pruning delay will apply to any unique set of labels for this metric.

func WithResetBeforeCollecting

func WithResetBeforeCollecting(resetEnabled bool) options.Option[Metric]

WithResetBeforeCollecting if enabled there will be a reset call on metric before each collectFunction call.

func WithType

func WithType(t MetricType) options.Option[Metric]

WithType sets the metric type: Gauge, GaugeVec, Counter, CounterVec.

Types

type Collection

type Collection struct {
	CollectionName string
	// contains filtered or unexported fields
}

func NewCollection

func NewCollection(name string, opts ...options.Option[Collection]) *Collection

func (*Collection) GetMetric

func (c *Collection) GetMetric(metricName string) *Metric

type Collector

type Collector struct {
	Registry *prometheus.Registry
	// contains filtered or unexported fields
}

Collector is responsible for creation and collection of metrics for the prometheus.

func New

func New() *Collector

New creates an instance of Manager and creates a new prometheus registry for the protocol metrics collection.

func (*Collector) Collect

func (c *Collector) Collect()

Collect collects all metrics from the registered collections.

func (*Collector) DeleteLabels

func (c *Collector) DeleteLabels(subsystem string, metricName string, labelValues map[string]string)

DeleteLabels deletes the metric with the given labels values.

func (*Collector) Increment

func (c *Collector) Increment(subsystem string, metricName string, labels ...string)

Increment increments the value of the existing metric defined by the subsystem and metricName. Note that the label values must be passed in the same order as they were defined in the metric, and must match the number of labels defined in the metric.

func (*Collector) RegisterCollection

func (c *Collector) RegisterCollection(coll *Collection)

func (*Collector) ResetMetric

func (c *Collector) ResetMetric(namespace string, metricName string)

ResetMetric resets the metric with the given name.

func (*Collector) Shutdown

func (c *Collector) Shutdown()

func (*Collector) Update

func (c *Collector) Update(subsystem string, metricName string, metricValue float64, labelValues ...string)

Update updates the value of the existing metric defined by the subsystem and metricName. Note that the label values must be passed in the same order as they were defined in the metric, and must match the number of labels defined in the metric.

type Metric

type Metric struct {
	Name      string
	Type      MetricType
	Namespace string
	// contains filtered or unexported fields
}

Metric is a single metric that will be registered to prometheus registry and collected with WithCollectFunc callback. Metric can be collected periodically based on metric collection rate of prometheus or WithUpdateOnEvent callback can be provided, so the Metric will keep its internal representation of metrics value, and WithCollectFunc will use it instead requesting data directly form other components.

func NewMetric

func NewMetric(name string, opts ...options.Option[Metric]) *Metric

NewMetric creates a new metric with given name and options.

type MetricType

type MetricType uint8
const (
	// Gauge is a metric that represents a single numerical value that can arbitrarily go up and down.
	// During metric Update the collected value is set, thus previous value is overwritten.
	Gauge MetricType = iota
	// Counter is a cumulative metric that represents a single numerical value that only ever goes up.
	// During metric Update the collected value is added to its current value.
	Counter
)

Jump to

Keyboard shortcuts

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