1 | import { IMetricContext } from "./contexts";
|
2 | /**
|
3 | * A simple interface for listening for Metric updates. Should be plugged into
|
4 | * something like Prometheus for recording.
|
5 | *
|
6 | * Metric names are defined in metric_names.ts - see documentation on the name
|
7 | * for what the context object contains. All metrics have a context object,
|
8 | * with applicable interface. See the IMetricContext interface for more
|
9 | * information.
|
10 | * @category Metrics
|
11 | */
|
12 | export interface IMetricListener {
|
13 | /**
|
14 | * Called when the given metric should start being tracked. Will be
|
15 | * paired with a matching onEndMetric() call.
|
16 | * @param {string} metricName The metric being called.
|
17 | * @param {IMetricContext} context Context for the metric. Never null.
|
18 | */
|
19 | onStartMetric(metricName: string, context: IMetricContext): void;
|
20 | /**
|
21 | * Called when the given metric should stop being tracked. Will have
|
22 | * started with a matching onStartMetric() call.
|
23 | * @param {string} metricName The metric being called.
|
24 | * @param {any} context Context for the metric. Never null.
|
25 | * @param {number} timeMs The measured time in milliseconds between
|
26 | * the start and end.
|
27 | */
|
28 | onEndMetric(metricName: string, context: IMetricContext, timeMs: number): void;
|
29 | /**
|
30 | * Called when a linear metric (increasing/decreasing number) should
|
31 | * be incremented.
|
32 | * @param {string} metricName The metric being called.
|
33 | * @param {IMetricContext} context Context for the metric. Never null.
|
34 | * @param {number} amount The amount to add. Never negative or zero.
|
35 | */
|
36 | onIncrement(metricName: string, context: IMetricContext, amount: number): any;
|
37 | /**
|
38 | * Called when a linear metric (increasing/decreasing number) should
|
39 | * be decremented.
|
40 | * @param {string} metricName The metric being called.
|
41 | * @param {IMetricContext} context Context for the metric. Never null.
|
42 | * @param {number} amount The amount to subtract. Never negative or zero.
|
43 | */
|
44 | onDecrement(metricName: string, context: IMetricContext, amount: number): any;
|
45 | /**
|
46 | * Called when a linear metric (increasing/decreasing number) should
|
47 | * be reset to zero.
|
48 | * @param {string} metricName The metric being called.
|
49 | * @param {IMetricContext} context Context for the metric. Never null.
|
50 | */
|
51 | onReset(metricName: string, context: IMetricContext): any;
|
52 | }
|