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