metrics

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCounter

func NewCounter(opts CounterOpts) prometheus.Counter

NewCounter created a new prometheus.Counter metric with the Warmup feature.

func NewHistogram

func NewHistogram(opts HistogramOpts) prometheus.Histogram

NewHistogram created a new prometheus.Histogram metric with the Warmup feature.

func NewSummary

func NewSummary(opts SummaryOpts) prometheus.Summary

NewSummary created a new prometheus.Summary metric with the Warmup feature.

func RestoreNowTime

func RestoreNowTime()

RestoreNowTime restores the 'now' time seen by this library to time.Now.

func SetUpNowTime

func SetUpNowTime(t time.Time)

SetUpNowTime overrides the 'now' time seen by this library to a constant value (instead of time.Now) This function is provided only to ease unit testing

Types

type CounterOpts

type CounterOpts struct {
	prometheus.CounterOpts
	// WarmUpDuration represents the time during which metrics are collected
	// with their initial value instead of their actual value, starting at the first collection.
	// The warmup period start at the first collection and ends after WarmUpDuration.
	WarmUpDuration time.Duration
	// ExpirationDelay is the maximum times a metrics keeps beeing collected when it not accessed/updated anymore.
	// It is only applicable to vector of metrics and zero value means infinite expiration time.
	ExpirationDelay time.Duration
}

type GaugeOpts

type GaugeOpts struct {
	prometheus.GaugeOpts
	// ExpirationDelay is the maximum times a metrics keeps beeing collected when it not accessed/updated anymore.
	// It is only applicable to vector of metrics and zero value means infinite expiration time.
	ExpirationDelay time.Duration
}

type HistogramOpts

type HistogramOpts struct {
	prometheus.HistogramOpts
	// WarmUpDuration represents the time during which metrics are collected
	// with their initial value instead of their actual value, starting at the first collection.
	// The warmup period start at the first collection and ends after WarmUpDuration.
	WarmUpDuration time.Duration
	// ExpirationDelay is the maximum times a metrics keeps beeing collected when it not accessed/updated anymore.
	// It is only applicable to vector of metrics and zero value means infinite expiration time.
	ExpirationDelay time.Duration
}

type MetricVec

type MetricVec[M prometheus.Metric] struct {
	// contains filtered or unexported fields
}

MetricVec is a generic implementation of a Vector of metrics, to bundle metrics of the same name that differ in their label values. It is an extension of prometheus.MetricVec that adds two functionalities to the vanilla prometheus.MetricVec: the metric 'warm-up' and automatic delete (expiration delay).

The available operations are the same as prometheus.MetricVec expect for the Curry operation that is not implemented.

You should not instantiate directly this struct

func NewCounterVec

func NewCounterVec(opts CounterOpts, labelNames []string) *MetricVec[prometheus.Counter]

NewCounterVec created a new vector of prometheus.Counter metrics with the Warmup and expiration features.

func NewGaugeVec

func NewGaugeVec(opts GaugeOpts, labelNames []string) *MetricVec[prometheus.Gauge]

NewGaugeVec created a new vector of prometheus.Gauge metrics with expiration features.

func NewHistogramVec

func NewHistogramVec(opts HistogramOpts, labelNames []string) *MetricVec[prometheus.Histogram]

NewHistogramVec created a new vector of prometheus.Histogram metrics with the Warmup and expiration features.

func NewSummaryVec

func NewSummaryVec(opts SummaryOpts, labelNames []string) *MetricVec[prometheus.Summary]

NewSummaryVec created a new vector of prometheus.Summary metrics with the Warmup and expiration features.

func (*MetricVec[M]) Collect

func (mv *MetricVec[M]) Collect(ch chan<- prometheus.Metric)

Collect implements prometheus.Collector.

Recently added metrics are collected with their initial value till the end of their WarmUp duration.

Expired metrics are ignored and removed from this vector.

func (*MetricVec[M]) Delete

func (mv *MetricVec[M]) Delete(labels prometheus.Labels) bool

DeleteLabelValues removes the metrics associated to the given label map (should match the variable labels in Desc)). It returns true if a metric was deleted.

func (*MetricVec[M]) DeleteLabelValues

func (mv *MetricVec[M]) DeleteLabelValues(labelValues ...string) bool

DeleteLabelValues removes the metrics associated to the given slice of label values (same order as the variable labels in Desc). It returns true if a metric was deleted.

func (*MetricVec[M]) Describe

func (mv *MetricVec[M]) Describe(ch chan<- *prometheus.Desc)

Describe implements prometheus.Collector.

func (*MetricVec[M]) GetMetricWith

func (mv *MetricVec[M]) GetMetricWith(labels prometheus.Labels) (M, error)

GetMetricWith returns the Metric for the given Labels map (the label names must match those of the variable labels in Desc). If that label map is accessed for the first time, a new Metric is created.

If an expiration delay was set in the options, the expiration time of the returned metrics is set to Now+ExpirationDelay.

IMPORTANT: you should not keep the returned metric for later usage if an ExpirationDelay was defined, for the reason explained above. Since the expiration time will never be reset, the metrics would automatically expires after ExpirationDelay, even if its value is updated.

This function mimics the function of prometheus.MetricVec with the same name.

func (*MetricVec[M]) GetMetricWithLabelValues

func (mv *MetricVec[M]) GetMetricWithLabelValues(labelValues ...string) (M, error)

GetMetricWithLabelValues returns the Metric for the given slice of label values (same order as the variable labels in Desc). If that combination of label values is accessed for the first time, a new Metric is created.

If an expiration delay was set in the options, the expiration time of the returned metrics is set to Now+ExpirationDelay.

IMPORTANT: you should not keep the returned metric for later usage if an ExpirationDelay was defined, for the reason explained above. Since the expiration time will never be reset, the metrics would automatically expires after ExpirationDelay, even if its value is updated.

This function mimics the function of prometheus.MetricVec with the same name.

func (*MetricVec[M]) Reset

func (mv *MetricVec[M]) Reset()

Reset delete all the metrics of this vector.

func (*MetricVec[M]) With

func (mv *MetricVec[M]) With(labels prometheus.Labels) M

With works as GetMetricWith, but panics where GetMetricWithLabels would have returned an error.

func (*MetricVec[M]) WithLabelValues

func (mv *MetricVec[M]) WithLabelValues(labelValues ...string) M

WithLabelValues works as GetMetricWithLabelValues, but panics where GetMetricWithLabelValues would have returned an error.

type SummaryOpts

type SummaryOpts struct {
	prometheus.SummaryOpts
	// WarmUpDuration represents the time during which metrics are collected
	// with their initial value instead of their actual value, starting at the first collection.
	// The warmup period start at the first collection and ends after WarmUpDuration.
	WarmUpDuration time.Duration
	// ExpirationDelay is the maximum times a metrics keeps beeing collected when it not accessed/updated anymore.
	// It is only applicable to vector of metrics and zero value means infinite expiration time.
	ExpirationDelay time.Duration
}

Jump to

Keyboard shortcuts

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