@adalo/metrics 0.1.114 → 0.1.116
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/baseMetricsClient.d.ts +171 -0
- package/lib/baseMetricsClient.d.ts.map +1 -0
- package/lib/baseMetricsClient.js +353 -0
- package/lib/baseMetricsClient.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -1
- package/lib/metricsClient.d.ts +11 -169
- package/lib/metricsClient.d.ts.map +1 -1
- package/lib/metricsClient.js +80 -350
- package/lib/metricsClient.js.map +1 -1
- package/lib/metricsDatabaseClient.d.ts +10 -12
- package/lib/metricsDatabaseClient.d.ts.map +1 -1
- package/lib/metricsDatabaseClient.js +11 -13
- package/lib/metricsDatabaseClient.js.map +1 -1
- package/lib/metricsQueueRedisClient.d.ts +1 -1
- package/lib/metricsQueueRedisClient.d.ts.map +1 -1
- package/lib/metricsQueueRedisClient.js +11 -12
- package/lib/metricsQueueRedisClient.js.map +1 -1
- package/lib/metricsRedisClient.d.ts +14 -16
- package/lib/metricsRedisClient.d.ts.map +1 -1
- package/lib/metricsRedisClient.js +15 -17
- package/lib/metricsRedisClient.js.map +1 -1
- package/package.json +1 -1
- package/src/baseMetricsClient.js +410 -0
- package/src/index.ts +1 -0
- package/src/metricsClient.js +79 -412
- package/src/metricsDatabaseClient.js +10 -12
- package/src/metricsQueueRedisClient.js +11 -12
- package/src/metricsRedisClient.js +14 -16
package/lib/metricsClient.d.ts
CHANGED
|
@@ -1,98 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MetricsClient handles Prometheus metrics collection and push.
|
|
3
3
|
* Supports gauges, counters, default metrics, and custom metrics.
|
|
4
|
+
* Extends BaseMetricsClient for common functionality.
|
|
4
5
|
*/
|
|
5
|
-
export class MetricsClient {
|
|
6
|
-
/**
|
|
7
|
-
* @param {Object} config
|
|
8
|
-
* @param {string} [config.appName] Name of the application
|
|
9
|
-
* @param {string} [config.dynoId] Dyno/instance ID
|
|
10
|
-
* @param {string} [config.processType] Process type (web, worker, etc.)
|
|
11
|
-
* @param {boolean} [config.enabled] Enable metrics collection
|
|
12
|
-
* @param {boolean} [config.logValues] Log metrics values to console
|
|
13
|
-
* @param {string} [config.pushgatewayUrl] PushGateway URL
|
|
14
|
-
* @param {string} [config.pushgatewaySecret] PushGateway secret token
|
|
15
|
-
* @param {number} [config.intervalSec] Interval in seconds for pushing metrics
|
|
16
|
-
* @param {boolean} [config.removeOldMetrics] Enable to clear metrics by service name
|
|
17
|
-
* @param {boolean} [config.scripDefaultMetrics] Enable to scip default metrics creation
|
|
18
|
-
* @param {function} [config.startupValidation] Add to validate on start push.
|
|
19
|
-
*/
|
|
20
|
-
constructor(config?: {
|
|
21
|
-
appName?: string | undefined;
|
|
22
|
-
dynoId?: string | undefined;
|
|
23
|
-
processType?: string | undefined;
|
|
24
|
-
enabled?: boolean | undefined;
|
|
25
|
-
logValues?: boolean | undefined;
|
|
26
|
-
pushgatewayUrl?: string | undefined;
|
|
27
|
-
pushgatewaySecret?: string | undefined;
|
|
28
|
-
intervalSec?: number | undefined;
|
|
29
|
-
removeOldMetrics?: boolean | undefined;
|
|
30
|
-
scripDefaultMetrics?: boolean | undefined;
|
|
31
|
-
startupValidation?: Function | undefined;
|
|
32
|
-
});
|
|
33
|
-
appName: string;
|
|
34
|
-
dynoId: string;
|
|
35
|
-
processType: string;
|
|
36
|
-
enabled: boolean;
|
|
37
|
-
logValues: boolean;
|
|
38
|
-
pushgatewayUrl: string;
|
|
39
|
-
authToken: string;
|
|
40
|
-
intervalSec: number;
|
|
41
|
-
startupValidation: Function | undefined;
|
|
42
|
-
prefixLogs: string;
|
|
43
|
-
_registry: client.Registry<"text/plain; version=0.0.4; charset=utf-8">;
|
|
44
|
-
defaultLabels: {
|
|
45
|
-
app: string;
|
|
46
|
-
dyno_id: string;
|
|
47
|
-
process_type: string;
|
|
48
|
-
};
|
|
49
|
-
gateway: client.Pushgateway<"text/plain; version=0.0.4; charset=utf-8">;
|
|
50
|
-
gauges: {};
|
|
51
|
-
counters: {};
|
|
52
|
-
countersFunctions: {};
|
|
53
|
-
/** @type {Object<string, function(): number | Promise<number>>} */
|
|
54
|
-
gaugeUpdaters: {
|
|
55
|
-
[x: string]: () => number | Promise<number>;
|
|
56
|
-
};
|
|
6
|
+
export class MetricsClient extends BaseMetricsClient {
|
|
57
7
|
_lastUsageMicros: number;
|
|
58
8
|
_lastCheckTime: number;
|
|
9
|
+
_httpRequestBuffer: any[];
|
|
59
10
|
/**
|
|
60
11
|
* Register all built-in default Gauges and Counters.
|
|
61
12
|
* @private
|
|
62
13
|
*/
|
|
63
14
|
private _initDefaultMetrics;
|
|
64
|
-
/**
|
|
65
|
-
* Create a gauge metric.
|
|
66
|
-
* @param {Object} options - Gauge configuration
|
|
67
|
-
* @param {string} options.name - Name of the gauge
|
|
68
|
-
* @param {string} options.help - Help text describing the gauge
|
|
69
|
-
* @param {function(): number|Promise<number>} [options.updateFn] - Optional function returning the gauge value
|
|
70
|
-
* @param {string[]} [options.labelNames] - Optional custom label names
|
|
71
|
-
* @returns {import('prom-client').Gauge} The created Prometheus gauge
|
|
72
|
-
*/
|
|
73
|
-
createGauge: ({ name, help, updateFn, labelNames, }: {
|
|
74
|
-
name: string;
|
|
75
|
-
help: string;
|
|
76
|
-
updateFn?: (() => number | Promise<number>) | undefined;
|
|
77
|
-
labelNames?: string[] | undefined;
|
|
78
|
-
}) => import('prom-client').Gauge;
|
|
79
|
-
/**
|
|
80
|
-
* Create a Prometheus Counter metric.
|
|
81
|
-
*
|
|
82
|
-
* @param {Object} params - Counter configuration
|
|
83
|
-
* @param {string} params.name - Metric name
|
|
84
|
-
* @param {string} params.help - Metric description
|
|
85
|
-
* @param {string[]} [params.labelNames] - Optional list of label names. Defaults to this.defaultLabels keys.
|
|
86
|
-
*
|
|
87
|
-
* @returns {(labels?: Object, incrementValue?: number) => void}
|
|
88
|
-
* A function to increment the counter.
|
|
89
|
-
* Usage: (labels?, incrementValue?)
|
|
90
|
-
*/
|
|
91
|
-
createCounter({ name, help, labelNames }: {
|
|
92
|
-
name: string;
|
|
93
|
-
help: string;
|
|
94
|
-
labelNames?: string[] | undefined;
|
|
95
|
-
}): (labels?: Object, incrementValue?: number) => void;
|
|
96
15
|
/**
|
|
97
16
|
* Get CPU usage percent (cgroup-aware)
|
|
98
17
|
* @returns {number}
|
|
@@ -119,9 +38,9 @@ export class MetricsClient {
|
|
|
119
38
|
*/
|
|
120
39
|
measureLag(): Promise<number>;
|
|
121
40
|
/**
|
|
122
|
-
*
|
|
41
|
+
* Track an HTTP request (adds to buffer for interval collection).
|
|
123
42
|
*
|
|
124
|
-
* @param {Object} params - The parameters for the request
|
|
43
|
+
* @param {Object} params - The parameters for the request.
|
|
125
44
|
* @param {string} params.method - HTTP method (GET, POST, etc.).
|
|
126
45
|
* @param {string} params.route - The full requested URL or route.
|
|
127
46
|
* @param {number} params.status_code - HTTP response status code.
|
|
@@ -138,92 +57,15 @@ export class MetricsClient {
|
|
|
138
57
|
duration: number;
|
|
139
58
|
}): void;
|
|
140
59
|
/**
|
|
141
|
-
*
|
|
142
|
-
* Track the `app_requests_total` and `app_requests_total_duration` metric.
|
|
143
|
-
*/
|
|
144
|
-
trackHttpRequestMiddleware: (req: any, res: any, next: any) => void;
|
|
145
|
-
/**
|
|
146
|
-
* Clear all collected counters
|
|
147
|
-
*/
|
|
148
|
-
clearAllCounters: () => void;
|
|
149
|
-
/**
|
|
150
|
-
* Push all gauges and counters to PushGateway and optionally log.
|
|
151
|
-
*/
|
|
152
|
-
pushMetrics: () => Promise<void>;
|
|
153
|
-
_startPush: (interval?: number, customPushMetics?: undefined) => void;
|
|
154
|
-
/**
|
|
155
|
-
* Start periodic metrics collection and push.
|
|
156
|
-
*
|
|
157
|
-
* This method wraps the internal `_startPush` method.
|
|
158
|
-
* If a `customPushMetrics` function is provided, it will be executed
|
|
159
|
-
* at the given interval instead of the default `pushMetrics` behavior.
|
|
160
|
-
*
|
|
161
|
-
* @param {number} [interval=this.intervalSec] - Interval in seconds between pushes.
|
|
162
|
-
* @param {() => void | Promise<void>} [customPushMetrics] - Optional custom push function. If provided, Prometheus push is skipped.
|
|
163
|
-
*/
|
|
164
|
-
startPush: (interval?: number | undefined, customPushMetics?: undefined) => void;
|
|
165
|
-
/**
|
|
166
|
-
* Cleanup metrics and exit process.
|
|
167
|
-
* @returns {Promise<void>}
|
|
168
|
-
*/
|
|
169
|
-
cleanup: () => Promise<void>;
|
|
170
|
-
/**
|
|
171
|
-
* Remove old/stale dyno/instance metrics from PushGateway.
|
|
172
|
-
*
|
|
173
|
-
* Compares existing PushGateway metrics for this job and deletes any instances
|
|
174
|
-
* that do not match the current dynoId.
|
|
175
|
-
*
|
|
176
|
-
* @param {boolean} removeOldMetrics If true, performs cleanup; otherwise does nothing
|
|
177
|
-
* @returns {Promise<void>}
|
|
60
|
+
* Collect HTTP metrics from buffer, group by labels, and set gauges.
|
|
178
61
|
* @private
|
|
179
62
|
*/
|
|
180
|
-
private
|
|
181
|
-
/**
|
|
182
|
-
* Delete metrics for this job/instance from PushGateway.
|
|
183
|
-
*
|
|
184
|
-
* @param {Object} [params]
|
|
185
|
-
* @param {string} [params.jobName] Job name (defaults to appName)
|
|
186
|
-
* @param {Object} [params.groupings] Grouping labels
|
|
187
|
-
* @param {string} [params.groupings.process_type] Process type label
|
|
188
|
-
* @param {string} [params.groupings.instance] Instance/dyno ID
|
|
189
|
-
* @returns {Promise<void>}
|
|
190
|
-
*/
|
|
191
|
-
gatewayDelete: (params?: {
|
|
192
|
-
jobName?: string | undefined;
|
|
193
|
-
groupings?: {
|
|
194
|
-
process_type?: string | undefined;
|
|
195
|
-
instance?: string | undefined;
|
|
196
|
-
} | undefined;
|
|
197
|
-
} | undefined) => Promise<void>;
|
|
198
|
-
/**
|
|
199
|
-
* Push metrics to PushGateway.
|
|
200
|
-
*
|
|
201
|
-
* @param {object} [params]
|
|
202
|
-
* @param {string} [params.jobName]
|
|
203
|
-
* @param {object} [params.groupings]
|
|
204
|
-
* @returns {Promise<void>}
|
|
205
|
-
*/
|
|
206
|
-
gatewayPush: (params?: {
|
|
207
|
-
jobName?: string | undefined;
|
|
208
|
-
groupings?: object | undefined;
|
|
209
|
-
} | undefined) => Promise<void>;
|
|
63
|
+
private _collectHttpMetrics;
|
|
210
64
|
/**
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
* @param {string[]} labels Additional label names
|
|
215
|
-
* @returns {string[]} Combined label names
|
|
65
|
+
* Express middleware to track HTTP requests.
|
|
66
|
+
* Track the `http_app_requests_total` and `http_app_requests_total_duration` metric.
|
|
216
67
|
*/
|
|
217
|
-
|
|
218
|
-
getDefaultLabels: (labels?: any[]) => {
|
|
219
|
-
app: string;
|
|
220
|
-
dyno_id: string;
|
|
221
|
-
process_type: string;
|
|
222
|
-
};
|
|
223
|
-
_setCleanupHandlers: () => void;
|
|
224
|
-
get metricsEnabled(): boolean;
|
|
225
|
-
get metricsLogValues(): boolean;
|
|
226
|
-
get registry(): client.Registry<"text/plain; version=0.0.4; charset=utf-8">;
|
|
68
|
+
trackHttpRequestMiddleware: (req: any, res: any, next: any) => void;
|
|
227
69
|
}
|
|
228
|
-
import
|
|
70
|
+
import { BaseMetricsClient } from "./baseMetricsClient";
|
|
229
71
|
//# sourceMappingURL=metricsClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metricsClient.d.ts","sourceRoot":"","sources":["../src/metricsClient.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"metricsClient.d.ts","sourceRoot":"","sources":["../src/metricsClient.js"],"names":[],"mappings":"AAIA;;;;GAIG;AACH;IAiBI,yBAAyB;IACzB,uBAAgC;IAEhC,0BAA4B;IAK9B;;;OAGG;IACH,4BA4DC;IAED;;;OAGG;IACH,0BAFa,MAAM,CA2BlB;IAED;;;OAGG;IACH,oBAFa,MAAM,CAiBlB;IAED;;;OAGG;IACH,2BAFa,MAAM,CAWlB;IAED;;;OAGG;IACH,2BAFa,MAAM,CAgBlB;IAED;;;OAGG;IACH,cAFa,QAAQ,MAAM,CAAC,CAO3B;IAED;;;;;;;;;;OAUG;IACH;QAP0B,MAAM,EAArB,MAAM;QACS,KAAK,EAApB,MAAM;QACS,WAAW,EAA1B,MAAM;QACU,KAAK;QACL,UAAU;QACX,QAAQ,EAAvB,MAAM;aAoBhB;IAED;;;OAGG;IACH,4BA0CC;IAUD;;;OAGG;IACH,oEA+BC;CACF"}
|