metrics

package
v0.0.0-...-68da624 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2014 License: Apache-2.0 Imports: 10 Imported by: 9

Documentation

Overview

In memory request performance metrics

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNetworkError

func IsNetworkError(attempt request.Attempt) bool

func SplitFloat64

func SplitFloat64(threshold, sentinel float64, values []float64) (good map[float64]bool, bad map[float64]bool)

SplitFloat64 provides simple anomaly detection for skewed data sets with no particular distribution. In essense it applies the formula if(v > median(values) + threshold * medianAbsoluteDeviation) -> anomaly There's a corner case where there are just 2 values, so by definition there's no value that exceeds the threshold. This case is solved by introducing additional value that we know is good, e.g. 0. That helps to improve the detection results on such data sets.

func SplitLatencies

func SplitLatencies(values []time.Duration, precision time.Duration) (good map[time.Duration]bool, bad map[time.Duration]bool)

SplitRatios provides simple anomaly detection for requests latencies. it splits values into good or bad category based on the threshold and the median value. If all values are not far from the median, it will return all values in 'good' set. Precision is the smallest value to consider, e.g. if set to millisecond, microseconds will be ignored.

func SplitRatios

func SplitRatios(values []float64) (good map[float64]bool, bad map[float64]bool)

SplitRatios provides simple anomaly detection for ratio values, that are all in the range [0, 1] it splits values into good or bad category based on the threshold and the median value. If all values are not far from the median, it will return all values in 'good' set.

Types

type FailPredicate

type FailPredicate func(request.Attempt) bool

Predicate that helps to see if the attempt resulted in error

type FailRateMeter

type FailRateMeter interface {
	GetRate() float64
	IsReady() bool
	GetWindowSize() time.Duration
	middleware.Observer
}

type HDRHistogram

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

func NewHDRHistogram

func NewHDRHistogram(low, high int64, sigfigs int) (h *HDRHistogram, err error)

func (*HDRHistogram) LatencyAtQuantile

func (h *HDRHistogram) LatencyAtQuantile(q float64) time.Duration

Returns latency at quantile with microsecond precision

func (*HDRHistogram) Merge

func (h *HDRHistogram) Merge(o Histogram) error

func (*HDRHistogram) RecordLatencies

func (h *HDRHistogram) RecordLatencies(d time.Duration, n int64) error

Records latencies with microsecond precision

func (*HDRHistogram) RecordValues

func (h *HDRHistogram) RecordValues(v, n int64) error

func (*HDRHistogram) Reset

func (h *HDRHistogram) Reset()

func (*HDRHistogram) ValueAtQuantile

func (h *HDRHistogram) ValueAtQuantile(q float64) int64

type Histogram

type Histogram interface {
	// Returns latency at quantile with microsecond precision
	LatencyAtQuantile(float64) time.Duration
	// Records latencies with microsecond precision
	RecordLatencies(d time.Duration, n int64) error

	ValueAtQuantile(q float64) int64
	RecordValues(v, n int64) error
	// Merge updates this histogram with values of another histogram
	Merge(Histogram) error
	// Resets state of the histogram
	Reset()
}

type NewHistogramFn

type NewHistogramFn func() (Histogram, error)

NewHistogramFn is a constructor that can be passed to NewRollingHistogram

func NewHDRHistogramFn

func NewHDRHistogramFn(low, high int64, sigfigs int) NewHistogramFn

NewHDRHistogramFn creates a constructor of HDR histograms with predefined parameters.

type NewRollingCounterFn

type NewRollingCounterFn func() (*RollingCounter, error)

NewRollingCounterFn is a constructor of rolling counters.

type RollingCounter

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

Calculates in memory failure rate of an endpoint using rolling window of a predefined size

func NewRollingCounter

func NewRollingCounter(buckets int, resolution time.Duration, timeProvider timetools.TimeProvider) (*RollingCounter, error)

NewRollingCounter creates a counter with fixed amount of buckets that are rotated every resolition period. E.g. 10 buckets with 1 second means that every new second the bucket is refreshed, so it maintains 10 second rolling window.

func (*RollingCounter) Buckets

func (c *RollingCounter) Buckets() int

func (*RollingCounter) Count

func (c *RollingCounter) Count() int64

func (*RollingCounter) CountedBuckets

func (c *RollingCounter) CountedBuckets() int

func (*RollingCounter) GetWindowSize

func (c *RollingCounter) GetWindowSize() time.Duration

func (*RollingCounter) Inc

func (c *RollingCounter) Inc()

func (*RollingCounter) Reset

func (c *RollingCounter) Reset()

func (*RollingCounter) Resolution

func (c *RollingCounter) Resolution() time.Duration

type RollingHistogram

type RollingHistogram interface {
	RecordValues(v, n int64) error
	RecordLatencies(d time.Duration, n int64) error
	Merged() (Histogram, error)
	Reset()
}

RollingHistogram holds multiple histograms and rotates every period. It provides resulting histogram as a result of a call of 'Merged' function.

func NewRollingHistogram

func NewRollingHistogram(maker NewHistogramFn, bucketCount int, period time.Duration, timeProvider timetools.TimeProvider) (RollingHistogram, error)

type RollingMeter

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

Calculates various performance metrics about the endpoint using counters of the predefined size

