metrics

package module
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2021 License: MIT Imports: 17 Imported by: 0

README

Build Status Code Coverage Go Report Card GoDoc

Documentation

Index

Constants

View Source
const MetricConflict = -1

Variables

View Source
var Options singleton

Functions

func Count

func Count(id CounterMetric) bool

Count increments the metric indicated by id. A return value of false indicates the count could not occur.

func CountIf

func CountIf(id CounterMetric, condition bool) bool

CountIf increments the metric indicated by id if the supplied condition is true. A return value of false indicates that the count could not occur or the supplied condition was false.

func CountN

func CountN(id CounterMetric, increment int64) bool

Count increments the metric indicated by the number provided. A return value of false indicates the count could not occur.

func InitializeEnvironmentTags

func InitializeEnvironmentTags(tags string)

func InitializeTags

func InitializeTags(tags string, reader func(string) string)

func Measure

func Measure(id GaugeMetric, value int64) bool

Measure sets the metric indicated to the value specified. A return value of false indicates the count could not occur.

func Microseconds

func Microseconds(duration time.Duration) int64

Microseconds converts the duration value to microseconds, a commonly used unit of measurement for latency metrics. This return value could easily be used as a gauge or histogram measurement.

func Milliseconds

func Milliseconds(duration time.Duration) int64

Milliseconds converts the duration value to milliseconds, a possible unit of measurement for latency metrics. This return value could easily be used as a gauge or histogram measurement.

func RawCount

func RawCount(id CounterMetric, value int64) bool

RawCount is similar to Measure, except that the backend is still a counter but the application is now responsible for tracking the count rather than the metric itself tracking it. A return value of false indicates the count could not occur.

func Record

func Record(id HistogramMetric, value int64) bool

Record records the value with the histogram indicated. A return value of false indicates the count could not occur.

func StartAppOptics

func StartAppOptics(key string, queueCapacity, writers int) error

StartAppOptics configures a new metrics instance, specifies a number of AppOptics writers, and starts measuring.

func StartAppOpticsConfig

func StartAppOpticsConfig(configLoader AppOpticsConfigLoader, queueCapacity, writers int) error

StartAppOpticsConfig uses the provided configLoader to configure a new metrics instance, specify a number of AppOptics writers, and start measuring.

func StartMeasuring

func StartMeasuring()

StartMeasuring signals to this library that all registrations have been performed.

func StopMeasuring

func StopMeasuring()

StopMeasuring turns measurement tracking off. It can be turned on again by calling StartMeasuring.

func TagAll

func TagAll(tagPairs ...string)

TagAll sets key/value pairs for all metrics.

func TagCounter

func TagCounter(id CounterMetric, tagPairs ...string)

TagCounter associates key/value string pairs with the provided metric id.

func TagGauge

func TagGauge(id GaugeMetric, tagPairs ...string)

TagGauge associates key/value string pairs with the provided metric id.

func TagHistogram

func TagHistogram(id HistogramMetric, tagPairs ...string)

TagHistogram associates key/value string pairs with the provided metric id.

Types

type AppOptics

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

func (*AppOptics) Listen

func (this *AppOptics) Listen(queue chan []MetricMeasurement)

type AppOpticsConfig

type AppOpticsConfig struct {
	Key string
}

type AppOpticsConfigLoader

type AppOpticsConfigLoader func() AppOpticsConfig

type AtomicMetric

type AtomicMetric struct {
	*ReportingFrequency
	// contains filtered or unexported fields
}

func NewAtomicMetric

func NewAtomicMetric(name string, update time.Duration, metricType int) *AtomicMetric

func NewCounter

func NewCounter(name string, update time.Duration) *AtomicMetric

func NewGauge

func NewGauge(name string, update time.Duration) *AtomicMetric

func (*AtomicMetric) Add

func (this *AtomicMetric) Add(delta int64)

func (*AtomicMetric) Measure

func (this *AtomicMetric) Measure() MetricMeasurement

func (*AtomicMetric) Set

func (this *AtomicMetric) Set(value int64)

type CounterMetric

type CounterMetric int

func AddCounter

func AddCounter(name string, reportingFrequency time.Duration) CounterMetric

AddCounter registers a named counter metric along with the desired reporting frequency. The function is meant to be called *only* at application startup and is not thread safe. A negative return value indicates that the registration was unsuccessful.

type GaugeMetric

type GaugeMetric int

