stats

package
v1.67.0-dev Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Overview

Package stats contains experimental metrics/stats API's.

Index

Constants

This section is empty.

Variables

View Source
var DefaultMetrics = NewMetrics()

DefaultMetrics are the default metrics registered through global metrics registry. This is written to at initialization time only, and is read only after initialization.

Functions

This section is empty.

Types

type Float64CountHandle

type Float64CountHandle MetricDescriptor

Float64CountHandle is a typed handle for a float count metric. This handle is passed at the recording point in order to know which metric to record on.

func RegisterFloat64Count

func RegisterFloat64Count(descriptor MetricDescriptor) *Float64CountHandle

RegisterFloat64Count registers the metric description onto the global registry. It returns a typed handle to use to recording data.

NOTE: this function must only be called during initialization time (i.e. in an init() function), and is not thread-safe. If multiple metrics are registered with the same name, this function will panic.

func (*Float64CountHandle) Descriptor

func (h *Float64CountHandle) Descriptor() *MetricDescriptor

Descriptor returns the float64 count handle typecast to a pointer to a MetricDescriptor.

func (*Float64CountHandle) Record

func (h *Float64CountHandle) Record(recorder MetricsRecorder, incr float64, labels ...string)

Record records the float64 count value on the metrics recorder provided.

type Float64HistoHandle

type Float64HistoHandle MetricDescriptor

Float64HistoHandle is a typed handle for a float histogram metric. This handle is passed at the recording point in order to know which metric to record on.

func RegisterFloat64Histo

func RegisterFloat64Histo(descriptor MetricDescriptor) *Float64HistoHandle

RegisterFloat64Histo registers the metric description onto the global registry. It returns a typed handle to use to recording data.

NOTE: this function must only be called during initialization time (i.e. in an init() function), and is not thread-safe. If multiple metrics are registered with the same name, this function will panic.

func (*Float64HistoHandle) Descriptor

func (h *Float64HistoHandle) Descriptor() *MetricDescriptor

Descriptor returns the float64 histo handle typecast to a pointer to a MetricDescriptor.

func (*Float64HistoHandle) Record

func (h *Float64HistoHandle) Record(recorder MetricsRecorder, incr float64, labels ...string)

Record records the float64 histo value on the metrics recorder provided.

type Int64CountHandle

type Int64CountHandle MetricDescriptor

Int64CountHandle is a typed handle for a int count metric. This handle is passed at the recording point in order to know which metric to record on.

func RegisterInt64Count

func RegisterInt64Count(descriptor MetricDescriptor) *Int64CountHandle

RegisterInt64Count registers the metric description onto the global registry. It returns a typed handle to use to recording data.

NOTE: this function must only be called during initialization time (i.e. in an init() function), and is not thread-safe. If multiple metrics are registered with the same name, this function will panic.

func (*Int64CountHandle) Descriptor

func (h *Int64CountHandle) Descriptor() *MetricDescriptor

Descriptor returns the int64 count handle typecast to a pointer to a MetricDescriptor.

func (*Int64CountHandle) Record

func (h *Int64CountHandle) Record(recorder MetricsRecorder, incr int64, labels ...string)

Record records the int64 count value on the metrics recorder provided.

type Int64GaugeHandle

type Int64GaugeHandle MetricDescriptor

Int64GaugeHandle is a typed handle for an int gauge metric. This handle is passed at the recording point in order to know which metric to record on.

func RegisterInt64Gauge

func RegisterInt64Gauge(descriptor MetricDescriptor) *Int64GaugeHandle

RegisterInt64Gauge registers the metric description onto the global registry. It returns a typed handle to use to recording data.

NOTE: this function must only be called during initialization time (i.e. in an init() function), and is not thread-safe. If multiple metrics are registered with the same name, this function will panic.

func (*Int64GaugeHandle) Descriptor

func (h *Int64GaugeHandle) Descriptor() *MetricDescriptor

Descriptor returns the int64 gauge handle typecast to a pointer to a MetricDescriptor.

func (*Int64GaugeHandle) Record

func (h *Int64GaugeHandle) Record(recorder MetricsRecorder, incr int64, labels ...string)

Record records the int64 histo value on the metrics recorder provided.

type Int64HistoHandle

type Int64HistoHandle MetricDescriptor

Int64HistoHandle is a typed handle for an int histogram metric. This handle is passed at the recording point in order to know which metric to record on.

func RegisterInt64Histo

func RegisterInt64Histo(descriptor MetricDescriptor) *Int64HistoHandle

