metrics

package module
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2025 License: Apache-2.0 Imports: 13 Imported by: 47

README

Ziti Metrics Library

This is a metrics library which is built on, and extends the go-metrics library.

It extends it by adding the following:

  1. Support for interval counters. These collect event counts related to a given identifier, over a given interval. The interval buckets are flushed regularly. These are good for things like collecting usage data.
  2. A Dispose method is defined on metrics, so they can be cleaned up, for metrics tied to transient entities.
  3. Reference counted metrics

Documentation

Index

Constants

View Source
const (
	MetricNameCount      = "count"
	MetricNameMean       = "mean"
	MetricNameRateM1     = "rate_m1"
	MetricNameRateM5     = "rate_m5"
	MetricNameRateM15    = "rate_m15"
	MetricNameMin        = "min"
	MetricNameMax        = "max"
	MetricNamePercentile = "percentile"
)
View Source
const (
	DefaultIntervalAgeThreshold = 80 * time.Second

	MinEventQueueSize     = 16
	DefaultEventQueueSize = 256
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DelegatingReporter added in v1.4.1

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

func NewDelegatingReporter added in v1.4.1

func NewDelegatingReporter(registry Registry, sink MetricSink, closeNotify <-chan struct{}) *DelegatingReporter

func (*DelegatingReporter) Start added in v1.4.1

func (self *DelegatingReporter) Start(interval time.Duration)

func (*DelegatingReporter) VisitFloatMetric added in v1.4.1

func (self *DelegatingReporter) VisitFloatMetric(name string, val float64, extra string)

func (*DelegatingReporter) VisitGauge added in v1.4.1

func (self *DelegatingReporter) VisitGauge(name string, gauge Gauge)

func (*DelegatingReporter) VisitHistogram added in v1.4.1

func (self *DelegatingReporter) VisitHistogram(name string, metric Histogram)

func (*DelegatingReporter) VisitIntMetric added in v1.4.1

func (self *DelegatingReporter) VisitIntMetric(name string, val int64, extra string)

func (*DelegatingReporter) VisitMeter added in v1.4.1

func (self *DelegatingReporter) VisitMeter(name string, metric Meter)

func (*DelegatingReporter) VisitPercentileMetric added in v1.4.1

func (self *DelegatingReporter) VisitPercentileMetric(name string, val PercentileSource, extra string)

func (*DelegatingReporter) VisitTimer added in v1.4.1

func (self *DelegatingReporter) VisitTimer(name string, metric Timer)

type Gauge

type Gauge interface {
	Metric
	Value() int64
	Update(int64)
}

Gauge represents a metric which is measuring a count and a rate

type Handler

type Handler interface {
	// AcceptMetrics is called when new metrics become available
	AcceptMetrics(message *metrics_pb.MetricsMessage)
}

Handler represents a sink for metric events

type Histogram

type Histogram interface {
	Metric
	Count() int64
	Max() int64
	Mean() float64
	Min() int64
	Percentile(float64) float64
	Percentiles([]float64) []float64
	StdDev() float64
	Sum() int64
	Variance() float64

	Clear()
	Update(int64)
	CreateSnapshot() Histogram
}

Histogram represents a metric which is measuring the distribution of values for some measurement

type IntervalCounter

type IntervalCounter interface {
	Metric
	Update(intervalId string, time time.Time, value uint64)
}

IntervalCounter allows tracking counters which are bucketized by some interval

type Meter

type Meter interface {
	Metric
	Count() int64
	Rate1() float64
	Rate5() float64
	Rate15() float64
	RateMean() float64
	Mark(int64)
}

Meter represents a metric which is measuring a count and a rate

type Metric

type Metric interface {
	Dispose()
}

Metric is the base functionality for all metrics types

type MetricSink added in v1.4.1

type MetricSink interface {
	Filter(name string) bool
	StartReport(registry Registry)
	EndReport(registry Registry)
	AcceptIntMetric(name string, value int64)
	AcceptFloatMetric(name string, value float64)
	AcceptPercentileMetric(name string, value PercentileSource)
}

type PercentileSource added in v1.4.1

type PercentileSource interface {
	Percentile(float64) float64
}

type Registry

type Registry interface {
	// SourceId returns the source id of this Registry
	SourceId() string

	// Gauge returns a Gauge for the given name. If one does not yet exist, one will be created
	Gauge(name string) Gauge

	// FuncGauge returns a Gauge for the given name. If one does not yet exist, one will be created using
	// the given function
	FuncGauge(name string, f func() int64) Gauge

	// Meter returns a Meter for the given name. If one does not yet exist, one will be created
	Meter(name string) Meter

	// Histogram returns a Histogram for the given name. If one does not yet exist, one will be created
	Histogram(name string) Histogram

	// Timer returns a Timer for the given name. If one does not yet exist, one will be created
	Timer(name string) Timer

	// EachMetric calls the given visitor function for each Metric in this registry
	EachMetric(visitor func(name string, metric Metric))

	// GetGauge returns the Gauge for the given name or nil if a Gauge with that name doesn't exist
	GetGauge(name string) Gauge

	// GetMeter returns the Meter for the given name or nil if a Meter with that name doesn't exist
	GetMeter(name string) Meter

	// GetHistogram returns the Histogram for the given name or nil if a Histogram with that name doesn't exist
	GetHistogram(name string) Histogram

	// GetTimer returns the Timer for the given name or nil if a Timer with that name doesn't exist
	GetTimer(name string) Timer

	// IsValidMetric returns true if a metric with the given name exists in the registry, false otherwise
	IsValidMetric(name string) bool

	// Poll returns a MetricsMessage with a snapshot of the metrics in the Registry
	Poll() *metrics_pb.MetricsMessage

	AcceptVisitor(visitor Visitor)

	// DisposeAll removes and cleans up all metrics currently in the Registry
	DisposeAll()
}

Registry allows for configuring and accessing metrics for an application

func NewRegistry

func NewRegistry(sourceId string, tags map[string]string) Registry

type Timer

type Timer interface {
	Metric
	Count() int64
	Max() int64
	Mean() float64
	Min() int64
	Percentile(float64) float64
	Percentiles([]float64) []float64
	Rate1() float64
	Rate5() float64
	Rate15() float64
	RateMean() float64
	StdDev() float64
	Sum() int64
	Variance() float64

	Time(func())
	Update(time.Duration)
	UpdateSince(time.Time)
	CreateSnapshot() Timer
}

type UsageCounter added in v1.1.0

type UsageCounter interface {
	Metric
	Update(source UsageSource, usageType string, time time.Time, value uint64)
}

A UsageCounter allows tracking usage bucketized by some interval

type UsageRegistry

type UsageRegistry interface {
	Registry
	PollWithoutUsageMetrics() *metrics_pb.MetricsMessage
	IntervalCounter(name string, intervalSize time.Duration) IntervalCounter
	UsageCounter(name string, intervalSize time.Duration) UsageCounter
	FlushToHandler(handler Handler)
	StartReporting(eventSink Handler, reportInterval time.Duration, msgQueueSize int)
}

UsageRegistry extends registry to allow collecting usage metrics

func NewUsageRegistry

func NewUsageRegistry(config UsageRegistryConfig) UsageRegistry

type UsageRegistryConfig added in v1.3.0

type UsageRegistryConfig struct {
	SourceId             string
	Tags                 map[string]string
	EventQueueSize       int
	CloseNotify          <-chan struct{}
	IntervalAgeThreshold time.Duration
}

func DefaultUsageRegistryConfig added in v1.3.0

func DefaultUsageRegistryConfig(sourceId string, closeNotify <-chan struct{}) UsageRegistryConfig

type UsageSource added in v1.1.0

type UsageSource interface {
	GetIntervalId() string
	GetTags() map[string]string
}

type Visitor added in v1.4.0

type Visitor interface {
	VisitGauge(name string, gauge Gauge)
	VisitMeter(name string, meter Meter)
	VisitHistogram(name string, histogram Histogram)
	VisitTimer(name string, timer Timer)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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