Class CachedCounters
java.lang.Object
org.pipservices3.components.count.CachedCounters
- All Implemented Interfaces:
org.pipservices3.commons.config.IConfigurable,org.pipservices3.commons.config.IReconfigurable,ICounters,ITimingCallback
- Direct Known Subclasses:
LogCounters
public abstract class CachedCounters extends Object implements ICounters, org.pipservices3.commons.config.IReconfigurable, ITimingCallback
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)
-
Field Summary
Fields Modifier and Type Field Description protected long_lastResetTimeprotected long_resetTimeout -
Constructor Summary
Constructors Modifier Constructor Description protectedCachedCounters()Creates a new CachedCounters object. -
Method Summary
Modifier and Type Method Description TimingbeginTiming(String name)Begins measurement of execution time interval.voidclear(String name)Clears (resets) a counter specified by its name.voidclearAll()Clears (resets) all counters.voidconfigure(org.pipservices3.commons.config.ConfigParams config)Configures component by passing configuration parameters.voiddump()Dumps (saves) the current values of counters.voidendTiming(String name, float elapsed)Ends measurement of execution elapsed time and updates specified counter.Counterget(String name, int type)Gets a counter specified by its name.List<Counter>getAll()Gets all captured counters.voidincrement(String name, int value)Increments counter by given value.voidincrementOne(String name)Increments counter by 1.voidlast(String name, float value)Records the last calculated measurement value.protected abstract voidsave(List<Counter> counters)Saves the current counters measurements.voidstats(String name, float value)Calculates min/average/max statistics based on the current and previous values.voidtimestamp(String name, ZonedDateTime value)Records the given timestamp.voidtimestampNow(String name)Records the current time as a timestamp.protected voidupdate()Makes counter measurements as updated and dumps them when timeout expires.
-
Field Details
-
_lastResetTime
protected long _lastResetTime -
_resetTimeout
protected long _resetTimeout
-
-
Constructor Details
-
CachedCounters
protected CachedCounters()Creates a new CachedCounters object.
-
-
Method Details
-
save
protected abstract void save(List<Counter> counters) throws org.pipservices3.commons.errors.InvocationExceptionSaves the current counters measurements.- Parameters:
counters- current counters measurements to be saves.- Throws:
org.pipservices3.commons.errors.InvocationException- when error occured.
-
configure
public void configure(org.pipservices3.commons.config.ConfigParams config)Configures component by passing configuration parameters.- Specified by:
configurein interfaceorg.pipservices3.commons.config.IConfigurable- Parameters:
config- configuration parameters to be set.
-
clear
Clears (resets) a counter specified by its name.- Parameters:
name- a counter name to clear.
-
clearAll
public void clearAll()Clears (resets) all counters. -
dump
public void dump() throws org.pipservices3.commons.errors.InvocationExceptionDumps (saves) the current values of counters.- Throws:
org.pipservices3.commons.errors.InvocationException- when error occured.- See Also:
save(List)
-
update
protected void update()Makes counter measurements as updated and dumps them when timeout expires.- See Also:
dump()
-
getAll
Gets all captured counters.- Returns:
- a list with counters.
-
get
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.type- a counter type.- Returns:
- an existing or newly created counter of the specified type.
-
beginTiming
Begins measurement of execution time interval. It returns Timing object which has to be called atTiming.endTiming()to end the measurement and update the counter.- Specified by:
beginTimingin interfaceICounters- Parameters:
name- a counter name of Interval type.- Returns:
- a Timing callback object to end timing.
-
endTiming
Ends measurement of execution elapsed time and updates specified counter.- Specified by:
endTimingin interfaceITimingCallback- Parameters:
name- a counter nameelapsed- execution elapsed time in milliseconds to update the counter.- See Also:
Timing.endTiming()
-
stats
Calculates min/average/max statistics based on the current and previous values. -
last
Records the last calculated measurement value. Usually this method is used by metrics calculated externally. -
timestampNow
Records the current time as a timestamp.- Specified by:
timestampNowin interfaceICounters- Parameters:
name- a counter name of Timestamp type.
-
timestamp
Records the given timestamp. -
incrementOne
Increments counter by 1.- Specified by:
incrementOnein interfaceICounters- Parameters:
name- a counter name of Increment type.
-
increment
Increments counter by given value.
-