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

Instance methods

save

Saves the current counters measurements.

protected save(counters: Counter[]): void

  • counters: Counter[] - current counters measurements to be saved.

setReferences

Sets references to dependent components.

public setReferences(references: IReferences): void

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

Examples

let counters = new LogCounters();
counters.setReferences(References.fromTuples(
    new Descriptor("pip-services", "logger", "console", "default", "1.0"), new ConsoleLogger()
));
 
counters.increment("mycomponent.mymethod.calls");
let timing = counters.beginTiming("mycomponent.mymethod.exec_time");
try {
    ...
} finally {
    timing.endTiming();
}

counters.dump();

See also