promext

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2024 License: Apache-2.0 Imports: 10 Imported by: 4

Documentation

Overview

Package promext contains custom metric types and pure utility functions

Types and functions inside are at the lowest level and should not call Logger or other packages, to avoid cyclic dependency

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectMetrics

func CollectMetrics(c prometheus.Collector, filterLabels prometheus.Labels) ([]*dto.Metric, error)

CollectMetrics exports all metrics matching an optional set of labels.

The values are already final during the collection. They won't change despite being pointers.

func DumpMetrics

func DumpMetrics(prefix string, skipComments, skipZeroValues bool, gatherers ...prometheus.Gatherer) string

DumpMetrics dumps matched metrics from the given gatherer(s) into the .prom text format

prefix can be empty to include all metrics

If no gatherers is provided, the DefaultGatherer is used

func DumpMetricsFrom

func DumpMetricsFrom(prefix string, skipComments, skipZeroValues bool, collectors ...prometheus.Collector) string

DumpMetricsFrom dumps matched metrics from the given collectors into the .prom text format

prefix can be empty to include all metrics

Extra check is enabled by using prometheus.PedanticRegistry

func GetExportedMetricValue

func GetExportedMetricValue(metric *dto.Metric) float64

GetExportedMetricValue returns the value of the exported (protobuf) metric.

For Summary and Histogram, the sum of samples is returned

func GetLabelValue

func GetLabelValue(metric *dto.Metric, targetLabel string) string

GetLabelValue reads the value of a specific label from the given metric.

If the label does not exist, an empty string is returned.

func MatchExportedMetrics

func MatchExportedMetrics(metrics []*dto.Metric, labels prometheus.Labels) []*dto.Metric

MatchExportedMetrics lists metrics under a family by matching given labels

func SumExportedMetrics

func SumExportedMetrics(metricFamily *dto.MetricFamily, labels map[string]string) float64

SumExportedMetrics returns the sum of values from metrics matching the labels

func SumMetricValues

func SumMetricValues(c prometheus.Collector) float64

SumMetricValues sums all the values of a given Prometheus Collector (GaugeVec or CounterVec).

Note curried metric vectors would give the same result as uncurried ones.

func SumMetricValues2

func SumMetricValues2(c prometheus.Collector, filterLabels prometheus.Labels) float64

SumMetricValues2 sums all the values of a given Prometheus Collector (GaugeVec or CounterVec), with a set of labels for filtering.

Note curried metric vectors would give the same result as uncurried ones.

func SumMetricValuesBy

func SumMetricValuesBy(c prometheus.Collector, keyLabel string, filterLabels prometheus.Labels) map[string]float64

SumMetricValuesBy sums all the values of a given Prometheus Collector (GaugeVec or CounterVec) by a specific label.

If the label does not exist for some of the metrics, the values would be summed under key="" in the resulting map.

Note curried metric vectors would give the same result as uncurried ones.

Types

type LazyRWCounter

type LazyRWCounter RWCounter

LazyRWCounter is prometheus.Counter with unsigned int64 type and getter, and only collected when not zero

type LazyRWCounterVec

type LazyRWCounterVec struct {
	RWCounterVec
}

LazyRWCounterVec is a lazy version of prometheus.CounterVec with unsigned int64 type and getter

Unlike the normal RWCounterVec, counters inside this vector are omitted from output collection if their values are zero

func NewLazyRWCounterVec

func NewLazyRWCounterVec(opts prometheus.CounterOpts, labelNames []string) *LazyRWCounterVec

NewLazyRWCounterVec creates a lazy RWCounterVec based on the provided CounterOpts and label names

Unlike the normal counter-vector, all zero-valued counters are omitted from metric collection / dump

func (*LazyRWCounterVec) Collect

func (v *LazyRWCounterVec) Collect(ch chan<- prometheus.Metric)

Collect implements prometheus.Collector, putting all non-zero counters to the given output channel

func (*LazyRWCounterVec) CurryWith

func (v *LazyRWCounterVec) CurryWith(labels prometheus.Labels) (*LazyRWCounterVec, error)

CurryWith returns a vector curried with the provided labels

func (*LazyRWCounterVec) GetMetricWithLabelValues

func (v *LazyRWCounterVec) GetMetricWithLabelValues(lvs ...string) (LazyRWCounter, error)

