metrics

package
v0.0.0-...-b70feef Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: Apache-2.0 Imports: 14 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewHttp = utilhttp.DeclareServer(
	func(HttpArgs) string { return "prometheus-http" },
	defaultHttpPort,
	defaultHttpsPort,
	func(HttpArgs, *flag.FlagSet) HttpOptions { return HttpOptions{} },
	func(_ HttpArgs, requests *component.DepRequests) httpDeps {
		return httpDeps{
			comp: component.DepPtr(requests, newRegistry()),
		}
	},
	func(_ HttpArgs, _ HttpOptions, deps httpDeps, mux *http.ServeMux) (*httpState, error) {

		mux.Handle("/", promhttp.HandlerFor(deps.comp.Get().PrometheusRegistry, promhttp.HandlerOpts{
			Registry: deps.comp.Get().PrometheusRegistry,
		}))

		return &httpState{}, nil
	},
	component.Lifecycle[HttpArgs, HttpOptions, httpDeps, httpState]{
		Start:        nil,
		Join:         nil,
		HealthChecks: nil,
	},
	func(HttpArgs, HttpOptions, httpDeps, *httpState) util.Empty { return util.Empty{} },
)

Functions

func Repeating

func Repeating[V any](
	ctx context.Context,
	deps ObserverDeps,
	handle TaggedHandle[V],
	getter func() V,
)

Types

type AnyField

type AnyField[StructType any] interface {
	InitFieldCollector(namePrefix string, helpPrefix string, tagKeys []string) prometheus.Collector
	EmitField(tagValues []string, value StructType)
}

A type-erased interface for Field[StructType, *].

func NewField

func NewField[StructType any, FieldType any](
	name string,
	help string,
	metricType Type[FieldType],
	extractor func(StructType) FieldType,
) AnyField[StructType]

type Emitter

type Emitter[Value any] interface {
	Emit(tagValues []string, value Value)
}

type Field

type Field[StructType any, FieldType any] struct {
	Name       string
	Help       string
	MetricType Type[FieldType]
	Extractor  func(StructType) FieldType
}

func (Field[StructType, FieldType]) EmitField

func (field Field[StructType, FieldType]) EmitField(tagValues []string, value StructType)

func (Field[StructType, FieldType]) InitFieldCollector

func (field Field[StructType, FieldType]) InitFieldCollector(namePrefix string, helpPrefix string, tagKeys []string) prometheus.Collector

type Flushable

type Flushable interface {
	Flush()
}

type FlushableType

type FlushableType[Value any] interface {
	// Do not extend Type[Value] directly to avoid accidentally passing into `Register.
	AsType() Type[Value]
	Flushable
}

type Handle

type Handle[Tags any, Value any] struct {
	// contains filtered or unexported fields
}

func Register

func Register[Value any, Tags any](
	registry Registry,
	name string,
	help string,
	metricType Type[Value],
	tagsDesc TagsDesc[Tags],
) Handle[Tags, Value]

func RegisterFlushable

func RegisterFlushable[Value any, Tags any](
	registry Registry,
	name string,
	help string,
	metricType FlushableType[Value],
	tagsDesc TagsDesc[Tags],
	frequency time.Duration,
) Handle[Tags, Value]

func RegisterMultiField

func RegisterMultiField[Value any, Tags any](
	registry Registry,
	namePrefix string,
	helpPrefix string,
	tagsDesc TagsDesc[Tags],
	fields ...AnyField[Value],
) Handle[Tags, Value]

func (Handle[Tags, Value]) Emit

func (handle Handle[Tags, Value]) Emit(value Value, tags Tags)

func (Handle[Tags, Value]) With

func (handle Handle[Tags, Value]) With(tags Tags) TaggedHandle[Value]

type HttpArgs

type HttpArgs struct{}

type HttpOptions

type HttpOptions struct{}

type ObserverDeps

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

func MakeObserverDeps

func MakeObserverDeps(requests *component.DepRequests) ObserverDeps

func (ObserverDeps) Registry

func (deps ObserverDeps) Registry() Registry

type Registry

type Registry struct {
	Prometheus *prometheus.Registry
	// contains filtered or unexported fields
}

type RegistryArgs

type RegistryArgs struct{}

type TaggedHandle

type TaggedHandle[Value any] struct {
	// contains filtered or unexported fields
}

func (TaggedHandle[Value]) Emit

func (handle TaggedHandle[Value]) Emit(value Value)

type TagsDesc

type TagsDesc[Instance any] interface {
	TagKeys() []string
	TagValues(instance Instance) []string
}

func NewReflectTags

func NewReflectTags[T any]() TagsDesc[T]

type Type

type Type[Value any] interface {
	InitCollector(name string, help string, tagKeys []string) prometheus.Collector
	Emitter[Value]
}

func AsyncLatencyDurationHistogram

func AsyncLatencyDurationHistogram() Type[time.Duration]

A histogram measuring the latency of an asynchronous operation.

func DurationGauge

func DurationGauge() Type[time.Duration]

func DurationHistogram

func DurationHistogram(buckets []float64) Type[time.Duration]

func ExponentialIntHistogram

func ExponentialIntHistogram(numBuckets int) Type[int]

func FloatCounter

func FloatCounter() Type[float64]

func FloatGauge

func FloatGauge() Type[float64]

func FunctionDurationHistogram

func FunctionDurationHistogram() Type[time.Duration]

A histogram measuring the time of a function execution.

func Int32Gauge

func Int32Gauge() Type[int32]

func Int64Gauge

func Int64Gauge() Type[int64]

func IntCounter

func IntCounter() Type[int]

func IntGauge

func IntGauge() Type[int]

func IntHistogram

func IntHistogram(buckets []int) Type[int]

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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