Implements: ICounters, IReconfigurable, ICounterTimingCallback
Description
The CompositeCounters allows you to aggregate all counters from different component references into a single one.
Important points
- It allows to capture metrics and conveniently send them to multiple destinations.
References
- *:counters:*:*:1.0 - (optional) ICounters components to pass collected measurements
Constructors
Creates a new instance of the counters.
CompositeCounters([IReferences? references])
- references: IReferences? - references to locate the component dependencies.
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.
@override
CounterTiming beginTiming(String name)
- name: String - counter name of Interval type.
- returns: CounterTiming - callback object to end counter_timing.
endTiming
Ends measurement of execution elapsed time and updates specified counter.
@override
void endTiming(String? name, int elapsed)
- name: String? - counter name
- elapsed: int - execution elapsed time in milliseconds to update the counter.
increment
Increments 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 externally calculated metrics.
@override
void last(String name, int value)
- name: String - counter name of Last type.
- value: int - last value to record.
setReferences
Sets references to dependent components.
@override
void setReferences(IReferences references)
- references: IReferences - references to locate the component’s dependencies.
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.
Examples
class MyComponent implements IReferenceable {
var _counters = new CompositeCounters();
void setReferences(IReferences references) {
_counters.setReferences(references);
...
}
void myMethod() {
_counters.increment('mycomponent.mymethod.calls');
var counter_timing =_counters.beginTiming('mycomponent.mymethod.exec_time');
try {
...
} finally {
counter_timing.endTiming();
}
}
}