Documentation ¶
Index ¶
- func WithCollectFunc(collectFunc func() (metricValue float64, labelValues []string)) options.Option[Metric]
- func WithHelp(help string) options.Option[Metric]
- func WithInitFunc(initFunc func()) options.Option[Metric]
- func WithInitValueFunc(initValueFunc func() (metricValue float64, labelValues []string)) options.Option[Metric]
- func WithLabels(labels ...string) options.Option[Metric]
- func WithMetric(metric *Metric) options.Option[Collection]
- func WithPruningDelay(pruningDelay time.Duration) options.Option[Metric]
- func WithResetBeforeCollecting(resetEnabled bool) options.Option[Metric]
- func WithType(t MetricType) options.Option[Metric]
- type Collection
- type Collector
- func (c *Collector) Collect()
- func (c *Collector) DeleteLabels(subsystem string, metricName string, labelValues map[string]string)
- func (c *Collector) Increment(subsystem string, metricName string, labels ...string)
- func (c *Collector) RegisterCollection(collection *Collection)
- func (c *Collector) ResetMetric(namespace string, metricName string)
- func (c *Collector) Shutdown()
- func (c *Collector) Update(subsystem string, metricName string, metricValue float64, ...)
- type Metric
- type MetricType
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 WithInitFunc ¶
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 ¶
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 ¶
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 ¶
WithResetBeforeCollecting if enabled there will be a reset call on metric before each collectFunction call.
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 ¶
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(collection *Collection)
func (*Collector) ResetMetric ¶
ResetMetric resets the metric with the given name.
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.
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 )