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.
publicCompositeCounters()
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.
publicCounterTiming beginTiming(String name)
- name: String - a counter name of Interval type.
- returns: CounterTiming - a callback object to end timing.
endTiming
Ends measurement of execution elapsed time and updates specified counter.
publicvoid endTiming(String name, float elapsed)
- name: String - a counter name
- elapsed: float - execution elapsed time in milliseconds to update the counter.
increment
Increments counter by given value.
publicvoid increment(String name, int value)
- name: string - a counter name of Increment type.
- value: int - a value to add to the counter.
incrementOne
Increments counter by 1.
publicvoid incrementOne(String name)
- name: String - a counter name of Increment type.
last
Records the last calculated measurement value. Usually this method is used by metrics calculated externally.
publicvoid last(String name, float value)
- name: String - a counter name of Last type.
- value: float - last value to record.
setReferences
Sets references to dependent components.
publicvoid setReferences(IReferences references) throws ReferenceException
- references: IReferences - references to locate the component dependencies.
stats
Calculates min/average/max statistics based on the current and previous values.
publicvoid stats(String name, float value)
- name: String - a counter name of Statistics type
- value: float - a value to update statistics
timestamp
Records the given timestamp.
publicvoid timestamp(String name, ZonedDateTime value)
- name: String - a counter name of Timestamp type.
- value: ZonedDateTime - a timestamp to record.
timestampNow
Records the current time as a timestamp.
publicvoid timestampNow(String name)
- name: String - a counter name of Timestamp type.
Examples
{@code
class MyComponent implements IReferenceable {
CompositeCounters _counters = new CompositeCounters();
public void setReferences(IReferences references) {
this._counters.setReferences(references);
...
}
public void myMethod() {
this._counters.increment("mycomponent.mymethod.calls");
CounterTiming timing = this._counters.beginTiming("mycomponent.mymethod.exec_time");
try {
...
} finally {
timing.endTiming();
}
}
}
}