count

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Interval   = 0
	LastValue  = 1
	Statistics = 2
	Timestamp  = 3
	Increment  = 4
)

Types of counters that measure different types of metrics Interval: = 0 Counters that measure execution time intervals LastValue: = 1 Counters that keeps the latest measured value Statistics: = 2 Counters that measure min/average/max statistics Timestamp: = 3 Counter that record timestamps Increment: = 4 Counter that increment counters

Variables

View Source
var CompositeCountersDescriptor = refer.NewDescriptor("pip-services", "counters", "composite", "*", "1.0")
View Source
var LogCountersDescriptor = refer.NewDescriptor("pip-services", "counters", "log", "*", "1.0")
View Source
var NullCountersDescriptor = refer.NewDescriptor("pip-services", "counters", "null", "*", "1.0")

Creates ICounters components by their descriptors.

Functions

func NewDefaultCountersFactory

func NewDefaultCountersFactory() *build.Factory

Create a new instance of the factory. Returns *build.Factory

Types

type CachedCounters

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

Abstract implementation of performance counters that measures and stores counters in memory. Child classes implement saving of the counters into various destinations.

Configuration parameters options: interval: interval in milliseconds to save current counters measurements (default: 5 mins) reset_timeout: timeout in milliseconds to reset the counters. 0 disables the reset (default: 0)

func InheritCacheCounters

func InheritCacheCounters(saver ICountersSaver) *CachedCounters

Inherit cache counters from saver Parameters:

  • save ICountersSaver

Returns *CachedCounters

func (*CachedCounters) BeginTiming

func (c *CachedCounters) BeginTiming(name string) *Timing

Begins measurement of execution time interval. It returns Timing object which has to be called at Timing.endTiming to end the measurement and update the counter. Parameters

  • name string a counter name of Interval type.

Returns *Timing a Timing callback object to end timing.

func (*CachedCounters) Clear

func (c *CachedCounters) Clear(name string)

Clears (resets) a counter specified by its name. Parameters:

  • name string a counter name to clear.

func (*CachedCounters) ClearAll

func (c *CachedCounters) ClearAll()

Clears (resets) all counters.

func (*CachedCounters) Configure

func (c *CachedCounters) Configure(config *config.ConfigParams)

Configures component by passing configuration parameters. Parameters:

  • config *config.ConfigParams configuration parameters to be set.

func (*CachedCounters) Dump

func (c *CachedCounters) Dump() error

Dumps (saves) the current values of counters.

func (*CachedCounters) EndTiming

func (c *CachedCounters) EndTiming(name string, elapsed float32)

Ends measurement of execution elapsed time and updates specified counter. see Timing.endTiming Parameters:

  • name string a counter name elapsed float32 execution elapsed time in milliseconds to update the counter.

func (*CachedCounters) Get

func (c *CachedCounters) Get(name string, typ int) *Counter

Gets a counter specified by its name. It counter does not exist or its type doesn't match the specified type it creates a new one. Parameters:

  • name string a counter name to retrieve.
  • typ int a counter type.

Returns *Counter an existing or newly created counter of the specified type.

func (*CachedCounters) GetAll

func (c *CachedCounters) GetAll() []*Counter

Gets all captured counters. Returns []*Counter

func (*CachedCounters) Increment

func (c *CachedCounters) Increment(name string, value int)

Increments counter by given value. Parameters:

  • name string a counter name of Increment type.
  • value int a value to add to the counter.

func (*CachedCounters) IncrementOne

func (c *CachedCounters) IncrementOne(name string)

Increments counter by 1. Parameters:

  • name string a counter name of Increment type.

func (*CachedCounters) Last

func (c *CachedCounters) Last(name string, value float32)

Records the last calculated measurement value. Usually this method is used by metrics calculated externally. Parameters:

  • name string a counter name of Last type.
  • value number a last value to record.

func (*CachedCounters) Stats

func (c *CachedCounters) Stats(name string, value float32)

Calculates min/average/max statistics based on the current and previous values. Parameters:

  • name string a counter name of Statistics type
  • value float32 a value to update statistics

func (*CachedCounters) Timestamp

func (c *CachedCounters) Timestamp(name string, value time.Time)

Records the given timestamp. Parameters:

  • name string a counter name of Timestamp type. value time.Time a timestamp to record.

func (*CachedCounters) TimestampNow

func (c *CachedCounters) TimestampNow(name string)

Records the current time as a timestamp. Parameters:

  • name string a counter name of Timestamp type.

type CompositeCounters

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

