stats

package
v0.0.0-...-0001d10 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2020 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IntAverage

func IntAverage(arr []int64) float64

IntAverage calculates the average of a slice. Returns 0 if slice is empty

func ResultTypeBool

func ResultTypeBool(ok bool) string

ResultTypeBool returns the string representation of a bool result used for tracking

Types

type Collector

type Collector interface {
	Stats() Metrics
}

Collector is the interface for all types that generate an aggregation of statistic information implement

type Counter

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

Counter is used to count how many times an event occurs

func (*Counter) Incr

func (c *Counter) Incr() uint64

Increment increments the counter by one

func (*Counter) Value

func (c *Counter) Value() uint64

Get returns the current value of the counter

type CounterGroup

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

CounterGroup implements a group of counters where counters can be added dynamically

func NewCounterGroup

func NewCounterGroup(names ...string) *CounterGroup

NewCounterGroup creates a new counter group. All counters are allocated at the creation time.

func (*CounterGroup) Get

func (g *CounterGroup) Get(name string) *Counter

Get retrieves the counter from the group. If no counter is found associated to that specific name a catch all counter is returned

func (*CounterGroup) Incr

func (g *CounterGroup) Incr(name string) uint64

Incr increments the required counter and if it does not exist it creates it

func (*CounterGroup) Stats

func (g *CounterGroup) Stats() map[string]interface{}

Value implements Collector for CounterGroup

type HealthStatus

type HealthStatus uint

HealthStatus of a service. This status should be advertised by a service so that a health checker can know what action if any is required to keep the status on a Healthy state

const (
	// Healthy status means that the service is up and running
	// and can take incoming requests
	Healthy HealthStatus = 0

	// Drain a service so that it processes the requests that
	// already are inflight but does not take further requests
	Drain HealthStatus = 1

	// Unhealthy status for a service that should be restarted
	Unhealthy HealthStatus = 2
)

type IntWindow

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

IntWindow keeps a window of data based on the number of data it can hold. When the window is full, it discards the oldest data to leave space for new data

func NewIntWindow

func NewIntWindow(maxSamples uint32) *IntWindow

NewWindow creates a new window that samples at most maxSamples

func (*IntWindow) Add

func (w *IntWindow) Add(sample int64)

Add a new sample to the window, shifting the window if maxSamples has been exceeded

func (*IntWindow) Stats

func (w *IntWindow) Stats() Metrics

Stats is the implementation of Collector for IntWindow

type MethodTracker

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

MethodTracker tracks method calls and latencies. It is useful to track all the calls within a single type. All the information of what a MethodTracker needs to track is defined at initialization time to avoid concurrency issues with the implementation, so it favours immutability. If an unexpected method is tracked the result is stored in the special "undefined" category.

func NewMethodTracker

func NewMethodTracker(methods ...string) *MethodTracker

NewMethodTracker creates a new method tracker using the defaults ResultTypeBool for Result types.

func NewMethodTrackerWithResult

func NewMethodTrackerWithResult(props *MethodTrackerProps) *MethodTracker

NewMethodTrackerWithResult creates a new MethodTracker with the specified properties

func (*MethodTracker) AddCount

func (t *MethodTracker) AddCount(name string, result string)

AddCount is a method to manually add a count to a method

func (*MethodTracker) Count

func (t *MethodTracker) Count(method string) (*CounterGroup, bool)

Count returns the counter used to track the method calls. If the method is not found it return nil, false

func (*MethodTracker) Instrument

func (t *MethodTracker) Instrument(
	name string,
	fn func() (interface{}, error),
) (interface{}, error)

Instrument instruments the call to a method collecting counts and latencies. It uses the defaults ResultTypeBool for the collection

func (*MethodTracker) InstrumentResult

func (t *MethodTracker) InstrumentResult(
	name string,
	fn func() *TrackResult,
) (interface{}, error)

InstrumentResult instruments the call to a method collecting counts and latencies

func (*MethodTracker) Latencies

func (t *MethodTracker) Latencies(method string) (*IntWindow, bool)

Latencies returns the window used to track the method call latencies. If the method is not found it return nil, false

func (*MethodTracker) Methods

func (t *MethodTracker) Methods() []string

Methods returns the list of methods tracked

func (*MethodTracker) Stats

func (t *MethodTracker) Stats() Metrics

Stats is the implementation of Collector for MethodTracker

func (*MethodTracker) StoreLatency

func (t *MethodTracker) StoreLatency(name string, latency int64)

StoreLatency is a method to manually store a new latency sample for a method

type MethodTrackerProps

type MethodTrackerProps struct {
	Methods    []string
	Results    []string
	WindowSize uint32
}

MethodTrackerProps are the properties used to define the behaviour of a MethodTracker

type Metrics

type Metrics map[string]interface{}

type TrackResult

type TrackResult struct {
	// Value of the instrumented function that is passed on
	// to the caller
	Value interface{}

	// Error of the instrumented function that is passed on
	// to the caller
	Error error

	// Type is the representation of the type that is used
	// for instrumentation. It categorizes the result
	Type string
}

TrackResult is the result of an instrumented function

Jump to

Keyboard shortcuts

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