UNPKG

3.86 kBTypeScriptView Raw
1/** @module count */
2import { IReferenceable } from 'pip-services3-commons-node';
3import { IReferences } from 'pip-services3-commons-node';
4import { ICounters } from './ICounters';
5import { CounterTiming } from './CounterTiming';
6import { ICounterTimingCallback } from './ICounterTimingCallback';
7/**
8 * Aggregates all counters from component references under a single component.
9 *
10 * It allows to capture metrics and conveniently send them to multiple destinations.
11 *
12 * ### References ###
13 *
14 * - <code>\*:counters:\*:\*:1.0</code> (optional) [[ICounters]] components to pass collected measurements
15 *
16 * @see [[ICounters]]
17 *
18 * ### Example ###
19 *
20 * class MyComponent implements IReferenceable {
21 * private _counters: CompositeCounters = new CompositeCounters();
22 *
23 * public setReferences(references: IReferences): void {
24 * this._counters.setReferences(references);
25 * ...
26 * }
27 *
28 * public myMethod(): void {
29 * this._counters.increment("mycomponent.mymethod.calls");
30 * var timing = this._counters.beginTiming("mycomponent.mymethod.exec_time");
31 * try {
32 * ...
33 * } finally {
34 * timing.endTiming();
35 * }
36 * }
37 * }
38 *
39 */
40export declare class CompositeCounters implements ICounters, ICounterTimingCallback, IReferenceable {
41 protected readonly _counters: ICounters[];
42 /**
43 * Creates a new instance of the counters.
44 *
45 * @param references references to locate the component dependencies.
46 */
47 constructor(references?: IReferences);
48 /**
49 * Sets references to dependent components.
50 *
51 * @param references references to locate the component dependencies.
52 */
53 setReferences(references: IReferences): void;
54 /**
55 * Begins measurement of execution time interval.
56 * It returns [[CounterTiming]] object which has to be called at
57 * [[CounterTiming.endTiming]] to end the measurement and update the counter.
58 *
59 * @param name a counter name of Interval type.
60 * @returns a [[CounterTiming]] callback object to end timing.
61 */
62 beginTiming(name: string): CounterTiming;
63 /**
64 * Ends measurement of execution elapsed time and updates specified counter.
65 *
66 * @param name a counter name
67 * @param elapsed execution elapsed time in milliseconds to update the counter.
68 *
69 * @see [[CounterTiming.endTiming]]
70 */
71 endTiming(name: string, elapsed: number): void;
72 /**
73 * Calculates min/average/max statistics based on the current and previous values.
74 *
75 * @param name a counter name of Statistics type
76 * @param value a value to update statistics
77 */
78 stats(name: string, value: number): void;
79 /**
80 * Records the last calculated measurement value.
81 *
82 * Usually this method is used by metrics calculated
83 * externally.
84 *
85 * @param name a counter name of Last type.
86 * @param value a last value to record.
87 */
88 last(name: string, value: number): void;
89 /**
90 * Records the current time as a timestamp.
91 *
92 * @param name a counter name of Timestamp type.
93 */
94 timestampNow(name: string): void;
95 /**
96 * Records the given timestamp.
97 *
98 * @param name a counter name of Timestamp type.
99 * @param value a timestamp to record.
100 */
101 timestamp(name: string, value: Date): void;
102 /**
103 * Increments counter by 1.
104 *
105 * @param name a counter name of Increment type.
106 */
107 incrementOne(name: string): void;
108 /**
109 * Increments counter by given value.
110 *
111 * @param name a counter name of Increment type.
112 * @param value a value to add to the counter.
113 */
114 increment(name: string, value: number): void;
115}