func AddGauge

func AddGauge(name string, reportingFrequency time.Duration) GaugeMetric

AddGauge registers a named gauge metric along with the desired reporting frequency. The function is meant to be called *only* at application startup and is not thread safe. A negative return value indicates that the registration was unsuccessful.

type Histogram

type Histogram interface {
	RecordValue(v int64) error
	Min() int64
	Max() int64
	Mean() float64
	StdDev() float64
	TotalCount() int64
	ValueAtQuantile(q float64) int64
}

type HistogramMaxMetric

type HistogramMaxMetric struct {
	*ReportingFrequency
	// contains filtered or unexported fields
}

func NewHistogramMaxMetric

func NewHistogramMaxMetric(basename string, histogram Histogram, update time.Duration) *HistogramMaxMetric

func (*HistogramMaxMetric) Measure

func (this *HistogramMaxMetric) Measure() MetricMeasurement

type HistogramMeanMetric

type HistogramMeanMetric struct {
	*ReportingFrequency
	// contains filtered or unexported fields
}

func NewHistogramMeanMetric

func NewHistogramMeanMetric(basename string, histogram Histogram, update time.Duration) *HistogramMeanMetric

func (*HistogramMeanMetric) Measure

func (this *HistogramMeanMetric) Measure() MetricMeasurement

type HistogramMetric

type HistogramMetric int

func AddHistogram

func AddHistogram(
	name string, reportingFrequency time.Duration,
	min, max int64, resolution int, quantiles ...float64) HistogramMetric

AddHistogram registers a named histogram metric along with the desired reporting frequency. The function is meant to be called *only* at application startup and is not thread safe. A negative return value indicates that the registration was unsuccessful.

type HistogramMinMetric

type HistogramMinMetric struct {
	*ReportingFrequency
	// contains filtered or unexported fields
}

func NewHistogramMinMetric

func NewHistogramMinMetric(basename string, histogram Histogram, update time.Duration) *HistogramMinMetric

func (*HistogramMinMetric) Measure

func (this *HistogramMinMetric) Measure() MetricMeasurement

type HistogramQuantileMetric

type HistogramQuantileMetric struct {
	*ReportingFrequency
	// contains filtered or unexported fields
}

func NewHistogramQuantileMetric

func NewHistogramQuantileMetric(
	basename string, quantile float64, histogram Histogram, update time.Duration) *HistogramQuantileMetric

func (*HistogramQuantileMetric) Measure

type HistogramStandardDeviationMetric

type HistogramStandardDeviationMetric struct {
	*ReportingFrequency
	// contains filtered or unexported fields
}

func NewHistogramStandardDeviationMetric

func NewHistogramStandardDeviationMetric(
	basename string, histogram Histogram, update time.Duration) *HistogramStandardDeviationMetric

func (*HistogramStandardDeviationMetric) Measure

type HistogramTotalCountMetric

type HistogramTotalCountMetric struct {
	*ReportingFrequency
	// contains filtered or unexported fields
}

func NewHistogramTotalCountMetric

func NewHistogramTotalCountMetric(
	basename string, histogram Histogram, update time.Duration) *HistogramTotalCountMetric

func (*HistogramTotalCountMetric) Measure

type ListenCloser added in v1.3.1

type ListenCloser interface {
	Listen()
	io.Closer
}

func NewListener added in v1.3.1

func NewListener(key string, options ...option) ListenCloser

type Measurement

type Measurement struct {
	Name  string            `json:"name"`
	Value int64             `json:"value"`
	Time  int64             `json:"time"`
	Tags  map[string]string `json:"tags"`
}

type Measurements

type Measurements struct {
	Measurements []Measurement `json:"measurements"`
}

type Metric

type Metric interface {
	MeasurementIsOverdue(now time.Time) bool
	Measure() MetricMeasurement
	ScheduleNextMeasurement(now time.Time)
}

type MetricMeasurement

type MetricMeasurement struct {
	Captured   time.Time
	ID         int
	Name       string
	MetricType int
	Value      int64
	Tags       map[string]string
}

type Metrics

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

Metrics can be used as a struct field and overridden with the Capture function in unit test setups to allow assertions on counted and measured values. This approach is similar to the one employed by the clock package (see github.com/smartystreets/clock).

func Capture

func Capture() *Metrics

func (*Metrics) Count

func (this *Metrics) Count(id CounterMetric) bool

func (*Metrics) CountIf