func NewRollingMeter

func NewRollingMeter(endpoint endpoint.Endpoint, buckets int, resolution time.Duration, timeProvider timetools.TimeProvider, isError FailPredicate) (*RollingMeter, error)

func (*RollingMeter) Buckets

func (r *RollingMeter) Buckets() int

func (*RollingMeter) FailureCount

func (r *RollingMeter) FailureCount() int64

func (*RollingMeter) GetRate

func (r *RollingMeter) GetRate() float64

func (*RollingMeter) GetWindowSize

func (r *RollingMeter) GetWindowSize() time.Duration

func (*RollingMeter) IsReady

func (r *RollingMeter) IsReady() bool

func (*RollingMeter) ObserveRequest

func (r *RollingMeter) ObserveRequest(request.Request)

func (*RollingMeter) ObserveResponse

func (r *RollingMeter) ObserveResponse(req request.Request, lastAttempt request.Attempt)

func (*RollingMeter) ProcessedCount

func (r *RollingMeter) ProcessedCount() int64

func (*RollingMeter) Reset

func (r *RollingMeter) Reset()

func (*RollingMeter) Resolution

func (r *RollingMeter) Resolution() time.Duration

func (*RollingMeter) SuccessCount

func (r *RollingMeter) SuccessCount() int64

type RoundTripMetrics

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

RoundTripMetrics provides aggregated performance metrics for HTTP requests processing such as round trip latency, response codes counters network error and total requests. all counters are collected as rolling window counters with defined precision, histograms are a rolling window histograms with defined precision as well. See RoundTripOptions for more detail on parameters.

func NewRoundTripMetrics

func NewRoundTripMetrics(o RoundTripOptions) (*RoundTripMetrics, error)

NewRoundTripMetrics returns new instance of metrics collector.

func (*RoundTripMetrics) GetLatencyHistogram

func (m *RoundTripMetrics) GetLatencyHistogram() (Histogram, error)

GetLatencyHistogram computes and returns resulting histogram with latencies observed.

func (*RoundTripMetrics) GetNetworkErrorCount

func (m *RoundTripMetrics) GetNetworkErrorCount() int64

GetNetworkErrorCount returns total count of processed requests observed

func (*RoundTripMetrics) GetNetworkErrorRatio

func (m *RoundTripMetrics) GetNetworkErrorRatio() float64

GetNetworkErrorRatio calculates the amont of network errors such as time outs and dropped connection that occured in the given time window compared to the total requests count.

func (*RoundTripMetrics) GetOptions

func (m *RoundTripMetrics) GetOptions() *RoundTripOptions

GetOptions returns settings used for this instance

func (*RoundTripMetrics) GetResponseCodeRatio

func (m *RoundTripMetrics) GetResponseCodeRatio(startA, endA, startB, endB int) float64

GetResponseCodeRatio calculates ratio of count(startA to endA) / count(startB to endB)

func (*RoundTripMetrics) GetStatusCodesCounts

func (m *RoundTripMetrics) GetStatusCodesCounts() map[int]int64

GetStatusCodesCounts returns map with counts of the response codes

func (*RoundTripMetrics) GetTotalCount

func (m *RoundTripMetrics) GetTotalCount() int64

GetTotalCount returns total count of processed requests collected.

func (*RoundTripMetrics) RecordMetrics

func (m *RoundTripMetrics) RecordMetrics(a request.Attempt)

RecordMetrics updates internal metrics collection based on the data from passed request.

func (*RoundTripMetrics) Reset

func (m *RoundTripMetrics) Reset()

type RoundTripOptions

type RoundTripOptions struct {
	// CounterBuckets - how many buckets to allocate for rolling counter. Defaults to 10 buckets.
	CounterBuckets int
	// CounterResolution specifies the resolution for a single bucket
	// (e.g. time.Second means that bucket will be counted for a second).
	// defaults to time.Second
	CounterResolution time.Duration
	// HistMin - minimum non 0 value for a histogram (default 1)
	HistMin int64
	// HistMax - maximum value that can be recorded for a histogram (default 3,600,000,000)
	HistMax int64
	// HistSignificantFigures - defines precision for a value. e.g. 3 - 0.1%X precision, default is 2 - 1% precision for X
	HistSignificantFigures int
	// HistBuckets - how many sub histogram to keep in a rolling histogram, default is 6
	HistBuckets int
	// HistPeriod - rotation period for a histogram, default is 10 seconds
	HistPeriod time.Duration
	// TimeProvider - to provide time provider in tests, default is RealTime
	TimeProvider timetools.TimeProvider
}

type TestMeter

type TestMeter struct {
	Rate       float64
	NotReady   bool
	WindowSize time.Duration
}

func (*TestMeter) GetRate

func (tm *TestMeter) GetRate() float64

func (*TestMeter) GetWindowSize

func (tm *TestMeter) GetWindowSize() time.Duration

func (*TestMeter) IsReady

func (tm *TestMeter) IsReady() bool

func (*TestMeter) ObserveRequest

func (em *TestMeter) ObserveRequest(r request.Request)

func (*TestMeter) ObserveResponse

func (em *TestMeter) ObserveResponse(r request.Request, lastAttempt request.Attempt)

Jump to

Keyboard shortcuts

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