Inherits: 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(IReferences references = null)
- references: IReferences - references to locate the component dependencies.
Fields
Instance methods
BeginTiming
Begins measurement of execution time interval. It returns a CounterTiming object which has to be called at CounterTiming.EndTiming to end the measurement and update the counter.
publicCounterTiming BeginTiming(string name)
- name: string - counter name of Interval type.
- returns: CounterTiming - callback object to end timing.
EndTiming
Ends measurement of execution elapsed time and updates the specified counter.
publicvoid EndTiming(string name, double elapsed)
- name: string - counter’s name
- elapsed: double - execution elapsed time in milliseconds to update the counter.
increment
Increments a counter by given value.
publicint Increment(string name, int value)
- name: string - counter’s name of Increment type.
- value: int - value to add to the counter.
IncrementOne
Increments counter by 1.
publicvoid IncrementOne(string name)
- name: string - counter’s 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 - counter’s name of Last type.
- value: float - last value to record.
SetReferences
Sets references to dependent components.
public virtualvoid 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.
publicvoid Stats(string name, float value)
- name: string - counter’s name of Statistics type
- value: float - value to update statistics
timestamp
Records the given timestamp.
publicvoid Timestamp(string name, DateTime value)
- name: string - counter’s name of Timestamp type.
- value: DateTime - timestamp to record.
TimestampNow
Records the current time as a timestamp.
publicTimestampNow(string name)
- name: string - counter’s name of Timestamp type.
Examples
class MyComponent: IReferenceable 
{
    CompositeCounters _counters = new CompositeCounters();
    public void SetReferences(IReferences references)
    {
        this._counters.SetReferences(references);
        ...
    }
    public void MyMethod()
    {
        this._counters.Increment("mycomponent.mymethod.calls");
        var timing = this._counters.BeginTiming("mycomponent.mymethod.exec_time");
        try
        {
            ...
        }
        finally
        {
            timing.EndTiming();
        }
    }
}