pip_services3_components.count.CompositeCounters module
pip_services3_components.log.CompositeCounters
Composite counters implementation
- copyright
Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.
- license
MIT, see LICENSE for more details.
-
class
pip_services3_components.count.CompositeCounters.
CompositeCounters
(references: pip_services3_commons.refer.IReferences.IReferences = None) Bases:
pip_services3_components.count.ICounters.ICounters
,pip_services3_components.count.ICounterTimingCallback.ICounterTimingCallback
,pip_services3_commons.refer.IReferenceable.IReferenceable
Aggregates all counters from component references under a single component.
It allows to capture metrics and conveniently send them to multiple destinations.
- ### References ###
*:counters:*:*:1.0 (optional) ICounters components to pass collected measurements
Example:
class MyComponent(IReferenceable): _counters = CompositeCounters() def set_references(self, references): self._counters.set_references(references) def my_method(self): self._counters.increment("mycomponent.mymethod.calls") timing = this._counters.begin_timing("mycomponent.mymethod.exec_time") # do something timing.end_timing()
-
begin_timing
(name: str) → pip_services3_components.count.CounterTiming.CounterTiming Begins measurement of execution time interval. It returns
CounterTiming
object which has to be called atCounterTiming.end_timing()
to end the measurement and update the counter.- Parameters
name – a counter name of Interval type.
- Returns
a
CounterTiming
callback object to end timing.
-
end_timing
(name: str, elapsed: float) Ends measurement of execution elapsed time and updates specified counter.
- Parameters
name – a counter name
elapsed – execution elapsed time in milliseconds to update the counter.
See
CounterTiming.end_timing()
-
increment
(name: str, value: float) Increments counter by given value.
- Parameters
name – a counter name of Increment type.
value – a value to add to the counter.
-
increment_one
(name: str) Increments counter by 1.
- Parameters
name – a counter name of Increment type.
-
last
(name: str, value: float) Records the last calculated measurement value. Usually this method is used by metrics calculated externally.
- Parameters
name – a counter name of Last type.
value – a last value to record.
-
set_references
(references: pip_services3_commons.refer.IReferences.IReferences) Sets references to dependent components.
- Parameters
references – references to locate the component dependencies.
-
stats
(name: str, value: float) Calculates min/average/max statistics based on the current and previous values.
- Parameters
name – a counter name of Statistics type
value – a value to update statistics
-
timestamp
(name: str, value: datetime.datetime) Records the given timestamp.
- Parameters
name – a counter name of Timestamp type.
value – a timestamp to record.