prometheus

package
v0.0.0-...-183aff7 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = func() metrics.Metrics {
	registry, ok := prometheus.DefaultRegisterer.(*prometheus.Registry)
	if !ok {
		alternativeDefaultRegistryOnce.Do(func() {
			alternativeDefaultRegistry = prometheus.NewRegistry()
		})
		registry = alternativeDefaultRegistry
	}
	return New(registry)
}

Default returns metrics.Metrics with the default configuration.

Functions

func FieldValueToString

func FieldValueToString(vI interface{}) string

FieldValueToString converts any value to a string, which could be used as label value in prometheus.

Types

type Count

Count is an implementation of metrics.Count.

func (*Count) Add

func (metric *Count) Add(delta uint64) types.Count

Add implementations metrics.Count.

func (*Count) Value

func (metric *Count) Value() any

Value implementations metrics.Metric.

func (*Count) WithResetFields

func (metric *Count) WithResetFields(fields field.AbstractFields) types.Count

WithResetFields implements metrics.Count

type CounterVec

type CounterVec struct {
	*prometheus.CounterVec
	Key            string
	PossibleLabels []string
}

CounterVec is a family of Count metrics.

func (*CounterVec) AddPossibleLabels

func (v *CounterVec) AddPossibleLabels(newLabels []string)

AddPossibleLabels adds prometheus labels to the list of expected labels of a Metric of this family.

func (*CounterVec) GetMetricWith

func (v *CounterVec) GetMetricWith(labels prometheus.Labels) (prometheus.Counter, error)

GetMetricWith returns a Metric with the values of labels as provided.

type Fields

type Fields = field.Fields

Fields is just a type-alias to field.Fields (for convenience).

type Gauge

Gauge is an implementation of metrics.Gauge.

func (*Gauge) Add

func (metric *Gauge) Add(delta float64) types.Gauge

Add implementations metrics.Gauge.

func (*Gauge) Value

func (metric *Gauge) Value() any

Value implementations metrics.Metric.

func (*Gauge) WithResetFields

func (metric *Gauge) WithResetFields(fields field.AbstractFields) types.Gauge

WithResetFields implements metrics.Gauge.

type GaugeVec

type GaugeVec struct {
	*prometheus.GaugeVec
	Key            string
	PossibleLabels []string
}

GaugeVec is a family of Gauge metrics.

func (*GaugeVec) AddPossibleLabels

func (v *GaugeVec) AddPossibleLabels(newLabels []string)

AddPossibleLabels adds prometheus labels to the list of expected labels of a Metric of this family.

func (*GaugeVec) GetMetricWith

func (v *GaugeVec) GetMetricWith(labels prometheus.Labels) (prometheus.Gauge, error)

GetMetricWith returns a Metric with the values of labels as provided.

type IntGauge

IntGauge is an implementation of metrics.IntGauge.

func (*IntGauge) Add

func (metric *IntGauge) Add(delta int64) types.IntGauge

Add implementations metrics.IntGauge.

func (*IntGauge) Value

func (metric *IntGauge) Value() any

Value implementations metrics.Metric.

func (*IntGauge) WithResetFields

func (metric *IntGauge) WithResetFields(fields field.AbstractFields) types.IntGauge

WithResetFields implements metrics.IntGauge

type Metrics

type Metrics struct {
	// contains filtered or unexported fields
}

Metrics implements a wrapper of prometheus metrics to implement metrics.Metrics.

Pretty slow and naive implementation. Could be improved by on-need basis. If you need a faster implementation, then try `tsmetrics`.

Warning! This implementation does not remove automatically metrics, thus if a metric was created once, it will be kept in memory forever. If you need a version of metrics which automatically removes metrics non-used for a long time, then try `tsmetrics`.

Warning! Prometheus does not support changing amount of labels for a metric, therefore we delete and create a metric from scratch if it is required to extend the set of labels. This procedure leads to a reset of the metric value. If you need a version of metrics which does not have such flaw, then try `tsmetrics` or `simplemetrics`.

func New

func New(registry *prometheus.Registry, opts ...Option) *Metrics

New returns a new instance of Metrics

func (*Metrics) Count

func (m *Metrics) Count(key string) types.Count

Count implements context.Metrics (see the description in the interface).

func (*Metrics) CountFields

func (m *Metrics) CountFields(key string, addFields field.AbstractFields) types.Count

CountFields returns Count metric given key and additional field values (on top of already defined).

func (*Metrics) Flush

func (*Metrics) Flush()

Flush implements metrics.Metrics (or more specifically belt.Tool).

func (*Metrics) ForEachCount

func (m *Metrics) ForEachCount(callback func(types.Count) bool) bool

ForEachCount iterates over each Count metric. Stops on first `false` returned by the callback.

func (*Metrics) ForEachGauge

func (m *Metrics) ForEachGauge(callback func(types.Gauge) bool) bool

ForEachGauge iterates over each Gauge metric. Stops on first `false` returned by the callback.

func (*Metrics) ForEachIntGauge

func (m *Metrics) ForEachIntGauge(callback func(types.IntGauge) bool) bool

ForEachIntGauge iterates over each IntGauge metric. Stops on first `false` returned by the callback.

func (*Metrics) Gatherer

func (m *Metrics) Gatherer() prometheus.Gatherer

Gatherer returns prometheus.Gatherer of this Metrics.

func (*Metrics) Gauge

func (m *Metrics) Gauge(key string) types.Gauge

Gauge implements context.Metrics (see the description in the interface).

func (*Metrics) GaugeFields

func (m *Metrics) GaugeFields(key string, addFields field.AbstractFields) types.Gauge

GaugeFields returns Gauge metric given key and additional field values (on top of already defined).

func (*Metrics) IntGauge

func (m *Metrics) IntGauge(key string) types.IntGauge

IntGauge implements context.Metrics (see the description in the interface).

func (*Metrics) IntGaugeFields

func (m *Metrics) IntGaugeFields(key string, addFields field.AbstractFields) types.IntGauge

IntGaugeFields returns IntGauge metric given key and additional field values (on top of already defined).

func (*Metrics) List

func (m *Metrics) List() []prometheus.Collector

List returns all the metrics. It could be used for a custom exporter.

func (*Metrics) Registerer

func (m *Metrics) Registerer() prometheus.Registerer

Registerer returns prometheus.Registerer of this Metrics.

func (*Metrics) WithContextFields

func (m *Metrics) WithContextFields(allFields *field.FieldsChain, newFieldsCount int) belt.Tool

WithContextFields implements metrics.Metrics.

func (*Metrics) WithTraceIDs

func (m *Metrics) WithTraceIDs(traceIDs belt.TraceIDs, newTraceIDsCount int) belt.Tool

WithTraceIDs implements metrics.Metrics.

type Option

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

Option is an optional argument to function New, that changes the behavior of the metrics handler.

type OptionDisableLabels

type OptionDisableLabels bool

OptionDisableLabels disables the labels (tags) and makes all the metrics flat. Attempts to get a metrics with the same key but different tags will result into getting the same metric. And all the metrics will be registered without labels.

Jump to

Keyboard shortcuts

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