LogCounters

Performance counters that periodically dump counters' measurements to logger.

Inherits: 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 override void Save(IEnumerable<Counter> counters)

  • counters: IEnumerable<Counter> - current counters' measurements to be saved.

SetReferences

Sets references to dependent components.

public virtual void SetReferences(IReferences references)

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

Examples

var counters = new LogCounters();
counters.SetReferences(References.FromTuples(
    new Descriptor("pip-services3", "logger", "console", "default", "1.0"), new ConsoleLogger()
));

counters.Increment("mycomponent.mymethod.calls");
var timing = counters.BeginTiming("mycomponent.mymethod.exec_time");

try {
    ...
    }
finally {
    timing.EndTiming();
}

counters.Dump();

See also