exporter

package
v0.12.1-0...-a53de21 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KnownStates

func KnownStates[T ~string](s []T) []string

KnownStates converts the given slice of ~string to a slice of strings.

func KnownStatesStringer

func KnownStatesStringer[T fmt.Stringer](s []T) []string

KnownStatesStringer converts the given slice of fmt.Stringer to a slice of strings.

Types

type Exporter

type Exporter[O client.Object, L client.ObjectList] struct {
	client.Reader

	Namespace, Subsystem string

	// StaticLabelKeys are added to all Metrics of this Exporter.
	StaticLabelKeys []string
	// GenerateStaticLabelValues returns the values for StaticLabelKeys.
	GenerateStaticLabelValues func(O) []string

	Metrics []Metric[O]

	// optional
	ListOptions []client.ListOption
}

Exporter is a generic state metrics exporter for a given Kubernetes object kind that can be added to a controller-runtime manager.

func (*Exporter[O, L]) AddToManager

func (e *Exporter[O, L]) AddToManager(mgr manager.Manager) error

AddToManager adds this exporter to the given manager and completes the Metrics descriptors.

func (*Exporter[O, L]) Collect

func (e *Exporter[O, L]) Collect(ch chan<- prometheus.Metric)

func (*Exporter[O, L]) Describe

func (e *Exporter[O, L]) Describe(ch chan<- *prometheus.Desc)

func (*Exporter[O, L]) NeedLeaderElection

func (e *Exporter[O, L]) NeedLeaderElection() bool

NeedLeaderElection tells the manager to run the exporter in all instances.

func (*Exporter[O, L]) Start

func (e *Exporter[O, L]) Start(_ context.Context) error

Start registers this collector in the controller-runtime metrics registry. When Start runs, caches have already been started, so we are ready to export metrics.

type GenerateFunc

type GenerateFunc[O client.Object] func(desc *prometheus.Desc, obj O, staticLabelValues []string, ch chan<- prometheus.Metric)

func GenerateStateSet

func GenerateStateSet[O client.Object](knownStates []string, unknownState *string, getState func(O) string) GenerateFunc[O]

GenerateStateSet returns a GenerateFunc that emits stateset metrics: - it generates one metric per known state - the value is 1 if getState returns the state, 0 otherwise - if unknownState is given, a metric with this state label is generated with value 1 if no other state has matched

type Metric

type Metric[O client.Object] struct {
	Name, Help string
	LabelKeys  []string

	// Generate returns all metric values for the given object.
	// staticLabelValues is the result of Exporter.GenerateStaticLabelValues and should be added as the first label values
	// to all metrics.
	Generate GenerateFunc[O]
	// contains filtered or unexported fields
}

Metric describes a single metric and how to generate it per object.

Jump to

Keyboard shortcuts

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