Aggregates all counters from component references under a single component.

It allows to capture metrics and conveniently send them to multiple destinations.

References *:counters:*:*:1.0 (optional) ICounters components to pass collected measurements see ICounters

Example

type MyComponent {
    _counters CompositeCounters = new CompositeCounters();
}
    func (mc * MyConponent)setReferences(references: IReferences) {
        mc._counters.SetReferences(references);
    }

    func (mc * MyConponent) myMethod() {
        mc._counters.Increment("mycomponent.mymethod.calls");
        timing := mc._counters.BeginTiming("mycomponent.mymethod.exec_time");
		 defer timing.EndTiming();
		// do something

    	}

var mc MyComponent{}; mc._counters = NewCompositeCounters();

func NewCompositeCounters

func NewCompositeCounters() *CompositeCounters

Creates a new instance of the counters. Returns *CompositeCounters

func NewCompositeCountersFromReferences

func NewCompositeCountersFromReferences(references refer.IReferences) *CompositeCounters

Creates a new instance of the counters. Parameters:

  • references refer.IReferences references to locate the component dependencies.

Returns *CompositeCounters

func (*CompositeCounters) BeginTiming

func (c *CompositeCounters) BeginTiming(name string) *Timing

Begins measurement of execution time interval. It returns Timing object which has to be called at Timing.endTiming to end the measurement and update the counter. Parameters:

  • name string a counter name of Interval type.

Returns *Timing a Timing callback object to end timing.

func (*CompositeCounters) EndTiming

func (c *CompositeCounters) EndTiming(name string, elapsed float32)

Ends measurement of execution elapsed time and updates specified counter. see Timing.endTiming Parameters:

  • name string a counter name
  • elapsed float32 execution elapsed time in milliseconds to update the counter.

func (*CompositeCounters) Increment

func (c *CompositeCounters) Increment(name string, value int)

Increments counter by given value. Parameters:

  • name string a counter name of Increment type.
  • value number a value to add to the counter.

func (*CompositeCounters) IncrementOne

func (c *CompositeCounters) IncrementOne(name string)

Increments counter by 1. Parameters:

  • name string a counter name of Increment type.

func (*CompositeCounters) Last

func (c *CompositeCounters) Last(name string, value float32)

Records the last calculated measurement value. Usually this method is used by metrics calculated externally. Parameters:

  • name string a counter name of Last type.
  • value float32 a last value to record.

func (*CompositeCounters) SetReferences

func (c *CompositeCounters) SetReferences(references refer.IReferences)

Sets references to dependent components. Parameters:

  • references refer.IReferences references to locate the component dependencies.

func (*CompositeCounters) Stats

func (c *CompositeCounters) Stats(name string, value float32)

Calculates min/average/max statistics based on the current and previous values. Parameters:

  • name string a counter name of Statistics type
  • value float32 a value to update statistics

func (*CompositeCounters) Timestamp

func (c *CompositeCounters) Timestamp(name string, value time.Time)

Records the given timestamp. Parameters:

  • name string a counter name of Timestamp type.
  • value time.Time a timestamp to record.

func (*CompositeCounters) TimestampNow

func (c *CompositeCounters) TimestampNow(name string)

Records the current time as a timestamp. Parameters:

  • name string a counter name of Timestamp type.

type Counter

type Counter struct {
	Name    string    `json:"name"`
	Type    int       `json:"type"`
	Last    float32   `json:"last"`
	Count   int       `json:"count"`
	Min     float32   `json:"min"`
	Max     float32   `json:"max"`
	Average float32   `json:"average"`
	Time    time.Time `json:"time"`
}

Data object to store measurement for a performance counter. This object is used by CachedCounters to store counters.

func NewCounter

func NewCounter(name string, typ int) *Counter

Creates a instance of the data obejct Parameters:

  • name string a counter name.
  • type CounterType a counter type.

Returns *Counter

type ICounters

type ICounters interface {
	// Begins measurement of execution time interval. It returns Timing object which has to be called at Timing.endTiming to end the measurement and update the counter.
	BeginTiming(name string) *Timing

	// Calculates min/average/max statistics based on the current and previous values.
	Stats(name string, value float32)

	// Records the last calculated measurement value.
	// Usually this method is used by metrics calculated externally.
	Last(name string, value float32)

	// Records the given timestamp.
	TimestampNow(name string)

	// Records the current time as a timestamp.
	Timestamp(name string, value time.Time)

	// Increments counter by 1.
	IncrementOne(name string)

	// Increments counter by given value.
	Increment(name string, value int)
}