RegisterInt64Histo registers the metric description onto the global registry. It returns a typed handle to use to recording data.

NOTE: this function must only be called during initialization time (i.e. in an init() function), and is not thread-safe. If multiple metrics are registered with the same name, this function will panic.

func (*Int64HistoHandle) Descriptor

func (h *Int64HistoHandle) Descriptor() *MetricDescriptor

Descriptor returns the int64 histo handle typecast to a pointer to a MetricDescriptor.

func (*Int64HistoHandle) Record

func (h *Int64HistoHandle) Record(recorder MetricsRecorder, incr int64, labels ...string)

Record records the int64 histo value on the metrics recorder provided.

type Metric

type Metric string

Metric is an identifier for a metric.

type MetricDescriptor

type MetricDescriptor struct {
	// The name of this metric. This name must be unique across the whole binary
	// (including any per call metrics). See
	// https://github.com/grpc/proposal/blob/master/A79-non-per-call-metrics-architecture.md#metric-instrument-naming-conventions
	// for metric naming conventions.
	Name Metric
	// The description of this metric.
	Description string
	// The unit (e.g. entries, seconds) of this metric.
	Unit string
	// The required label keys for this metric. These are intended to
	// metrics emitted from a stats handler.
	Labels []string
	// The optional label keys for this metric. These are intended to attached
	// to metrics emitted from a stats handler if configured.
	OptionalLabels []string
	// Whether this metric is on by default.
	Default bool
	// The type of metric. This is set by the metric registry, and not intended
	// to be set by a component registering a metric.
	Type MetricType
	// Bounds are the bounds of this metric. This only applies to histogram
	// metrics. If unset or set with length 0, stats handlers will fall back to
	// default bounds.
	Bounds []float64
}

MetricDescriptor is the data for a registered metric.

func DescriptorForMetric

func DescriptorForMetric(metric Metric) *MetricDescriptor

DescriptorForMetric returns the MetricDescriptor from the global registry.

Returns nil if MetricDescriptor not present.

type MetricType

type MetricType int

MetricType is the type of metric.

const (
	MetricTypeIntCount MetricType = iota
	MetricTypeFloatCount
	MetricTypeIntHisto
	MetricTypeFloatHisto
	MetricTypeIntGauge
)

Type of metric supported by this instrument registry.

type Metrics

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

Metrics is a set of metrics to record. Once created, Metrics is immutable, however Add and Remove can make copies with specific metrics added or removed, respectively.

Do not construct directly; use NewMetrics instead.

func NewMetrics

func NewMetrics(metrics ...Metric) *Metrics

NewMetrics returns a Metrics containing Metrics.

func (*Metrics) Add

func (m *Metrics) Add(metrics ...Metric) *Metrics

Add adds the metrics to the metrics set and returns a new copy with the additional metrics.

func (*Metrics) Join

func (m *Metrics) Join(metrics *Metrics) *Metrics

Join joins the metrics passed in with the metrics set, and returns a new copy with the merged metrics.

func (*Metrics) Metrics

func (m *Metrics) Metrics() map[Metric]bool

Metrics returns the metrics set. The returned map is read-only and must not be modified.

func (*Metrics) Remove

func (m *Metrics) Remove(metrics ...Metric) *Metrics

Remove removes the metrics from the metrics set and returns a new copy with the metrics removed.

type MetricsRecorder

type MetricsRecorder interface {
	// RecordInt64Count records the measurement alongside labels on the int
	// count associated with the provided handle.
	RecordInt64Count(handle *Int64CountHandle, incr int64, labels ...string)
	// RecordFloat64Count records the measurement alongside labels on the float
	// count associated with the provided handle.
	RecordFloat64Count(handle *Float64CountHandle, incr float64, labels ...string)
	// RecordInt64Histo records the measurement alongside labels on the int
	// histo associated with the provided handle.
	RecordInt64Histo(handle *Int64HistoHandle, incr int64, labels ...string)
	// RecordFloat64Histo records the measurement alongside labels on the float
	// histo associated with the provided handle.
	RecordFloat64Histo(handle *Float64HistoHandle, incr float64, labels ...string)
	// RecordInt64Gauge records the measurement alongside labels on the int
	// gauge associated with the provided handle.
	RecordInt64Gauge(handle *Int64GaugeHandle, incr int64, labels ...string)
}

MetricsRecorder records on metrics derived from metric registry.

Jump to

Keyboard shortcuts

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