Class CompositeCounters
java.lang.Object
org.pipservices3.components.count.CompositeCounters
- All Implemented Interfaces:
org.pipservices3.commons.refer.IReferenceable,ICounters,ITimingCallback
public class CompositeCounters extends Object implements ICounters, ITimingCallback, org.pipservices3.commons.refer.IReferenceable
Aggregates all counters from component references under a single component.
It allows to capture metrics and conveniently send them to multiple destinations.
### References ###
- *:counters:*:*:1.0 (optional)
ICounterscomponents to pass collected measurements
### Example ###
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");
Timing timing = this._counters.beginTiming("mycomponent.mymethod.exec_time");
try {
...
} finally {
timing.endTiming();
}
}
}
- See Also:
ICounters
-
Constructor Summary
Constructors Constructor Description CompositeCounters()Creates a new instance of the counters. -
Method Summary
Modifier and Type Method Description TimingbeginTiming(String name)Begins measurement of execution time interval.voidendTiming(String name, float elapsed)Ends measurement of execution elapsed time and updates specified counter.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.voidsetReferences(org.pipservices3.commons.refer.IReferences references)Sets references to dependent components.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.
-
Constructor Details
-
CompositeCounters
public CompositeCounters()Creates a new instance of the counters.
-
-
Method Details
-
setReferences
public void setReferences(org.pipservices3.commons.refer.IReferences references) throws org.pipservices3.commons.refer.ReferenceExceptionSets references to dependent components.- Specified by:
setReferencesin interfaceorg.pipservices3.commons.refer.IReferenceable- Parameters:
references- references to locate the component dependencies.- Throws:
org.pipservices3.commons.refer.ReferenceException- when no references found.
-
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.
-