GetMetricWithLabelValues returns the Counter for the given slice of label values (same order as the variable labels in Desc).

func (*LazyRWCounterVec) MustCurryWith

func (v *LazyRWCounterVec) MustCurryWith(labels prometheus.Labels) *LazyRWCounterVec

MustCurryWith returns a vector curried with the provided labels or panic

func (*LazyRWCounterVec) WithLabelValues

func (v *LazyRWCounterVec) WithLabelValues(lvs ...string) LazyRWCounter

WithLabelValues returns the Counter for the given slice of label values or panic (same order as the variable labels in Desc).

type RWCounter

type RWCounter interface {
	prometheus.Metric
	prometheus.Collector

	Get() uint64
	Inc() uint64
	Add(uint64) uint64
}

RWCounter is prometheus.Counter with unsigned int64 type and getter

The code is nearly 100% copy paste from prometheus.Counter. Use generics when available.

type RWCounterVec

type RWCounterVec struct {
	*prometheus.MetricVec
	// contains filtered or unexported fields
}

RWCounterVec is prometheus.CounterVec with unsigned int64 type and getter

The code is nearly 100% copy paste from prometheus.CounterVec. Use generics when available.

func NewRWCounterVec

func NewRWCounterVec(opts prometheus.CounterOpts, labelNames []string) *RWCounterVec

NewRWCounterVec creates a new RWCounterVec based on the provided CounterOpts and label names

func (*RWCounterVec) CurryWith

func (v *RWCounterVec) CurryWith(labels prometheus.Labels) (*RWCounterVec, error)

CurryWith returns a vector curried with the provided labels

func (*RWCounterVec) GetMetricWithLabelValues

func (v *RWCounterVec) GetMetricWithLabelValues(lvs ...string) (RWCounter, error)

GetMetricWithLabelValues returns the Counter for the given slice of label values (same order as the variable labels in Desc).

func (*RWCounterVec) MustCurryWith

func (v *RWCounterVec) MustCurryWith(labels prometheus.Labels) *RWCounterVec

MustCurryWith returns a vector curried with the provided labels or panic

func (*RWCounterVec) WithLabelValues

func (v *RWCounterVec) WithLabelValues(lvs ...string) RWCounter

WithLabelValues returns the Counter for the given slice of label values or panic (same order as the variable labels in Desc).

type RWGauge

type RWGauge interface {
	prometheus.Metric
	prometheus.Collector

	Get() int64
	Set(int64)
	Inc() int64
	Dec() int64
	Add(int64) int64
	Sub(int64) int64
	WaitForZero(timeout time.Duration) bool
}

RWGauge is prometheus.Gauge with signed int64 type and getter

The code is nearly 100% copy paste from prometheus.Gauge. Use generics when available.

type RWGaugeVec

type RWGaugeVec struct {
	*prometheus.MetricVec
	// contains filtered or unexported fields
}

RWGaugeVec is prometheus.GaugeVec with signed int64 type and getter

The code is nearly 100% copy paste from prometheus.GaugeVec. Use generics when available.

func NewRWGaugeVec

func NewRWGaugeVec(opts prometheus.GaugeOpts, labelNames []string) *RWGaugeVec

NewRWGaugeVec creates a new RWGaugeVec based on the provided GaugeOpts and label names

func (*RWGaugeVec) CurryWith

func (v *RWGaugeVec) CurryWith(labels prometheus.Labels) (*RWGaugeVec, error)

CurryWith returns a vector curried with the provided labels

func (*RWGaugeVec) GetMetricWithLabelValues

func (v *RWGaugeVec) GetMetricWithLabelValues(lvs ...string) (RWGauge, error)

GetMetricWithLabelValues returns the Gauge for the given slice of label values (same order as the variable labels in Desc).

func (*RWGaugeVec) MustCurryWith

func (v *RWGaugeVec) MustCurryWith(labels prometheus.Labels) *RWGaugeVec

MustCurryWith returns a vector curried with the provided labels or panic

func (*RWGaugeVec) WithLabelValues

func (v *RWGaugeVec) WithLabelValues(lvs ...string) RWGauge

WithLabelValues returns the Gauge for the given slice of label values or panic (same order as the variable labels in Desc).

Jump to

Keyboard shortcuts

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