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 void save(List<Counter[]> counters)

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

setReferences

Sets references to dependent components.

public void setReferences(IReferences references) throws ReferenceException

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

Examples

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

See also