Implements: ICounters, IReconfigurable, ICounterTimingCallback
Description
The CachedCounters class allows you to create performace counters that measure and store those values in memory.
Important points
- Child classes can implement saving of the counters into various different 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)
Constructors
Creates a new CachedCounters object.
CachedCounters()
Fields
Instance methods
beginTiming
Begins measurement of execution time interval. It returns CounterTiming object which has to be called at [CounterTiming.endTiming to end the measurement and update the counter.
CounterTiming beginTiming(String name)
- name: String - counter name of Interval type.
- returns: CounterTiming - callback object to end counter_timing.
clear
Clears (resets) a counter specified by its name.
void clear(String name)
- name: String - name of counter to clear.
clearAll
Clears (resets) all counters.
void clearAll()
configure
Configures component by passing configuration parameters.
@override
void configure(ConfigParams config)
- config: ConfigParams - configuration parameters to be set.
dump
Dumps (saves) the current values of counters.
void dump()
endTiming
Ends measurement of execution elapsed time and updates a specified counter.
@override
void endTiming(String? name, int elapsed)
- name: String? - counter’s name
- elapsed: int - execution elapsed time in milliseconds to update the counter.
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.
Counter get(String? name, CounterType type)
- name: String - name of counter to retrieve.
- type: CounterType - counter type.
- returns: Counter - existing or newly created counter of the specified type.
getAll
Gets all captured counters.
List<Counter> getAll()
- returns: List<Counter> - list with counters.
getInterval
Gets the counters dump/save interval.
int getInterval()
- returns: int - interval in milliseconds.
increment
Increments a counter by given value.
@override
void increment(String name, int value)
- name: String - counter name of Increment type.
- value: int - value to add to the counter.
incrementOne
Increments counter by 1.
@override
void incrementOne(String name)
- name: String - counter name of Increment type.
last
Records the last calculated measurement value. Usually this method is used by metrics calculated externally.
@override
void last(String name, int value)
- name: String - counter name of Last type.
- value: int - last value to record.
save
Saves the current counters measurements.
void save(List<Counter> counters)
- counters: List<Counter> - current counters measurements to be saved.
setInterval
Sets the counters dump/save interval.
@override
void setInterval(int value)
- value: int - new interval in milliseconds.
stats
Calculates min/average/max statistics based on the current and previous values.
@override
void stats(String name, int value)
- name: String - counter name of Statistics type
- value: int - value to update statistics
timestamp
Records the given timestamp.
@override
void timestamp(String name, DateTime value)
- name: String - counter name of Timestamp type.
- value: DateTime - timestamp to record.
timestampNow
Records the current time as a timestamp.
@override
void timestampNow(String name)
- name: String - counter name of Timestamp type.
update
Makes counter measurements as updated and dumps them when timeout expires.
void _update()