func (this *Metrics) CountIf(id CounterMetric, condition bool) bool

func (*Metrics) CountN

func (this *Metrics) CountN(id CounterMetric, increment int64) bool

func (*Metrics) CounterValue

func (this *Metrics) CounterValue(id CounterMetric) int64

Helper functions for test assertions:

func (*Metrics) GaugeValue

func (this *Metrics) GaugeValue(id GaugeMetric) int64

func (*Metrics) HistogramValue

func (this *Metrics) HistogramValue(id HistogramMetric) Histogram

func (*Metrics) Measure

func (this *Metrics) Measure(id GaugeMetric, value int64) bool

func (*Metrics) RawCount

func (this *Metrics) RawCount(id CounterMetric, value int64) bool

func (*Metrics) Record

func (this *Metrics) Record(id HistogramMetric, value int64) bool

type MetricsTracker

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

func New

func New() *MetricsTracker

func (*MetricsTracker) AddCounter

func (this *MetricsTracker) AddCounter(name string, update time.Duration) CounterMetric

func (*MetricsTracker) AddGauge

func (this *MetricsTracker) AddGauge(name string, update time.Duration) GaugeMetric

func (*MetricsTracker) AddHistogram

func (this *MetricsTracker) AddHistogram(
	name string, update time.Duration, min, max int64, resolution int, quantiles ...float64,
) HistogramMetric

func (*MetricsTracker) Count

func (this *MetricsTracker) Count(id CounterMetric) bool

func (*MetricsTracker) CountN

func (this *MetricsTracker) CountN(id CounterMetric, n int64) bool

func (*MetricsTracker) Measure

func (this *MetricsTracker) Measure(id GaugeMetric, value int64) bool

func (*MetricsTracker) RawCount

func (this *MetricsTracker) RawCount(id CounterMetric, value int64) bool

func (*MetricsTracker) Record

func (this *MetricsTracker) Record(id HistogramMetric, value int64) bool

func (*MetricsTracker) StartMeasuring

func (this *MetricsTracker) StartMeasuring()

func (*MetricsTracker) StopMeasuring

func (this *MetricsTracker) StopMeasuring()

func (*MetricsTracker) TagAll

func (this *MetricsTracker) TagAll(tagPairs ...string)

func (*MetricsTracker) TagCounter

func (this *MetricsTracker) TagCounter(metric CounterMetric, tagPairs ...string)

func (*MetricsTracker) TagGauge

func (this *MetricsTracker) TagGauge(metric GaugeMetric, tagPairs ...string)

func (*MetricsTracker) TagHistogram

func (this *MetricsTracker) TagHistogram(metric HistogramMetric, tagPairs ...string)

func (*MetricsTracker) TakeMeasurements

func (this *MetricsTracker) TakeMeasurements(now time.Time) (measurements []MetricMeasurement)

type ReportingFrequency

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

func (*ReportingFrequency) MeasurementIsOverdue

func (this *ReportingFrequency) MeasurementIsOverdue(now time.Time) (overdue bool)

func (*ReportingFrequency) ScheduleNextMeasurement

func (this *ReportingFrequency) ScheduleNextMeasurement(now time.Time)

type SynchronizedHistogram

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

func NewSynchronizedHistogram

func NewSynchronizedHistogram(inner Histogram, readLock, writeLock sync.Locker) *SynchronizedHistogram

func (*SynchronizedHistogram) Max

func (this *SynchronizedHistogram) Max() int64

func (*SynchronizedHistogram) Mean

func (this *SynchronizedHistogram) Mean() float64

func (*SynchronizedHistogram) Min

func (this *SynchronizedHistogram) Min() int64

func (*SynchronizedHistogram) RecordValue

func (this *SynchronizedHistogram) RecordValue(v int64) error

func (*SynchronizedHistogram) StdDev

func (this *SynchronizedHistogram) StdDev() float64

func (*SynchronizedHistogram) TotalCount

func (this *SynchronizedHistogram) TotalCount() int64

func (*SynchronizedHistogram) ValueAtQuantile

func (this *SynchronizedHistogram) ValueAtQuantile(q float64) int64

Directories

Path Synopsis
internal
hdrhistogram
Package hdrhistogram provides an implementation of Gil Tene's HDR Histogram data structure.
Package hdrhistogram provides an implementation of Gil Tene's HDR Histogram data structure.

Jump to

Keyboard shortcuts

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