type ICountersSaver

type ICountersSaver interface {
	Save(counters []*Counter) error
}

type ITimingCallback

type ITimingCallback interface {
	EndTiming(name string, elapsed float32)
}

Ends measurement of execution elapsed time and updates specified counter. see Timing.endTiming Parameters:

  • name string a counter name
  • elapsed float32 execution elapsed time in milliseconds to update the counter.

type LogCounters

type LogCounters struct {
	CachedCounters
	// contains filtered or unexported fields
}

Performance counters that periodically dumps counters measurements to logger.

Configuration parameters options: interval: interval in milliseconds to save current counters measurements (default: 5 mins) reset_timeout: timeout in milliseconds to reset the counters. 0 disables the reset (default: 0) References *:logger:*:*:1.0 ILogger components to dump the captured counters *:context-info:*:*:1.0 (optional) ContextInfo to detect the context id and specify counters source see Counter

see CachedCounters

see CompositeLogger

Example counters := NewLogCounters(); counters.SetReferences(NewReferencesFromTuples(

NewDescriptor("pip-services", "logger", "console", "default", "1.0"), NewConsoleLogger()

));

counters.Increment("mycomponent.mymethod.calls"); timing := counters.BeginTiming("mycomponent.mymethod.exec_time"); defer timing.EndTiming();

// do something

counters.Dump();

func NewLogCounters

func NewLogCounters() *LogCounters

Creates a new instance of the counters. Returns *LogCounters

func (*LogCounters) Save

func (c *LogCounters) Save(counters []*Counter) error

Saves the current counters measurements. Parameters:

  • counters []*Counter current counters measurements to be saves.

func (*LogCounters) SetReferences

func (c *LogCounters) SetReferences(references refer.IReferences)

Sets references to dependent components. Parameters:

  • references refer.IReferences references to locate the component dependencies.

type NullCounters

type NullCounters struct{}

Dummy implementation of performance counters that doesn't do anything.

It can be used in testing or in situations when counters is required but shall be disabled.

func NewNullCounters

func NewNullCounters() *NullCounters

Creates a new instance of the counter. Returns *NullCounters

func (*NullCounters) BeginTiming

func (c *NullCounters) BeginTiming(name string) *Timing

Begins measurement of execution time interval. It returns Timing object which has to be called at Timing.endTiming to end the measurement and update the counter. Parameters:

  • name string a counter name of Interval type.

Returns *Timing a Timing callback object to end timing.

func (*NullCounters) Increment

func (c *NullCounters) Increment(name string, value float32)

Increments counter by given value. Parameters:

  • name string a counter name of Increment type.
  • value float32 a value to add to the counter.

func (*NullCounters) IncrementOne

func (c *NullCounters) IncrementOne(name string)

Increments counter by 1. Parameters:

  • name string a counter name of Increment type.

func (*NullCounters) Last

func (c *NullCounters) Last(name string, value float32)

Records the last calculated measurement value. Usually this method is used by metrics calculated externally. Parameters:

  • name string a counter name of Last type.
  • value float32 a last value to record.

func (*NullCounters) Stats

func (c *NullCounters) Stats(name string, value float32)

Calculates min/average/max statistics based on the current and previous values. Parameters:

  • name string a counter name of Statistics type
  • value float32 a value to update statistics

func (*NullCounters) Timestamp

func (c *NullCounters) Timestamp(name string, value time.Time)

Records the given timestamp. Parameters:

  • name string a counter name of Timestamp type.
  • value time.Time a timestamp to record.

func (*NullCounters) TimestampNow

func (c *NullCounters) TimestampNow(name string)

Records the current time as a timestamp. Parameters:

  • name string a counter name of Timestamp type.

type Timing

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

Callback object returned by ICounters.beginTiming to end timing of execution block and update the associated counter.

Example

timing := counters.BeginTiming("mymethod.exec_time");
 defer  timing.EndTiming();

func NewEmptyTiming

func NewEmptyTiming() *Timing

Creates a new instance of the timing callback object. Retruns *Timing

func NewTiming

func NewTiming(counter string, callback ITimingCallback) *Timing

Creates a new instance of the timing callback object. Parameters:

  • counter string an associated counter name
  • callback ITimingCallback a callback that shall be called when EndTiming is called.

Retruns *Timing

func (*Timing) EndTiming

func (c *Timing) EndTiming()

Ends timing of an execution block, calculates elapsed time and updates the associated counter.

Jump to

Keyboard shortcuts

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