metrics

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package metrics implements the metrics server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter added in v0.4.0

type Counter interface {
	prometheus.Metric
	prometheus.Collector
	// Set sets the counter to the given value.
	Set(value float64)
}

Counter is a prometheus counter that can be incremented and decremented.

func NewCounter added in v0.4.0

func NewCounter(opts CounterOpts) Counter

NewCounter returns a new counter.

type CounterOpts added in v0.4.0

type CounterOpts = prometheus.CounterOpts

CounterOpts is a prometheus counter options.

type Data added in v0.6.0

type Data struct {
	Node      *corev1.Node
	Pod       *corev1.Pod
	Container *corev1.Container
}

Data is a data structure that is passed to the cel program

type DataSource added in v0.4.0

type DataSource interface {
	ListPods(nodeName string) ([]log.ObjectRef, bool)
}

DataSource is the interface for getting data for metrics

type Environment added in v0.6.0

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

Environment is environment in which cel programs are executed

func NewEnvironment added in v0.6.0

func NewEnvironment(conf EnvironmentConfig) (*Environment, error)

NewEnvironment returns a Environment that is able to evaluate node metrics

func (*Environment) ClearResultCache added in v0.6.0

func (e *Environment) ClearResultCache()

ClearResultCache clears the result cache

func (*Environment) Compile added in v0.6.0

func (e *Environment) Compile(src string) (*Evaluator, error)

Compile is responsible for compiling a cel program

type EnvironmentConfig added in v0.6.0

type EnvironmentConfig struct {
	EnableResultCache bool

	Now                    func() time.Time
	StartedContainersTotal func(nodeName string) int64

	ContainerResourceUsage func(resourceName, podNamespace, podName, containerName string) float64
	PodResourceUsage       func(resourceName, podNamespace, podName string) float64
	NodeResourceUsage      func(resourceName, nodeName string) float64

	ContainerResourceCumulativeUsage func(resourceName, podNamespace, podName, containerName string) float64
	PodResourceCumulativeUsage       func(resourceName, podNamespace, podName string) float64
	NodeResourceCumulativeUsage      func(resourceName, nodeName string) float64
}

EnvironmentConfig holds configuration for a cel program

type Evaluator added in v0.6.0

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

Evaluator evaluates a cel program

func (*Evaluator) EvaluateFloat64 added in v0.6.0

func (e *Evaluator) EvaluateFloat64(ctx context.Context, data Data) (float64, error)

EvaluateFloat64 evaluates a cel program and returns a float64.

func (*Evaluator) EvaluateString added in v0.6.0

func (e *Evaluator) EvaluateString(ctx context.Context, data Data) (string, error)

EvaluateString evaluates a cel program and returns a string

type Gauge added in v0.4.0

type Gauge = prometheus.Gauge

Gauge is a prometheus gauge that can be incremented and decremented.

func NewGauge added in v0.4.0

func NewGauge(opts GaugeOpts) Gauge

NewGauge returns a new gauge.

type GaugeOpts added in v0.4.0

type GaugeOpts = prometheus.GaugeOpts

GaugeOpts is a prometheus gauge options.

type Histogram

type Histogram interface {
	prometheus.Metric
	prometheus.Collector
	Set(le float64, val uint64)
}

Histogram is a metric to track distributions of events.

func NewHistogram

func NewHistogram(opts HistogramOpts) Histogram

NewHistogram creates new Histogram based on Histogram options

type HistogramOpts

type HistogramOpts struct {
	// Namespace, Subsystem, and Name are components of the fully-qualified
	// name of the Histogram (created by joining these components with
	// "_"). Only Name is mandatory, the others merely help structuring the
	// name. Note that the fully-qualified name of the Histogram must be a
	// valid Prometheus metric name.
	Namespace string
	Subsystem string
	Name      string

	// Help provides information about this Histogram.
	//
	// Metrics with the same fully-qualified name must have the same Help
	// string.
	Help string

	// ConstLabels are used to attach fixed labels to this metric. Metrics
	// with the same fully-qualified name must have the same label names in
	// their ConstLabels.
	//
	// ConstLabels are only used rarely. In particular, do not use them to
	// attach the same labels to all your metrics. Those use cases are
	// better covered by target labels set by the scraping Prometheus
	// server, or by one specific metric (e.g. a build_info or a
	// machine_role metric). See also
	// https://prometheus.io/docs/instrumenting/writing_exporters/#target-labels-not-static-scraped-labels
	ConstLabels prometheus.Labels
	Buckets     []float64
}

HistogramOpts provides configuration options for Histogram.

type UpdateHandler

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

UpdateHandler handles updating metrics on request

func NewMetricsUpdateHandler

func NewMetricsUpdateHandler(conf UpdateHandlerConfig) *UpdateHandler

NewMetricsUpdateHandler creates new metric update handler based on the config

func (*UpdateHandler) ServeHTTP

func (h *UpdateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*UpdateHandler) Update added in v0.4.0

func (h *UpdateHandler) Update(ctx context.Context, nodeName string, metrics []internalversion.MetricConfig)

Update updates metrics for a node

type UpdateHandlerConfig

type UpdateHandlerConfig struct {
	DataSource      DataSource
	Environment     *Environment
	NodeCacheGetter informer.Getter[*corev1.Node]
	PodCacheGetter  informer.Getter[*corev1.Pod]
}

UpdateHandlerConfig is configuration for a single node

Jump to

Keyboard shortcuts

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