monitor

package
v0.0.0-...-38ef2fc Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2020 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package monitor helps monitoring of Go applications. The stop watch part allows to measure the execution time and retrieve how often it is called, minimum, maximum, and average durations. Another one is the stay-set indicator allowing to increase and decrease values and retrieve count, maximum, minimum, and current value. This can help to control and manage limiters or pools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, monitor Monitor) context.Context

NewContext creates a context containing a logger.

Types

type IndicatorValue

type IndicatorValue struct {
	ID      string
	Count   int
	Current int
	Min     int
	Max     int
}

IndicatorValue manages the value range for one indicator.

func (*IndicatorValue) String

func (iv *IndicatorValue) String() string

String implements fmt.Stringer.

type IndicatorValues

type IndicatorValues []IndicatorValue

IndicatorValues is a set of stay-set values.

func (IndicatorValues) Len

func (ivs IndicatorValues) Len() int

func (IndicatorValues) Less

func (ivs IndicatorValues) Less(i, j int) bool

func (IndicatorValues) Swap

func (ivs IndicatorValues) Swap(i, j int)

type Measuring

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

Measuring defines one execution time measuring containing the ID and the starting time of the measuring and able to pass this data after the end of the measuring to the measurer.

func (*Measuring) End

func (m *Measuring) End() time.Duration

End ends the measuring and passes it to the measurer.

type Monitor

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

Monitor combines StopWatch and StaySetIndicator.

func FromContext

func FromContext(ctx context.Context) (Monitor, bool)

FromContext retrieves a logger from a context.

func New

func New() *Monitor

New creates a new monitor.

func (*Monitor) Reset

func (m *Monitor) Reset()

Reset clears all collected values so far.

func (*Monitor) StaySetIndicator

func (m *Monitor) StaySetIndicator() *StaySetIndicator

StaySetIndicator returns a stay-set indicator instance.

func (*Monitor) Stop

func (m *Monitor) Stop()

Stop terminates the monitor.

func (*Monitor) StopWatch

func (m *Monitor) StopWatch() *StopWatch

StopWatch returns the internal stop watch instance.

type StaySetIndicator

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

StaySetIndicator allows to increase and decrease stay-set values.

func (*StaySetIndicator) Decrease

func (i *StaySetIndicator) Decrease(id string)

Decrease decreases a stay-set staySetIndicator.

func (*StaySetIndicator) Do

func (i *StaySetIndicator) Do(f func(IndicatorValue) error) error

Do performs the function f for all values.

func (*StaySetIndicator) Increase

func (i *StaySetIndicator) Increase(id string)

Increase increases a stay-set staySetIndicator.

func (*StaySetIndicator) Read

Read returns a stay-set staySetIndicator.

type StopWatch

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

StopWatch allows to measure the execution time of code fragments.

func (*StopWatch) Begin

func (s *StopWatch) Begin(id string) *Measuring

Begin starts a new measuring with a given id.

func (*StopWatch) Do

func (s *StopWatch) Do(f func(WatchValue) error) error

Do performs the function f for all measuring points.

func (*StopWatch) Measure

func (s *StopWatch) Measure(id string, f func()) time.Duration

Measure measures the execution time of one function.

func (*StopWatch) Read

func (s *StopWatch) Read(id string) (WatchValue, error)

Read returns the measuring point for an id.

type WatchValue

type WatchValue struct {
	ID    string
	Count int
	Total time.Duration
	Min   time.Duration
	Max   time.Duration
	Avg   time.Duration
}

WatchValue manages the value range for one watch.

func (*WatchValue) String

func (wv *WatchValue) String() string

String implements fmt.Stringer.

type WatchValues

type WatchValues []WatchValue

WatchValues is a set of values.

func (WatchValues) Len

func (wvs WatchValues) Len() int

func (WatchValues) Less

func (wvs WatchValues) Less(i, j int) bool

func (WatchValues) Swap

func (wvs WatchValues) Swap(i, j int)

Jump to

Keyboard shortcuts

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