Documentation ¶
Index ¶
- func IntAverage(arr []int64) float64
- func ResultTypeBool(ok bool) string
- type Collector
- type Counter
- type CounterGroup
- type HealthStatus
- type IntWindow
- type MethodTracker
- func (t *MethodTracker) AddCount(name string, result string)
- func (t *MethodTracker) Count(method string) (*CounterGroup, bool)
- func (t *MethodTracker) Instrument(name string, fn func() (interface{}, error)) (interface{}, error)
- func (t *MethodTracker) InstrumentResult(name string, fn func() *TrackResult) (interface{}, error)
- func (t *MethodTracker) Latencies(method string) (*IntWindow, bool)
- func (t *MethodTracker) Methods() []string
- func (t *MethodTracker) Stats() Metrics
- func (t *MethodTracker) StoreLatency(name string, latency int64)
- type MethodTrackerProps
- type Metrics
- type TrackResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IntAverage ¶
IntAverage calculates the average of a slice. Returns 0 if slice is empty
func ResultTypeBool ¶
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
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 ¶
NewWindow creates a new window that samples at most maxSamples
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 ¶
MethodTrackerProps are the properties used to define the behaviour of a MethodTracker
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