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.

_save(counters: List[Counter])

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

set_references

Sets references to dependent components.

set_references(references: IReferences)

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

Examples

counters = LogCounters()
counters.set_references(References.from_tuples(
            Descriptor("pip-services", "logger", "console", "default", "1.0"), ConsoleLogger()))

counters.increment("mycomponent.mymethod.calls")
timing = counters.begin_timing("mycomponent.mymethod.exec_time")
# do something
timing.end_timing()

See also