memmetrics

package
Version: v2.0.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RTCounter

func RTCounter(new NewCounterFn) rrOptSetter

RTCounter set a builder function for Counter

func RTHistogram

func RTHistogram(fn NewRollingHistogramFn) rrOptSetter

RTHistogram set a builder function for RollingHistogram

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 essence 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)

SplitLatencies 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 HDRHistogram

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

HDRHistogram is a tiny wrapper around github.com/codahale/hdrhistogram that provides convenience functions for measuring http latencies

func NewHDRHistogram

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

NewHDRHistogram creates a new HDRHistogram

func (*HDRHistogram) Export

func (h *HDRHistogram) Export() *HDRHistogram

Export export a HDRHistogram

func (*HDRHistogram) LatencyAtQuantile

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

LatencyAtQuantile sets latency at quantile with microsecond precision

func (*HDRHistogram) Merge

func (h *HDRHistogram) Merge(other *HDRHistogram) error

Merge merge a HDRHistogram

func (*HDRHistogram) RecordLatencies

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

RecordLatencies Records latencies with microsecond precision

func (*HDRHistogram) RecordValues

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

RecordValues sets record values

func (*HDRHistogram) Reset

func (h *HDRHistogram) Reset()

Reset reset a HDRHistogram

func (*HDRHistogram) ValueAtQuantile

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

ValueAtQuantile sets value at quantile

type NewCounterFn

type NewCounterFn func() (*RollingCounter, error)

NewCounterFn builder function type

type NewRTMetricsFn

type NewRTMetricsFn func() (*RTMetrics, error)

NewRTMetricsFn builder function type

type NewRollingHistogramFn

type NewRollingHistogramFn func() (*RollingHDRHistogram, error)

NewRollingHistogramFn builder function type

type RTMetrics

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

RTMetrics 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 RTOptions for more detail on parameters.

func NewRTMetrics

func NewRTMetrics(settings ...rrOptSetter) (*RTMetrics, error)

NewRTMetrics returns new instance of metrics collector.

func (*RTMetrics) Append

func (m *RTMetrics) Append(other *RTMetrics) error

Append append a metric

func (*RTMetrics) CounterWindowSize

func (m *RTMetrics) CounterWindowSize() time.Duration

CounterWindowSize gets total windows size

func (*RTMetrics) Export

func (m *RTMetrics) Export() *RTMetrics

Export Returns a new RTMetrics which is a copy of the current one

func (*RTMetrics) LatencyHistogram

func (m *RTMetrics) LatencyHistogram() (*HDRHistogram, error)

LatencyHistogram computes and returns resulting histogram with latencies observed.

func (*RTMetrics) NetworkErrorCount

func (m *RTMetrics) NetworkErrorCount() int64

NetworkErrorCount returns total count of processed requests observed

func (*RTMetrics) NetworkErrorRatio

func (m *RTMetrics) NetworkErrorRatio() float64

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

func (*RTMetrics) Record

func (m *RTMetrics) Record(code int, duration time.Duration)

Record records a metric

func (*RTMetrics) Reset

func (m *RTMetrics) Reset()

Reset reset metrics

func (*RTMetrics) ResponseCodeRatio

func (m *RTMetrics) ResponseCodeRatio(startA, endA, startB, endB int) float64

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

func (*RTMetrics) StatusCodesCounts

func (m *RTMetrics) StatusCodesCounts() map[int]int64

StatusCodesCounts returns map with counts of the response codes

func (*RTMetrics) TotalCount

func (m *RTMetrics) TotalCount() int64

TotalCount returns total count of processed requests collected.

type RatioCounter

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

RatioCounter calculates a ratio of a/a+b over a rolling window of predefined buckets

func NewRatioCounter

func NewRatioCounter(buckets int, resolution time.Duration, options ...ratioOptSetter) (*RatioCounter, error)

NewRatioCounter creates a new RatioCounter

func (*RatioCounter) Buckets

func (r *RatioCounter) Buckets() int

Buckets gets buckets

func (*RatioCounter) CountA

func (r *RatioCounter) CountA() int64

CountA gets count A

func (*RatioCounter) CountB

func (r *RatioCounter) CountB() int64

CountB gets count B

func (*RatioCounter) IncA

func (r *RatioCounter) IncA(v int)

IncA increment counter A

func (*RatioCounter) IncB

func (r *RatioCounter) IncB(v int)

IncB increment counter B

func (*RatioCounter) IsReady

func (r *RatioCounter) IsReady() bool

IsReady returns true if the counter is ready

func (*RatioCounter) ProcessedCount

func (r *RatioCounter) ProcessedCount() int64

ProcessedCount gets processed count

func (*RatioCounter) Ratio

func (r *RatioCounter) Ratio() float64

Ratio gets ratio

func (*RatioCounter) Reset

func (r *RatioCounter) Reset()

Reset reset the counter

func (*RatioCounter) Resolution

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

Resolution gets resolution

func (*RatioCounter) WindowSize

func (r *RatioCounter) WindowSize() time.Duration

WindowSize gets windows size

type RollingCounter

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

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

func NewCounter

func NewCounter(buckets int, resolution time.Duration, options ...rcOptSetter) (*RollingCounter, error)

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

func (*RollingCounter) Append

func (c *RollingCounter) Append(o *RollingCounter) error

Append append a counter

func (*RollingCounter) Buckets

func (c *RollingCounter) Buckets() int

Buckets gets buckets

func (*RollingCounter) Clone

func (c *RollingCounter) Clone() *RollingCounter

Clone clone a counter

func (*RollingCounter) Count

func (c *RollingCounter) Count() int64

Count counts

func (*RollingCounter) CountedBuckets

func (c *RollingCounter) CountedBuckets() int

CountedBuckets gets counted buckets

func (*RollingCounter) Inc

func (c *RollingCounter) Inc(v int)

Inc increment counter

func (*RollingCounter) Reset

func (c *RollingCounter) Reset()

Reset reset a counter

func (*RollingCounter) Resolution

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

Resolution gets resolution

func (*RollingCounter) WindowSize

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

WindowSize gets windows size

type RollingHDRHistogram

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

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

func NewRollingHDRHistogram

func NewRollingHDRHistogram(low, high int64, sigfigs int, period time.Duration, bucketCount int, options ...rhOptSetter) (*RollingHDRHistogram, error)

NewRollingHDRHistogram created a new RollingHDRHistogram

func (*RollingHDRHistogram) Append

Append append a RollingHDRHistogram

func (*RollingHDRHistogram) Export

Export export a RollingHDRHistogram

func (*RollingHDRHistogram) Merged

func (r *RollingHDRHistogram) Merged() (*HDRHistogram, error)

Merged gets merged histogram

func (*RollingHDRHistogram) RecordLatencies

func (r *RollingHDRHistogram) RecordLatencies(v time.Duration, n int64) error

RecordLatencies sets records latencies

func (*RollingHDRHistogram) RecordValues

func (r *RollingHDRHistogram) RecordValues(v, n int64) error

RecordValues set record values

func (*RollingHDRHistogram) Reset

func (r *RollingHDRHistogram) Reset()

Reset reset a RollingHDRHistogram

type TestMeter

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

TestMeter a test meter

func (*TestMeter) GetRate

func (tm *TestMeter) GetRate() float64

GetRate gets rate

func (*TestMeter) GetWindowSize

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

GetWindowSize gets windows size

func (*TestMeter) IsReady

func (tm *TestMeter) IsReady() bool

IsReady returns true if the meter is ready

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL