LogCounters

Performance counters that periodically dump counters' measurements to logger.

Implements: CachedCounters, IReferenceable

Description

The LogCounters allows you to create performance counters that periodically dump 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

Constructors

Creates a new instance of the counters.

LogCounters()

Instance methods

save

Saves the current counters measurements.

@override

void save(List<Counter>? counters)

  • counters: List<Counter>? - current counters measurements to be saved.

setReferences

Sets references to dependent components.

@override

void setReferences(IReferences references)

  • references: IReferences - references to locate the component dependencies.

Examples

var counters = LogCounters();
counters.setReferences(References.fromTuples([
    Descriptor("pip-services", "logger", "console", "default", "1.0"), ConsoleLogger()
]));

counters.increment("mycomponent.mymethod.calls");
var counter_timing = counters.beginTiming("mycomponent.mymethod.exec_time");

try {
    ...
} finally {
    counter_timing.endTiming();
}

counters.dump();

See also