metrics

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package metrics provides types for collecting and reporting metrics.

Index

Constants

View Source
const (
	// DefaultNamespace is the default namespace used for all metrics.
	DefaultNamespace = "kgateway"
)

Variables

View Source
var (

	// DefaultBuckets defines the default buckets used for histograms.
	DefaultBuckets = prometheus.DefBuckets
)

Functions

func Active

func Active() bool

Active checks if metrics are globally active.

func GetPromCollector

func GetPromCollector(c any) prometheus.Collector

GetPromCollector returns the underlying collector for any valid prometheus metric. This is exported for testing purposes.

func RegisterEvents

func RegisterEvents[T any](c krt.Collection[T], f func(o krt.Event[T])) krt.Syncer

RegisterEvents registers KRT events for a collection if metrics are active.

func SetActive

func SetActive(active bool)

SetActive sets the globally active state for metrics. Setting this does not effect metrics that are already being collected.

func SetRegistry

func SetRegistry(useBuiltinRegistry bool, r RegistererGatherer)

SetRegistry sets the global metrics registry.

Types

type Counter

type Counter interface {
	Metric
	Inc(...Label)
	Add(float64, ...Label)
	Reset()
}

Counter defines the interface for a counter metric.

func NewCounter

func NewCounter(opts CounterOpts, labels []string) Counter

NewCounter creates a new counter metric.

type CounterOpts

type CounterOpts prometheus.CounterOpts

CounterOpts defines options for creating a counter metric.

type Gauge

type Gauge interface {
	Metric
	Set(float64, ...Label)
	Add(float64, ...Label)
	Sub(float64, ...Label)
	Reset()
}

Gauge defines the interface for a gauge metric.

func NewGauge

func NewGauge(opts GaugeOpts, labels []string) Gauge

NewGauge creates a new gauge metric.

type GaugeOpts

type GaugeOpts prometheus.GaugeOpts

GaugeOpts defines options for creating a gauge metric.

type Histogram

type Histogram interface {
	Metric
	Observe(float64, ...Label)
	Reset()
}

Histogram defines the interface for a histogram metric.

func NewHistogram

func NewHistogram(opts HistogramOpts, labels []string) Histogram

NewHistogram creates a new histogram metric.

type HistogramOpts

type HistogramOpts prometheus.HistogramOpts

HistogramOpts defines options for creating a histogram metric.

type Label

type Label struct {
	Name  string
	Value string
}

Label defines a name-value pair for labeling metrics.

type Metric

type Metric interface {
	Labels() []string
}

Metric defines a base interface for metrics.

type RegistererGatherer

type RegistererGatherer metrics.RegistererGatherer

RegistererGatherer combines the Registerer and Gatherer interfaces from the Prometheus metrics library. These values can be used as metrics registries.

func NewRegistry

func NewRegistry() RegistererGatherer

NewRegistry creates a new metrics registry.

func Registry

func Registry() RegistererGatherer

Registry returns the global metrics registry.

Directories

Path Synopsis
cmd
findmetrics command
Generate a list of all metrics defined in project source files.
Generate a list of all metrics defined in project source files.
Package metricstest provides utilities for testing metrics.
Package metricstest provides utilities for testing metrics.

Jump to

Keyboard shortcuts

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