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
_lastResetTime
protected long
_resetTimeout
-
Constructor Summary
Constructors Modifier Constructor Description protected
CachedCounters()
Creates a new CachedCounters object. -
Method Summary
Modifier and Type Method Description Timing
beginTiming(String name)
Begins measurement of execution time interval.void
clear(String name)
Clears (resets) a counter specified by its name.void
clearAll()
Clears (resets) all counters.void
configure(org.pipservices3.commons.config.ConfigParams config)
Configures component by passing configuration parameters.void
dump()
Dumps (saves) the current values of counters.void
endTiming(String name, float elapsed)
Ends measurement of execution elapsed time and updates specified counter.Counter
get(String name, int type)
Gets a counter specified by its name.List<Counter>
getAll()
Gets all captured counters.void
increment(String name, int value)
Increments counter by given value.void
incrementOne(String name)
Increments counter by 1.void
last(String name, float value)
Records the last calculated measurement value.protected abstract void
save(List<Counter> counters)
Saves the current counters measurements.void
stats(String name, float value)
Calculates min/average/max statistics based on the current and previous values.void
timestamp(String name, ZonedDateTime value)
Records the given timestamp.void
timestampNow(String name)
Records the current time as a timestamp.protected void
update()
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:
configure
in 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:
beginTiming
in 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:
endTiming
in 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:
timestampNow
in interfaceICounters
- Parameters:
name
- a counter name of Timestamp type.
-
timestamp
Records the given timestamp. -
incrementOne
Increments counter by 1.- Specified by:
incrementOne
in interfaceICounters
- Parameters:
name
- a counter name of Increment type.
-
increment
Increments counter by given value.
-