Documentation ¶
Overview ¶
The metrics package provides a set of helpers (wrappers around [prometheus Go library](https://pkg.go.dev/github.com/prometheus/client_golang/prometheus)) for defining and managing prometheus metrics.
The package is designed to support the following functionality:
- Group metrics based on their purpose and load groups independently. This gives us more control over what metrics are exposed and how cardinality is managed.
- Define custom collectors, e.g. reading metrics directly from BPF maps. This decouples metrics from events passed through ringbuffer.
- Let users configure high-cardinality dynamic labels, for both "regular" metrics and custom collectors.
- Constrain metrics cardinality for metrics with known labels.
- Initialize metrics with known labels on startup. This makes resources usage more predictable, as cardinality of these metrics won't grow.
- Autogenerate reference documentation from metrics help texts.
- Delete stale metrics. This will prevent growing cardinality. Currently we do it when a pod is deleted, but it should be easy to extend this to other cases.
- Keep common labels consistent between metrics. This makes it easier to write queries.
Here we describe the key parts of the metrics package. See also doc comments in the code for more details.
`Group` interface and `metricsGroup` struct implementing it are wrappers around `prometheus.Registry` intended to define sub-registries of the root registry. In addition to registering metrics, it supports:
- initializing metrics on startup
- initializing metrics for generating docs
- constraining metrics cardinality (constrained group contains only metrics with constrained cardinality)
`Opts` struct is a wrapper around `prometheus.Opts` that additionally supports defining constrained and unconstrained labels.
`ConstrainedLabel` and `UnconstrainedLabel` structs represent metric labels.
`FilteredLabels` interface represents configurable labels. It's intended to be used as a type parameter when defining a granular metric, to add common labels. The idea is that users can configure which of these (potentially high-cardinality) labels are actually exposed - see `CreateProcessLabels` in `pkg/option` for an example. The values of these labels are always unconstrained. `NilLabels` package variable is a special case of `FilteredLabels` with no labels, which is used in convenience wrappers around granular metrics.
`GranularCounter[L FilteredLabels]` (and analogous Gauge and Histogram) struct is a wrapper around `prometheus.CounterVec` (Gauge, Histogram) with additional properties:
- cardinality can be constrained
- support for configurable labels
- metric is initialized at startup for known label values
- metric is automatically included in generated docs
`Counter` (and analogous Gauge and Histogram) struct is a convenience wrapper around `GranularCounter[NilLabels]` (Gauge, Histogram).
`customCollector` struct represents a custom collector (e.g. reading metrics directly from a BPF map). It contains a list of metrics, collect function and an optional separate collect function for generating docs.
`GranularCustomMetric[L FilteredLabels]` interface and `granularCustomCounter` struct (and analogous Gauge) implementing it represent a metric that's not stored and updated using prometheus library, but collected independently, e.g. directly from a BPF map. Similarly like "regular" metrics, it supports constraining cardinality and adding configurable labels via type parameter.
`CustomMetric` interface and `customCounter` struct (and analogous Gauge) implementing it are convenience wrappers around `GranularCustomMetric[NilLabels]`.
Index ¶
- Variables
- func DeleteMetricsForPod(pod *corev1.Pod)
- func GetPodQueue() workqueue.DelayingInterface
- func ListMetricsWithPod() []*prometheus.MetricVec
- func NewCounterVecWithPod(opts prometheus.CounterOpts, labels []string) *prometheus.CounterVec
- func NewCounterVecWithPodV2(opts prometheus.CounterVecOpts) *prometheus.CounterVec
- func NewGaugeVecWithPod(opts prometheus.GaugeOpts, labels []string) *prometheus.GaugeVec
- func NewGaugeVecWithPodV2(opts prometheus.GaugeVecOpts) *prometheus.GaugeVec
- func NewHistogramVecWithPod(opts prometheus.HistogramOpts, labels []string) *prometheus.HistogramVec
- func NewHistogramVecWithPodV2(opts prometheus.HistogramVecOpts) *prometheus.HistogramVec
- func RegisterPodDeleteHandler()
- func StartPodDeleteHandler()
- type BPFMetric
- type CollectorWithInit
- type ConstrainedLabel
- type Counter
- type CustomMetric
- type CustomMetrics
- type FilteredLabels
- type FilteredLabelsExample
- type Gauge
- type GranularCounter
- func MustNewGranularCounter[L FilteredLabels](promOpts prometheus.CounterOpts, extraLabels []string) *GranularCounter[L]
- func MustNewGranularCounterWithInit[L FilteredLabels](opts Opts, init initCounterFunc) *GranularCounter[L]
- func NewGranularCounter[L FilteredLabels](opts Opts, init initCounterFunc) (*GranularCounter[L], error)
- func (m *GranularCounter[L]) Collect(ch chan<- prometheus.Metric)
- func (m *GranularCounter[L]) Describe(ch chan<- *prometheus.Desc)
- func (m *GranularCounter[L]) Init()
- func (m *GranularCounter[L]) InitForDocs()
- func (m *GranularCounter[L]) IsConstrained() bool
- func (m *GranularCounter[L]) WithLabelValues(commonLvs *L, lvs ...string) prometheus.Counter
- type GranularCustomMetric
- func MustNewGranularCustomCounter[L FilteredLabels](opts Opts) GranularCustomMetric[L]
- func MustNewGranularCustomGauge[L FilteredLabels](opts Opts) GranularCustomMetric[L]
- func NewGranularCustomCounter[L FilteredLabels](opts Opts) (GranularCustomMetric[L], error)
- func NewGranularCustomGauge[L FilteredLabels](opts Opts) (GranularCustomMetric[L], error)
- type GranularGauge
- func MustNewGranularGauge[L FilteredLabels](promOpts prometheus.GaugeOpts, extraLabels []string) *GranularGauge[L]
- func MustNewGranularGaugeWithInit[L FilteredLabels](opts Opts, init initGaugeFunc) *GranularGauge[L]
- func NewGranularGauge[L FilteredLabels](opts Opts, init initGaugeFunc) (*GranularGauge[L], error)
- func (m *GranularGauge[L]) Collect(ch chan<- prometheus.Metric)
- func (m *GranularGauge[L]) Describe(ch chan<- *prometheus.Desc)
- func (m *GranularGauge[L]) Init()
- func (m *GranularGauge[L]) InitForDocs()
- func (m *GranularGauge[L]) IsConstrained() bool
- func (m *GranularGauge[L]) WithLabelValues(commonLvs *L, lvs ...string) prometheus.Gauge
- type GranularHistogram
- func MustNewGranularHistogram[L FilteredLabels](promOpts prometheus.HistogramOpts, extraLabels []string) *GranularHistogram[L]
- func MustNewGranularHistogramWithInit[L FilteredLabels](opts HistogramOpts, init initHistogramFunc) *GranularHistogram[L]
- func NewGranularHistogram[L FilteredLabels](opts HistogramOpts, init initHistogramFunc) (*GranularHistogram[L], error)
- func (m *GranularHistogram[L]) Collect(ch chan<- prometheus.Metric)
- func (m *GranularHistogram[L]) Describe(ch chan<- *prometheus.Desc)
- func (m *GranularHistogram[L]) Init()
- func (m *GranularHistogram[L]) InitForDocs()
- func (m *GranularHistogram[L]) IsConstrained() bool
- func (m *GranularHistogram[L]) WithLabelValues(commonLvs *L, lvs ...string) prometheus.Observer
- type Group
- type Histogram
- type HistogramOpts
- type LabelFilter
- type NilLabels
- type Opts
- type ProcessLabels
- type UnconstrainedLabel
Constants ¶
This section is empty.
Variables ¶
var ( // TODO: Standardize labels used by different metrics: op, msg_op, opcode. // Also, add a human-readable counterpart. OpCodeLabel = ConstrainedLabel{ Name: "msg_op", Values: getOpcodes(), } EventTypeLabel = ConstrainedLabel{ Name: "event_type", Values: getEventTypes(), } )
var ErrInvalidMetricType = errors.New("invalid metric type")
Functions ¶
func DeleteMetricsForPod ¶ added in v0.11.0
func GetPodQueue ¶ added in v0.11.0
func GetPodQueue() workqueue.DelayingInterface
func ListMetricsWithPod ¶ added in v0.11.0
func ListMetricsWithPod() []*prometheus.MetricVec
func NewCounterVecWithPod ¶ added in v0.11.0
func NewCounterVecWithPod(opts prometheus.CounterOpts, labels []string) *prometheus.CounterVec
NewCounterVecWithPod is a wrapper around prometheus.NewCounterVec that also registers the metric to be cleaned up when a pod is deleted.
It should be used only to register metrics that have "pod" and "namespace" labels. Using it for metrics without these labels won't break anything, but might add an unnecessary overhead.
func NewCounterVecWithPodV2 ¶ added in v1.2.0
func NewCounterVecWithPodV2(opts prometheus.CounterVecOpts) *prometheus.CounterVec
NewCounterVecWithPodV2 is a wrapper around prometheus.V2.NewCounterVec that also registers the metric to be cleaned up when a pod is deleted.
See NewCounterVecWithPod for usage notes.
func NewGaugeVecWithPod ¶ added in v0.11.0
func NewGaugeVecWithPod(opts prometheus.GaugeOpts, labels []string) *prometheus.GaugeVec
NewGaugeVecWithPod is a wrapper around prometheus.NewGaugeVec that also registers the metric to be cleaned up when a pod is deleted.
See NewCounterVecWithPod for usage notes.
func NewGaugeVecWithPodV2 ¶ added in v1.2.0
func NewGaugeVecWithPodV2(opts prometheus.GaugeVecOpts) *prometheus.GaugeVec
NewGaugeVecWithPodV2 is a wrapper around prometheus.V2.NewGaugeVec that also registers the metric to be cleaned up when a pod is deleted.
See NewCounterVecWithPod for usage notes.
func NewHistogramVecWithPod ¶ added in v0.11.0
func NewHistogramVecWithPod(opts prometheus.HistogramOpts, labels []string) *prometheus.HistogramVec
NewHistogramVecWithPod is a wrapper around prometheus.NewHistogramVec that also registers the metric to be cleaned up when a pod is deleted.
See NewCounterVecWithPod for usage notes.
func NewHistogramVecWithPodV2 ¶ added in v1.2.0
func NewHistogramVecWithPodV2(opts prometheus.HistogramVecOpts) *prometheus.HistogramVec
NewHistogramVecWithPodV2 is a wrapper around prometheus.V2.NewHistogramVec that also registers the metric to be cleaned up when a pod is deleted.
See NewCounterVecWithPod for usage notes.
func RegisterPodDeleteHandler ¶ added in v0.11.0
func RegisterPodDeleteHandler()
RegisterPodDeleteHandler registers handler for deleting metrics associated with deleted pods. Without it, Tetragon kept exposing stale metrics for deleted pods. This was causing continuous increase in memory usage in Tetragon agent as well as in the metrics scraper.
func StartPodDeleteHandler ¶ added in v0.11.0
func StartPodDeleteHandler()
Types ¶
type BPFMetric ¶ added in v1.0.0
type BPFMetric interface { Desc() *prometheus.Desc MustMetric(value float64, labelValues ...string) prometheus.Metric }
func NewBPFCounter ¶ added in v1.0.0
func NewBPFCounter(desc *prometheus.Desc) BPFMetric
DEPRECATED: Use NewCustomCounter instead.
func NewBPFGauge ¶ added in v1.0.0
func NewBPFGauge(desc *prometheus.Desc) BPFMetric
DEPRECATED: Use NewCustomGauge instead.
type CollectorWithInit ¶ added in v1.2.0
type CollectorWithInit interface { prometheus.Collector // contains filtered or unexported methods }
CollectorWithInit extends prometheus.Collector with initializer.
func NewCustomCollector ¶ added in v1.2.0
func NewCustomCollector( metrics []customMetric, collect collectFunc, collectForDocs collectFunc, ) CollectorWithInit
NewCustomCollector creates a new customCollector.
If collectForDocs is nil, the collector will use collect function for both regular metrics server and generating documentation.
type ConstrainedLabel ¶ added in v1.2.0
ConstrainedLabel represents a label with constrained cardinality. Values is a list of all possible values of the label.
type Counter ¶ added in v1.2.0
type Counter struct { *GranularCounter[NilLabels] }
Counter wraps prometheus.CounterVec and implements CollectorWithInit.
The only difference between GranularCounter[FilteredLabels] and Counter is WithLabelValues method, which in the latter doesn't take generic FilteredLabels argument. We can also use GranularCounter[NilLabels] to define counters with no configurable labels, but then we have to pass an additional nil argument to WithLabelValues. A separate type is provided for convenience and easy migration.
func MustNewCounter ¶ added in v1.2.0
MustNewCounter is a convenience function that wraps NewCounter and panics on error.
func NewCounter ¶ added in v1.2.0
NewCounter creates a new Counter.
See NewGranularCounter for usage notes.
func (*Counter) Collect ¶ added in v1.2.0
func (m *Counter) Collect(ch chan<- prometheus.Metric)
Collect implements CollectorWithInit (prometheus.Collector).
func (*Counter) Describe ¶ added in v1.2.0
func (m *Counter) Describe(ch chan<- *prometheus.Desc)
Describe implements CollectorWithInit (prometheus.Collector).
func (*Counter) InitForDocs ¶ added in v1.2.0
func (m *Counter) InitForDocs()
InitForDocs implements CollectorWithInit.
func (*Counter) IsConstrained ¶ added in v1.2.0
IsConstrained implements CollectorWithInit.
func (*Counter) WithLabelValues ¶ added in v1.2.0
func (m *Counter) WithLabelValues(lvs ...string) prometheus.Counter
WithLabelValues is similar to WithLabelValues method from prometheus package. The arguments are values of first constrained labels, then unconstrained labels.
type CustomMetric ¶ added in v1.2.0
type CustomMetric interface { MustMetric(value float64, lvs ...string) prometheus.Metric // contains filtered or unexported methods }
CustomMetric represents a metric collected independently of prometheus package that has no configurable labels.
The only difference between GranularCustomMetric[FilteredLabels] and CustomMetric is MustMetric method, which in the latter doesn't take generic FilteredLabels argument. We can also use GranularCustomMetric[NilLabels] to define custom metrics with no configurable labels, but then we have to pass an additional nil argument to MustMetric. A separate interface is provided for convenience and easy migration.
See GranularCustomMetric for usage notes.
func MustNewCustomCounter ¶ added in v1.2.0
func MustNewCustomCounter(opts Opts) CustomMetric
MustNewCustomCounter is a convenience function that wraps NewCustomCounter and panics on error.
func MustNewCustomGauge ¶ added in v1.2.0
func MustNewCustomGauge(opts Opts) CustomMetric
MustNewCustomGauge is a convenience function that wraps NewCustomGauge and panics on error.
func NewCustomCounter ¶ added in v1.2.0
func NewCustomCounter(opts Opts) (CustomMetric, error)
NewCustomCounter creates a new customCounter.
func NewCustomGauge ¶ added in v1.2.0
func NewCustomGauge(opts Opts) (CustomMetric, error)
NewCustomGauge creates a new customGauge.
type CustomMetrics ¶ added in v1.2.0
type CustomMetrics []customMetric
type FilteredLabels ¶ added in v1.1.0
type FilteredLabelsExample ¶ added in v1.2.0
type FilteredLabelsExample interface {
Example() FilteredLabels
}
type Gauge ¶ added in v1.2.0
type Gauge struct { *GranularGauge[NilLabels] }
Gauge wraps prometheus.GaugeVec and implements CollectorWithInit.
The only difference between GranularGauge[FilteredLabels] and Gauge is WithLabelValues method, which in the latter doesn't take generic FilteredLabels argument. We can also use GranularGauge[NilLabels] to define gauges with no configurable labels, but then we have to pass an additional nil argument to WithLabelValues. A separate type is provided for convenience and easy migration.
func MustNewGauge ¶ added in v1.2.0
MustNewGauge is a convenience function that wraps NewGauge and panics on error.
func NewGauge ¶ added in v1.2.0
NewGauge creates a new Gauge.
See NewGranularCounter for usage notes.
func (*Gauge) Collect ¶ added in v1.2.0
func (m *Gauge) Collect(ch chan<- prometheus.Metric)
Collect implements CollectorWithInit (prometheus.Collector).
func (*Gauge) Describe ¶ added in v1.2.0
func (m *Gauge) Describe(ch chan<- *prometheus.Desc)
Describe implements CollectorWithInit (prometheus.Collector).
func (*Gauge) InitForDocs ¶ added in v1.2.0
func (m *Gauge) InitForDocs()
InitForDocs implements CollectorWithInit.
func (*Gauge) IsConstrained ¶ added in v1.2.0
IsConstrained implements CollectorWithInit.
func (*Gauge) WithLabelValues ¶ added in v1.2.0
func (m *Gauge) WithLabelValues(lvs ...string) prometheus.Gauge
WithLabelValues is similar to WithLabelValues method from prometheus package. The arguments are values of first constrained labels, then unconstrained labels.
type GranularCounter ¶ added in v1.0.0
type GranularCounter[L FilteredLabels] struct { // contains filtered or unexported fields }
GranularCounter wraps prometheus.CounterVec and implements CollectorWithInit.
func MustNewGranularCounter ¶ added in v1.0.0
func MustNewGranularCounter[L FilteredLabels](promOpts prometheus.CounterOpts, extraLabels []string) *GranularCounter[L]
MustNewGranularCounter is a convenience function that wraps NewGranularCounter and panics on error.
NOTE: The function takes different arguments than NewGranularCounter, to provide a bridge between the new metrics library and the existing code defining metrics.
DEPRECATED: Use MustNewGranularCounterWithInit instead.
func MustNewGranularCounterWithInit ¶ added in v1.2.0
func MustNewGranularCounterWithInit[L FilteredLabels](opts Opts, init initCounterFunc) *GranularCounter[L]
MustNewGranularCounterWithInit is a convenience function that wraps NewGranularCounter and panics on error.
func NewGranularCounter ¶ added in v1.0.0
func NewGranularCounter[L FilteredLabels](opts Opts, init initCounterFunc) (*GranularCounter[L], error)
NewGranularCounter creates a new GranularCounter.
The init argument is a function that initializes the metric with some label values. Doing so allows us to keep resources usage predictable. If the metric is constrained (i.e. type parameter is NilLabels and there are no unconstrained labels) and init is nil, then the metric will be initialized with all possible combinations of labels. If the metric is unconstrained, it won't be initialized by default.
Pass an init function in the following cases:
- metric is constrained but not all combinations of labels make sense (e.g. there is a hierarchy between labels or two labels represent the same thing in different formats, or two labels are mutually exclusive).
- metric is unconstrained, but some of the unconstrained label values are known beforehand, so can be initialized.
- you want to disable default initialization - pass func(*prometheus.CounterVec) {} in such case
func (*GranularCounter[L]) Collect ¶ added in v1.1.0
func (m *GranularCounter[L]) Collect(ch chan<- prometheus.Metric)
Collect implements CollectorWithInit (prometheus.Collector).
func (*GranularCounter[L]) Describe ¶ added in v1.1.0
func (m *GranularCounter[L]) Describe(ch chan<- *prometheus.Desc)
Describe implements CollectorWithInit (prometheus.Collector).
func (*GranularCounter[L]) Init ¶ added in v1.2.0
func (m *GranularCounter[L]) Init()
Init implements CollectorWithInit.
func (*GranularCounter[L]) InitForDocs ¶ added in v1.2.0
func (m *GranularCounter[L]) InitForDocs()
InitForDocs implements CollectorWithInit.
func (*GranularCounter[L]) IsConstrained ¶ added in v1.2.0
func (m *GranularCounter[L]) IsConstrained() bool
IsConstrained implements CollectorWithInit.
func (*GranularCounter[L]) WithLabelValues ¶ added in v1.0.0
func (m *GranularCounter[L]) WithLabelValues(commonLvs *L, lvs ...string) prometheus.Counter
WithLabelValues is similar to WithLabelValues method from prometheus package, but takes generic FilteredLabels as the first argument. The following arguments are values of first constrained labels, then unconstrained labels.
type GranularCustomMetric ¶ added in v1.2.0
type GranularCustomMetric[L FilteredLabels] interface { MustMetric(value float64, commonLvs *L, lvs ...string) prometheus.Metric // contains filtered or unexported methods }
GranularCustomMetric represents a metric collected independently of prometheus package, for example in a BPF map.
It's intended to be used in a custom collector (see customcollector.go). The interface doesn't provide any validation, so it's entirely up to the collector implementer to guarantee metrics consistency, including enforcing labels constraints.
func MustNewGranularCustomCounter ¶ added in v1.2.0
func MustNewGranularCustomCounter[L FilteredLabels](opts Opts) GranularCustomMetric[L]
MustNewGranularCustomCounter is a convenience function that wraps NewGranularCustomCounter and panics on error.
func MustNewGranularCustomGauge ¶ added in v1.2.0
func MustNewGranularCustomGauge[L FilteredLabels](opts Opts) GranularCustomMetric[L]
MustNewGranularCustomGauge is a convenience function that wraps NewGranularCustomGauge and panics on error.
func NewGranularCustomCounter ¶ added in v1.2.0
func NewGranularCustomCounter[L FilteredLabels](opts Opts) (GranularCustomMetric[L], error)
NewGranularCustomCounter creates a new granularCustomCounter.
func NewGranularCustomGauge ¶ added in v1.2.0
func NewGranularCustomGauge[L FilteredLabels](opts Opts) (GranularCustomMetric[L], error)
NewGranularCustomGauge creates a new granularCustomGauge.
type GranularGauge ¶ added in v1.0.0
type GranularGauge[L FilteredLabels] struct { // contains filtered or unexported fields }
GranularGauge wraps prometheus.GaugeVec and implements CollectorWithInit.
func MustNewGranularGauge ¶ added in v1.0.0
func MustNewGranularGauge[L FilteredLabels](promOpts prometheus.GaugeOpts, extraLabels []string) *GranularGauge[L]
MustNewGranularGauge is a convenience function that wraps NewGranularGauge and panics on error.
See MustNewGranularCounter for usage notes.
DEPRECATED: Use MustNewGranularGaugeWithInit instead.
func MustNewGranularGaugeWithInit ¶ added in v1.2.0
func MustNewGranularGaugeWithInit[L FilteredLabels](opts Opts, init initGaugeFunc) *GranularGauge[L]
MustNewGranularGaugeWithInit is a convenience function that wraps NewGranularGauge and panics on error.
func NewGranularGauge ¶ added in v1.0.0
func NewGranularGauge[L FilteredLabels](opts Opts, init initGaugeFunc) (*GranularGauge[L], error)
NewGranularGauge creates a new GranularGauge.
See NewGranularCounter for usage notes.
func (*GranularGauge[L]) Collect ¶ added in v1.1.0
func (m *GranularGauge[L]) Collect(ch chan<- prometheus.Metric)
Collect implements CollectorWithInit (prometheus.Collector).
func (*GranularGauge[L]) Describe ¶ added in v1.1.0
func (m *GranularGauge[L]) Describe(ch chan<- *prometheus.Desc)
Describe implements CollectorWithInit (prometheus.Collector).
func (*GranularGauge[L]) Init ¶ added in v1.2.0
func (m *GranularGauge[L]) Init()
Init implements CollectorWithInit.
func (*GranularGauge[L]) InitForDocs ¶ added in v1.2.0
func (m *GranularGauge[L]) InitForDocs()
InitForDocs implements CollectorWithInit.
func (*GranularGauge[L]) IsConstrained ¶ added in v1.2.0
func (m *GranularGauge[L]) IsConstrained() bool
IsConstrained implements CollectorWithInit.
func (*GranularGauge[L]) WithLabelValues ¶ added in v1.0.0
func (m *GranularGauge[L]) WithLabelValues(commonLvs *L, lvs ...string) prometheus.Gauge
WithLabelValues is similar to WithLabelValues method from prometheus package, but takes generic FilteredLabels as the first argument. The following arguments are values of first constrained labels, then unconstrained labels.
type GranularHistogram ¶ added in v1.0.0
type GranularHistogram[L FilteredLabels] struct { // contains filtered or unexported fields }
GranularHistogram wraps prometheus.HistogramVec and implements CollectorWithInit.
func MustNewGranularHistogram ¶ added in v1.0.0
func MustNewGranularHistogram[L FilteredLabels](promOpts prometheus.HistogramOpts, extraLabels []string) *GranularHistogram[L]
MustNewGranularHistogram is a convenience function that wraps NewGranularHistogram and panics on error.
See MustNewGranularCounter for usage notes.
DEPRECATED: Use MustNewGranularHistogramWithInit instead.
func MustNewGranularHistogramWithInit ¶ added in v1.2.0
func MustNewGranularHistogramWithInit[L FilteredLabels](opts HistogramOpts, init initHistogramFunc) *GranularHistogram[L]
MustNewGranularHistogramWithInit is a convenience function that wraps NewGranularHistogram and panics on error.
func NewGranularHistogram ¶ added in v1.0.0
func NewGranularHistogram[L FilteredLabels](opts HistogramOpts, init initHistogramFunc) (*GranularHistogram[L], error)
NewGranularHistogram creates a new GranularHistogram.
See NewGranularCounter for usage notes.
func (*GranularHistogram[L]) Collect ¶ added in v1.1.0
func (m *GranularHistogram[L]) Collect(ch chan<- prometheus.Metric)
Collect implements CollectorWithInit (prometheus.Collector).
func (*GranularHistogram[L]) Describe ¶ added in v1.1.0
func (m *GranularHistogram[L]) Describe(ch chan<- *prometheus.Desc)
Describe implements CollectorWithInit (prometheus.Collector).
func (*GranularHistogram[L]) Init ¶ added in v1.2.0
func (m *GranularHistogram[L]) Init()
Init implements CollectorWithInit.
func (*GranularHistogram[L]) InitForDocs ¶ added in v1.2.0
func (m *GranularHistogram[L]) InitForDocs()
InitForDocs implements CollectorWithInit.
func (*GranularHistogram[L]) IsConstrained ¶ added in v1.2.0
func (m *GranularHistogram[L]) IsConstrained() bool
IsConstrained implements CollectorWithInit.
func (*GranularHistogram[L]) WithLabelValues ¶ added in v1.0.0
func (m *GranularHistogram[L]) WithLabelValues(commonLvs *L, lvs ...string) prometheus.Observer
WithLabelValues is similar to WithLabelValues method from prometheus package, but takes generic FilteredLabels as the first argument. The following arguments are values of first constrained labels, then unconstrained labels.
type Group ¶ added in v1.2.0
type Group interface { prometheus.Registerer CollectorWithInit ExtendInit(func()) ExtendInitForDocs(func()) }
Group extends prometheus.Registerer with CollectorWithInit. It represents a sub-registry of the root prometheus.Registry.
func NewMetricsGroup ¶ added in v1.2.0
NewMetricsGroup creates a new Group.
type Histogram ¶ added in v1.2.0
type Histogram struct { *GranularHistogram[NilLabels] }
Histogram wraps prometheus.HistogramVec and implements CollectorWithInit.
The only difference between GranularHistogram[FilteredLabels] and Histogram is WithLabelValues method, which in the latter doesn't take generic FilteredLabels argument. We can also use GranularHistogram[NilLabels] to define histograms with no configurable labels, but then we have to pass an additional nil argument to WithLabelValues. A separate type is provided for convenience and easy migration.
func MustNewHistogram ¶ added in v1.2.0
func MustNewHistogram(opts HistogramOpts, init initHistogramFunc) *Histogram
MustNewHistogram is a convenience function that wraps NewHistogram and panics on error.
func NewHistogram ¶ added in v1.2.0
func NewHistogram(opts HistogramOpts, init initHistogramFunc) (*Histogram, error)
NewHistogram creates a new Histogram.
See NewGranularCounter for usage notes.
func (*Histogram) Collect ¶ added in v1.2.0
func (m *Histogram) Collect(ch chan<- prometheus.Metric)
Collect implements CollectorWithInit (prometheus.Collector).
func (*Histogram) Describe ¶ added in v1.2.0
func (m *Histogram) Describe(ch chan<- *prometheus.Desc)
Describe implements CollectorWithInit (prometheus.Collector).
func (*Histogram) Init ¶ added in v1.2.0
func (m *Histogram) Init()
Init implements CollectorWithInit.
func (*Histogram) InitForDocs ¶ added in v1.2.0
func (m *Histogram) InitForDocs()
InitForDocs implements CollectorWithInit.
func (*Histogram) IsConstrained ¶ added in v1.2.0
IsConstrained implements CollectorWithInit.
func (*Histogram) WithLabelValues ¶ added in v1.2.0
func (m *Histogram) WithLabelValues(lvs ...string) prometheus.Observer
WithLabelValues is similar to WithLabelValues method from prometheus package. The arguments are values of first constrained labels, then unconstrained labels.
type HistogramOpts ¶ added in v1.2.0
HistogramOpts extends Opts with histogram-specific fields.
type LabelFilter ¶ added in v1.0.0
func (LabelFilter) WithEnabledLabels ¶ added in v1.1.0
func (f LabelFilter) WithEnabledLabels(enabledLabels []string) LabelFilter
WithEnabledLabels returns a new LabelFilter with only the labels in enabledLabels enabled. If enabledLabels is nil, a copy of the original LabelFilter is returned. If enabledLabels is empty, all labels are disabled. If enabledLabels contains labels that are not in the original LabelFilter, they are ignored.
type NilLabels ¶ added in v1.2.0
type NilLabels struct{}
func (NilLabels) Example ¶ added in v1.2.0
func (l NilLabels) Example() FilteredLabels
type Opts ¶ added in v1.2.0
type Opts struct { prometheus.Opts ConstrainedLabels []ConstrainedLabel UnconstrainedLabels []UnconstrainedLabel }
Opts extends prometheus.Opts with constrained and unconstrained labels.
If using granular wrappers for prometheus metrics, then constrained labels will be replaced with an empty string if a values outside of the list is passed.
If using granular metric interface (either wrappers or custom metrics), then labels passed via type parameter: - are assumed to be unconstrained - will be added at the beginning of the final labels list - must not overlap with labels passed via Opts
func NewOpts ¶ added in v1.2.0
func NewOpts( namespace, subsystem, name, help string, constLabels prometheus.Labels, constrainedLabels []ConstrainedLabel, unconstrainedLabels []UnconstrainedLabel, ) Opts
type ProcessLabels ¶ added in v1.1.0
func NewProcessLabels ¶ added in v1.1.0
func NewProcessLabels(namespace, workload, pod, binary string) *ProcessLabels
func (ProcessLabels) Example ¶ added in v1.2.0
func (l ProcessLabels) Example() FilteredLabels
func (ProcessLabels) Keys ¶ added in v1.1.0
func (l ProcessLabels) Keys() []string
func (ProcessLabels) Values ¶ added in v1.1.0
func (l ProcessLabels) Values() []string
type UnconstrainedLabel ¶ added in v1.2.0
UnconstrainedLabel represents a label with unconstrained cardinality. ExampleValue is an example value of the label used for documentation.