-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.d.ts
150 lines (138 loc) · 5.15 KB
/
client.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { EventEmitter } from 'events';
import { Transform, TransformOptions } from 'readable-stream';
import { MetricOptions } from '@metrics/metric';
declare class MetricsClient extends Transform {
constructor(options?: MetricsClient.MetricsClientOptions);
counter(
options: MetricsClient.BaseMetricsOptions,
): MetricsClient.MetricsCounter;
gauge(
options: MetricsClient.BaseMetricsOptions,
): MetricsClient.MetricsGauge;
histogram(
options: MetricsClient.MetricsHistogramOptions,
): MetricsClient.MetricsHistogram;
summary(
options: MetricsClient.BaseMetricsOptions,
): MetricsClient.MetricsHistogram;
metric(options: MetricOptions): void;
timer(options: MetricOptions): (options?: Partial<MetricOptions>) => void;
}
declare namespace MetricsClient {
export interface BaseMetricsOptions {
/**
* Valid characters: `a-zA-Z0-9_`
*/
name: string;
description: string;
labels?: Record<string, string | number | boolean | null>;
}
export interface MetricsCounter extends EventEmitter {
/**
* Increment the counter
*
* @example <caption>Increment by 1</caption>
* counter.inc();
* @example <caption>Increment by 10</caption>
* counter.inc(10);
* @example <caption>Increment by 1 with labels</caption>
* counter.inc({ labels: { url: 'https://www.mysite.com' } });
* @example <caption>Increment by 10 with labels</caption>
* counter.inc(10, { labels: { url: 'https://www.mysite.com' } });
*/
inc(
value?: number | Pick<BaseMetricsOptions, 'labels'>,
options?: Pick<BaseMetricsOptions, 'labels'>,
): void;
}
export interface MetricsGauge extends EventEmitter {
set(value: number, options?: Pick<BaseMetricsOptions, 'labels'>): void;
}
export interface MetricsHistogramOptions extends BaseMetricsOptions {
buckets?: number[];
}
export type EndTimer = (
options?: Pick<BaseMetricsOptions, 'labels'>,
) => void;
export interface MetricsHistogram extends EventEmitter {
/**
* When called, will popupale the metrics stream with a histogram value.
*
* @param value
* @param options
*/
observe(
value: number,
options?: Pick<MetricsHistogramOptions, 'labels' | 'buckets'>,
): void;
/**
* Measure time between two points.
*
* @example <caption>Measure time between two points</caption>
* const end = histogram.timer();
* // some stuff happens
* end();
* @example <caption>Measure time between two points with labels</caption>
* const end = histogram.timer({ labels: { url: 'https://www.mysite.com' } });
* // some stuff happens
* end();
* @example <caption>Measure time between two points with labels in the end function</caption>
* const end = histogram.timer();
* // some stuff happens
* end({ labels: { url: 'https://www.mysite.com' } });
* @example <caption>Set custom buckets</caption>
* const end = histogram.timer({ buckets: [0.1, 0.5, 1, 2, 5] });
* // some stuff happens
* end();
*/
timer(
options?: Pick<MetricsHistogramOptions, 'labels' | 'buckets'>,
): EndTimer;
}
export interface MetricsSummaryOptions extends BaseMetricsOptions {
quantiles?: number[];
}
export interface MetricsSummary extends EventEmitter {
/**
* When called, will popupale the metrics stream with a histogram value.
*
* @param value
* @param options
*/
observe(
value: number,
options?: Pick<MetricsSummaryOptions, 'labels' | 'quantiles'>,
): void;
/**
* Measure time between two points.
*
* @example <caption>Measure time between two points</caption>
* const end = summary.timer();
* // some stuff happens
* end();
* @example <caption>Measure time between two points with labels</caption>
* const end = summary.timer({ labels: { url: 'https://www.mysite.com' } });
* // some stuff happens
* end();
* @example <caption>Measure time between two points with labels in the end function</caption>
* const end = summary.timer();
* // some stuff happens
* end({ labels: { url: 'https://www.mysite.com' } });
* @example <caption>Set custom buckets</caption>
* const end = summary.timer({ quantiles: [0.001, 0.01, 0.5, 0.9, 0.99] });
* // some stuff happens
* end();
*/
timer(
options?: Pick<MetricsSummaryOptions, 'labels' | 'quantiles'>,
): EndTimer;
}
export interface MetricsClientOptions extends TransformOptions {
/**
* An optional unique identifier of the MetricsClient instance.
* A random ID will be generated if not provided.
*/
id?: string;
}
}
export = MetricsClient;