pip_services3_components.count.CachedCounters module
pip_services3_components.counters.CachedCounters
Cached 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.CachedCounters.
CachedCounters
Bases:
pip_services3_components.count.ICounters.ICounters
,pip_services3_commons.config.IReconfigurable.IReconfigurable
,pip_services3_components.count.ICounterTimingCallback.ICounterTimingCallback
Abstract implementation of performance counters that measures and stores counters in memory. Child classes implement saving of the counters into various destinations.
- ### 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)
-
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.
-
clear
(name: str) Clears (resets) a counter specified by its name.
- Parameters
name – a counter name to clear.
-
clear_all
() Clears (resets) all counters.
-
configure
(config: pip_services3_commons.config.ConfigParams.ConfigParams) Configures component by passing configuration parameters.
- Parameters
config – configuration parameters to be set.
-
dump
() Dumps (saves) the current values of counters.
-
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.
-
get
(name: str, typ: pip_services3_components.count.CounterType.CounterType) → pip_services3_components.count.Counter.Counter Gets a counter specified by its name. It counter does not exist or its type doesn’t match the specified type it creates a new one.
- Parameters
name – a counter name to retrieve.
typ – a counter type.
- Returns
an existing or newly created counter of the specified type.
-
get_all
() → List[pip_services3_components.count.Counter.Counter] Gets all captured counters.
- Returns
a list with counters.
-
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_interval
(value: float) Sets the counters dump/save interval.
- Parameters
value – a new interval in milliseconds.
-
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.