@pawells/nestjs-prometheus 1.1.2 → 2.0.0-dev.f44b25c
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/README.md +2 -2
- package/build/README.md +2 -2
- package/build/controllers/metrics.controller.d.ts +6 -6
- package/build/controllers/metrics.controller.d.ts.map +1 -1
- package/build/controllers/metrics.controller.js +11 -11
- package/build/controllers/metrics.controller.js.map +1 -1
- package/build/package.json +2 -2
- package/build/prometheus.exporter.d.ts +13 -13
- package/build/prometheus.exporter.d.ts.map +1 -1
- package/build/prometheus.exporter.js +83 -83
- package/build/prometheus.exporter.js.map +1 -1
- package/build/prometheus.module.d.ts +3 -3
- package/build/prometheus.module.d.ts.map +1 -1
- package/build/prometheus.module.js +7 -7
- package/build/prometheus.module.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -201,8 +201,8 @@ The main NestJS module. Implements `OnModuleInit` and `OnApplicationShutdown`.
|
|
|
201
201
|
Implements `IMetricsExporter` from `@pawells/nestjs-shared`.
|
|
202
202
|
|
|
203
203
|
**Properties:**
|
|
204
|
-
- `
|
|
205
|
-
- `
|
|
204
|
+
- `SupportsEventBased` - `true` (buffers metric values)
|
|
205
|
+
- `SupportsPull` - `true` (supports pull-based retrieval)
|
|
206
206
|
|
|
207
207
|
**Methods:**
|
|
208
208
|
- `onDescriptorRegistered(descriptor: MetricDescriptor)` - Called when a metric is registered; creates the appropriate prom-client instrument
|
package/build/README.md
CHANGED
|
@@ -201,8 +201,8 @@ The main NestJS module. Implements `OnModuleInit` and `OnApplicationShutdown`.
|
|
|
201
201
|
Implements `IMetricsExporter` from `@pawells/nestjs-shared`.
|
|
202
202
|
|
|
203
203
|
**Properties:**
|
|
204
|
-
- `
|
|
205
|
-
- `
|
|
204
|
+
- `SupportsEventBased` - `true` (buffers metric values)
|
|
205
|
+
- `SupportsPull` - `true` (supports pull-based retrieval)
|
|
206
206
|
|
|
207
207
|
**Methods:**
|
|
208
208
|
- `onDescriptorRegistered(descriptor: MetricDescriptor)` - Called when a metric is registered; creates the appropriate prom-client instrument
|
|
@@ -11,7 +11,7 @@ import { PrometheusExporter } from '../prometheus.exporter.js';
|
|
|
11
11
|
*
|
|
12
12
|
* Response Headers:
|
|
13
13
|
* - `Content-Type: text/plain; version=0.0.4; charset=utf-8`
|
|
14
|
-
* - `X-Robots-
|
|
14
|
+
* - `X-Robots-ITag: noindex, nofollow` — prevents search engine indexing
|
|
15
15
|
*
|
|
16
16
|
* Security:
|
|
17
17
|
* - Protected by MetricsGuard from @pawells/nestjs-shared
|
|
@@ -25,7 +25,7 @@ import { PrometheusExporter } from '../prometheus.exporter.js';
|
|
|
25
25
|
* Response:
|
|
26
26
|
* 200 OK
|
|
27
27
|
* Content-Type: text/plain; version=0.0.4; charset=utf-8
|
|
28
|
-
* X-Robots-
|
|
28
|
+
* X-Robots-ITag: noindex, nofollow
|
|
29
29
|
*
|
|
30
30
|
* # HELP http_request_duration_seconds Duration of HTTP requests in seconds
|
|
31
31
|
* # TYPE http_request_duration_seconds histogram
|
|
@@ -34,7 +34,7 @@ import { PrometheusExporter } from '../prometheus.exporter.js';
|
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
36
|
export declare class MetricsController {
|
|
37
|
-
private readonly
|
|
37
|
+
private readonly Exporter;
|
|
38
38
|
constructor(exporter: PrometheusExporter);
|
|
39
39
|
/**
|
|
40
40
|
* Get all metrics in Prometheus text format
|
|
@@ -55,7 +55,7 @@ export declare class MetricsController {
|
|
|
55
55
|
*
|
|
56
56
|
* Response Headers:
|
|
57
57
|
* - Content-Type: text/plain; version=0.0.4; charset=utf-8
|
|
58
|
-
* - X-Robots-
|
|
58
|
+
* - X-Robots-ITag: noindex, nofollow
|
|
59
59
|
*
|
|
60
60
|
* @param response - Express response object
|
|
61
61
|
* @returns Promise that resolves when response is sent
|
|
@@ -67,7 +67,7 @@ export declare class MetricsController {
|
|
|
67
67
|
*
|
|
68
68
|
* HTTP/1.1 200 OK
|
|
69
69
|
* Content-Type: text/plain; version=0.0.4; charset=utf-8
|
|
70
|
-
* X-Robots-
|
|
70
|
+
* X-Robots-ITag: noindex, nofollow
|
|
71
71
|
*
|
|
72
72
|
* # HELP process_cpu_user_seconds_total Total user CPU time spent in seconds.
|
|
73
73
|
* # TYPE process_cpu_user_seconds_total counter
|
|
@@ -79,6 +79,6 @@ export declare class MetricsController {
|
|
|
79
79
|
* ...
|
|
80
80
|
* ```
|
|
81
81
|
*/
|
|
82
|
-
|
|
82
|
+
GetMetrics(response: Response): Promise<void>;
|
|
83
83
|
}
|
|
84
84
|
//# sourceMappingURL=metrics.controller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.controller.d.ts","sourceRoot":"","sources":["../../src/controllers/metrics.controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBACa,iBAAiB;
|
|
1
|
+
{"version":3,"file":"metrics.controller.d.ts","sourceRoot":"","sources":["../../src/controllers/metrics.controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBACa,iBAAiB;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;gBAG7C,QAAQ,EAAE,kBAAkB;IAK7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA0CG;IAKU,UAAU,CAAQ,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CAIjE"}
|
|
@@ -24,7 +24,7 @@ import { PrometheusExporter } from '../prometheus.exporter.js';
|
|
|
24
24
|
*
|
|
25
25
|
* Response Headers:
|
|
26
26
|
* - `Content-Type: text/plain; version=0.0.4; charset=utf-8`
|
|
27
|
-
* - `X-Robots-
|
|
27
|
+
* - `X-Robots-ITag: noindex, nofollow` — prevents search engine indexing
|
|
28
28
|
*
|
|
29
29
|
* Security:
|
|
30
30
|
* - Protected by MetricsGuard from @pawells/nestjs-shared
|
|
@@ -38,7 +38,7 @@ import { PrometheusExporter } from '../prometheus.exporter.js';
|
|
|
38
38
|
* Response:
|
|
39
39
|
* 200 OK
|
|
40
40
|
* Content-Type: text/plain; version=0.0.4; charset=utf-8
|
|
41
|
-
* X-Robots-
|
|
41
|
+
* X-Robots-ITag: noindex, nofollow
|
|
42
42
|
*
|
|
43
43
|
* # HELP http_request_duration_seconds Duration of HTTP requests in seconds
|
|
44
44
|
* # TYPE http_request_duration_seconds histogram
|
|
@@ -47,9 +47,9 @@ import { PrometheusExporter } from '../prometheus.exporter.js';
|
|
|
47
47
|
* ```
|
|
48
48
|
*/
|
|
49
49
|
let MetricsController = class MetricsController {
|
|
50
|
-
|
|
50
|
+
Exporter;
|
|
51
51
|
constructor(exporter) {
|
|
52
|
-
this.
|
|
52
|
+
this.Exporter = exporter;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* Get all metrics in Prometheus text format
|
|
@@ -70,7 +70,7 @@ let MetricsController = class MetricsController {
|
|
|
70
70
|
*
|
|
71
71
|
* Response Headers:
|
|
72
72
|
* - Content-Type: text/plain; version=0.0.4; charset=utf-8
|
|
73
|
-
* - X-Robots-
|
|
73
|
+
* - X-Robots-ITag: noindex, nofollow
|
|
74
74
|
*
|
|
75
75
|
* @param response - Express response object
|
|
76
76
|
* @returns Promise that resolves when response is sent
|
|
@@ -82,7 +82,7 @@ let MetricsController = class MetricsController {
|
|
|
82
82
|
*
|
|
83
83
|
* HTTP/1.1 200 OK
|
|
84
84
|
* Content-Type: text/plain; version=0.0.4; charset=utf-8
|
|
85
|
-
* X-Robots-
|
|
85
|
+
* X-Robots-ITag: noindex, nofollow
|
|
86
86
|
*
|
|
87
87
|
* # HELP process_cpu_user_seconds_total Total user CPU time spent in seconds.
|
|
88
88
|
* # TYPE process_cpu_user_seconds_total counter
|
|
@@ -94,21 +94,21 @@ let MetricsController = class MetricsController {
|
|
|
94
94
|
* ...
|
|
95
95
|
* ```
|
|
96
96
|
*/
|
|
97
|
-
async
|
|
98
|
-
const
|
|
99
|
-
response.send(
|
|
97
|
+
async GetMetrics(response) {
|
|
98
|
+
const Metrics = await this.Exporter.GetMetrics();
|
|
99
|
+
response.send(Metrics);
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
102
|
__decorate([
|
|
103
103
|
Get('metrics'),
|
|
104
104
|
UseGuards(MetricsGuard),
|
|
105
105
|
Header('Content-Type', 'text/plain; version=0.0.4; charset=utf-8'),
|
|
106
|
-
Header('X-Robots-
|
|
106
|
+
Header('X-Robots-ITag', 'noindex, nofollow'),
|
|
107
107
|
__param(0, Res()),
|
|
108
108
|
__metadata("design:type", Function),
|
|
109
109
|
__metadata("design:paramtypes", [Object]),
|
|
110
110
|
__metadata("design:returntype", Promise)
|
|
111
|
-
], MetricsController.prototype, "
|
|
111
|
+
], MetricsController.prototype, "GetMetrics", null);
|
|
112
112
|
MetricsController = __decorate([
|
|
113
113
|
Controller(),
|
|
114
114
|
__metadata("design:paramtypes", [PrometheusExporter])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.controller.js","sourceRoot":"","sources":["../../src/controllers/metrics.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;
|
|
1
|
+
{"version":3,"file":"metrics.controller.js","sourceRoot":"","sources":["../../src/controllers/metrics.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IACZ,QAAQ,CAAqB;IAE9C,YACC,QAA4B;QAE5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA0CG;IAKU,AAAN,KAAK,CAAC,UAAU,CAAQ,QAAkB;QAChD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;QACjD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxB,CAAC;CACD,CAAA;AAJa;IAJZ,GAAG,CAAC,SAAS,CAAC;IACd,SAAS,CAAC,YAAY,CAAC;IACvB,MAAM,CAAC,cAAc,EAAE,0CAA0C,CAAC;IAClE,MAAM,CAAC,eAAe,EAAE,mBAAmB,CAAC;IACpB,WAAA,GAAG,EAAE,CAAA;;;;mDAG7B;AA3DW,iBAAiB;IAD7B,UAAU,EAAE;qCAKD,kBAAkB;GAJjB,iBAAiB,CA4D7B"}
|
package/build/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pawells/nestjs-prometheus",
|
|
3
3
|
"displayName": "@pawells/nestjs-prometheus",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0-dev.f44b25c",
|
|
5
5
|
"description": "NestJS Prometheus metrics module with endpoint controller",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./build/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"xss": ">=1.0.0"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@pawells/nestjs-shared": "
|
|
43
|
+
"@pawells/nestjs-shared": "2.0.0-dev.f44b25c"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=22.0.0"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IMetricsExporter,
|
|
1
|
+
import type { IMetricsExporter, IMetricDescriptor, IMetricValue } from '@pawells/nestjs-shared';
|
|
2
2
|
/**
|
|
3
3
|
* Prometheus metrics exporter implementation
|
|
4
4
|
*
|
|
@@ -33,34 +33,34 @@ export declare class PrometheusExporter implements IMetricsExporter {
|
|
|
33
33
|
* This exporter buffers metric values as they are recorded and flushes
|
|
34
34
|
* them into prom-client instruments on each pull (getMetrics)
|
|
35
35
|
*/
|
|
36
|
-
readonly
|
|
36
|
+
readonly SupportsEventBased = true;
|
|
37
37
|
/**
|
|
38
38
|
* This exporter supports pull-based metric retrieval
|
|
39
39
|
*/
|
|
40
|
-
readonly
|
|
40
|
+
readonly SupportsPull = true;
|
|
41
41
|
/**
|
|
42
42
|
* Prom-client Registry instance for managing instruments
|
|
43
43
|
* @private
|
|
44
44
|
*/
|
|
45
|
-
private readonly
|
|
45
|
+
private readonly Registry;
|
|
46
46
|
/**
|
|
47
47
|
* Cache of created prom-client instruments (Counter, Histogram, Gauge)
|
|
48
48
|
* Keyed by metric name
|
|
49
49
|
* @private
|
|
50
50
|
*/
|
|
51
|
-
private readonly
|
|
51
|
+
private readonly Instruments;
|
|
52
52
|
/**
|
|
53
53
|
* Pending metric values to be flushed into prom-client instruments on next getMetrics()
|
|
54
54
|
* Keyed by metric name
|
|
55
55
|
* @private
|
|
56
56
|
*/
|
|
57
|
-
private readonly
|
|
57
|
+
private readonly Pending;
|
|
58
58
|
/**
|
|
59
59
|
* Running totals for updown_counter metrics (persistent across scrapes)
|
|
60
60
|
* Keyed by metric name, then by normalized label key
|
|
61
61
|
* @private
|
|
62
62
|
*/
|
|
63
|
-
private readonly
|
|
63
|
+
private readonly GaugeValues;
|
|
64
64
|
/**
|
|
65
65
|
* Maximum number of pending metric values per metric before culling oldest entries
|
|
66
66
|
* Prevents unbounded memory growth if metrics are recorded much faster than pulled
|
|
@@ -70,12 +70,12 @@ export declare class PrometheusExporter implements IMetricsExporter {
|
|
|
70
70
|
/**
|
|
71
71
|
* Logger instance for warnings and errors
|
|
72
72
|
*/
|
|
73
|
-
private readonly
|
|
73
|
+
private readonly Logger;
|
|
74
74
|
/**
|
|
75
75
|
* Normalize label keys to handle consistent ordering regardless of insertion order
|
|
76
76
|
* @private
|
|
77
77
|
*/
|
|
78
|
-
private static
|
|
78
|
+
private static NormalizeLabelKey;
|
|
79
79
|
/**
|
|
80
80
|
* Create a new PrometheusExporter instance
|
|
81
81
|
*
|
|
@@ -109,7 +109,7 @@ export declare class PrometheusExporter implements IMetricsExporter {
|
|
|
109
109
|
* });
|
|
110
110
|
* ```
|
|
111
111
|
*/
|
|
112
|
-
|
|
112
|
+
OnDescriptorRegistered(descriptor: IMetricDescriptor): void;
|
|
113
113
|
/**
|
|
114
114
|
* Buffer a metric value to be flushed on next getMetrics() call
|
|
115
115
|
*
|
|
@@ -133,7 +133,7 @@ export declare class PrometheusExporter implements IMetricsExporter {
|
|
|
133
133
|
* });
|
|
134
134
|
* ```
|
|
135
135
|
*/
|
|
136
|
-
|
|
136
|
+
OnMetricRecorded(value: IMetricValue): void;
|
|
137
137
|
/**
|
|
138
138
|
* Retrieve all metrics in Prometheus text format
|
|
139
139
|
*
|
|
@@ -164,7 +164,7 @@ export declare class PrometheusExporter implements IMetricsExporter {
|
|
|
164
164
|
* // http_request_duration_seconds_bucket{le="0.01",...} 5
|
|
165
165
|
* ```
|
|
166
166
|
*/
|
|
167
|
-
|
|
167
|
+
GetMetrics(): Promise<string>;
|
|
168
168
|
/**
|
|
169
169
|
* Shutdown the exporter and clean up resources
|
|
170
170
|
*
|
|
@@ -182,6 +182,6 @@ export declare class PrometheusExporter implements IMetricsExporter {
|
|
|
182
182
|
* await exporter.shutdown();
|
|
183
183
|
* ```
|
|
184
184
|
*/
|
|
185
|
-
|
|
185
|
+
Shutdown(): Promise<void>;
|
|
186
186
|
}
|
|
187
187
|
//# sourceMappingURL=prometheus.exporter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus.exporter.d.ts","sourceRoot":"","sources":["../src/prometheus.exporter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"prometheus.exporter.d.ts","sourceRoot":"","sources":["../src/prometheus.exporter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEhG;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBACa,kBAAmB,YAAW,gBAAgB;IAC1D;;;OAGG;IACH,SAAgB,kBAAkB,QAAQ;IAE1C;;OAEG;IACH,SAAgB,YAAY,QAAQ;IAEpC;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IAEpC;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAmE;IAE/F;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;IAEtD;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAmC;IAE/D;;;;OAIG;IAEH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,sBAAsB,CAAQ;IAEtD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IAEnC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAKhC;;;;;OAKG;;IAYH;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACI,sBAAsB,CAAC,UAAU,EAAE,iBAAiB,GAAG,IAAI;IAgElE;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACI,gBAAgB,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAiBlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACU,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAqG1C;;;;;;;;;;;;;;;;OAgBG;IAEU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAMtC"}
|
|
@@ -46,34 +46,34 @@ let PrometheusExporter = class PrometheusExporter {
|
|
|
46
46
|
* This exporter buffers metric values as they are recorded and flushes
|
|
47
47
|
* them into prom-client instruments on each pull (getMetrics)
|
|
48
48
|
*/
|
|
49
|
-
|
|
49
|
+
SupportsEventBased = true;
|
|
50
50
|
/**
|
|
51
51
|
* This exporter supports pull-based metric retrieval
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
SupportsPull = true;
|
|
54
54
|
/**
|
|
55
55
|
* Prom-client Registry instance for managing instruments
|
|
56
56
|
* @private
|
|
57
57
|
*/
|
|
58
|
-
|
|
58
|
+
Registry;
|
|
59
59
|
/**
|
|
60
60
|
* Cache of created prom-client instruments (Counter, Histogram, Gauge)
|
|
61
61
|
* Keyed by metric name
|
|
62
62
|
* @private
|
|
63
63
|
*/
|
|
64
|
-
|
|
64
|
+
Instruments;
|
|
65
65
|
/**
|
|
66
66
|
* Pending metric values to be flushed into prom-client instruments on next getMetrics()
|
|
67
67
|
* Keyed by metric name
|
|
68
68
|
* @private
|
|
69
69
|
*/
|
|
70
|
-
|
|
70
|
+
Pending;
|
|
71
71
|
/**
|
|
72
72
|
* Running totals for updown_counter metrics (persistent across scrapes)
|
|
73
73
|
* Keyed by metric name, then by normalized label key
|
|
74
74
|
* @private
|
|
75
75
|
*/
|
|
76
|
-
|
|
76
|
+
GaugeValues;
|
|
77
77
|
/**
|
|
78
78
|
* Maximum number of pending metric values per metric before culling oldest entries
|
|
79
79
|
* Prevents unbounded memory growth if metrics are recorded much faster than pulled
|
|
@@ -84,14 +84,14 @@ let PrometheusExporter = class PrometheusExporter {
|
|
|
84
84
|
/**
|
|
85
85
|
* Logger instance for warnings and errors
|
|
86
86
|
*/
|
|
87
|
-
|
|
87
|
+
Logger;
|
|
88
88
|
/**
|
|
89
89
|
* Normalize label keys to handle consistent ordering regardless of insertion order
|
|
90
90
|
* @private
|
|
91
91
|
*/
|
|
92
|
-
static
|
|
93
|
-
const
|
|
94
|
-
return JSON.stringify(Object.fromEntries(
|
|
92
|
+
static NormalizeLabelKey(labels) {
|
|
93
|
+
const SortedEntries = Object.entries(labels).sort(([a], [b]) => a.localeCompare(b));
|
|
94
|
+
return JSON.stringify(Object.fromEntries(SortedEntries));
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
97
|
* Create a new PrometheusExporter instance
|
|
@@ -100,13 +100,13 @@ let PrometheusExporter = class PrometheusExporter {
|
|
|
100
100
|
* (process CPU, memory, event loop, garbage collection, etc.).
|
|
101
101
|
*/
|
|
102
102
|
constructor() {
|
|
103
|
-
this.
|
|
104
|
-
this.
|
|
105
|
-
this.
|
|
106
|
-
this.
|
|
107
|
-
this.
|
|
103
|
+
this.Registry = new Registry();
|
|
104
|
+
this.Instruments = new Map();
|
|
105
|
+
this.Pending = new Map();
|
|
106
|
+
this.GaugeValues = new Map();
|
|
107
|
+
this.Logger = new AppLogger(undefined, PrometheusExporter_1.name);
|
|
108
108
|
// Collect Node.js default metrics into our registry
|
|
109
|
-
collectDefaultMetrics({ register: this.
|
|
109
|
+
collectDefaultMetrics({ register: this.Registry });
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
112
|
* Called when a metric descriptor is registered in InstrumentationRegistry
|
|
@@ -134,59 +134,59 @@ let PrometheusExporter = class PrometheusExporter {
|
|
|
134
134
|
* });
|
|
135
135
|
* ```
|
|
136
136
|
*/
|
|
137
|
-
|
|
137
|
+
OnDescriptorRegistered(descriptor) {
|
|
138
138
|
const { name, type, help, labelNames, buckets } = descriptor;
|
|
139
139
|
// Guard against duplicate registration
|
|
140
|
-
if (this.
|
|
140
|
+
if (this.Instruments.has(name)) {
|
|
141
141
|
return;
|
|
142
142
|
}
|
|
143
143
|
// Validate required fields
|
|
144
144
|
if (!name) {
|
|
145
|
-
this.
|
|
145
|
+
this.Logger.warn('Metric descriptor registered with empty name');
|
|
146
146
|
return;
|
|
147
147
|
}
|
|
148
148
|
if (!help) {
|
|
149
|
-
this.
|
|
149
|
+
this.Logger.warn(`Metric descriptor "${name}" registered with empty help text`);
|
|
150
150
|
return;
|
|
151
151
|
}
|
|
152
|
-
let
|
|
152
|
+
let Instrument;
|
|
153
153
|
switch (type) {
|
|
154
154
|
case 'counter':
|
|
155
|
-
|
|
155
|
+
Instrument = new Counter({
|
|
156
156
|
name,
|
|
157
157
|
help,
|
|
158
158
|
labelNames,
|
|
159
|
-
registers: [this.
|
|
159
|
+
registers: [this.Registry],
|
|
160
160
|
});
|
|
161
161
|
break;
|
|
162
162
|
case 'histogram':
|
|
163
|
-
|
|
163
|
+
Instrument = new Histogram({
|
|
164
164
|
name,
|
|
165
165
|
help,
|
|
166
166
|
labelNames,
|
|
167
167
|
buckets,
|
|
168
|
-
registers: [this.
|
|
168
|
+
registers: [this.Registry],
|
|
169
169
|
});
|
|
170
170
|
break;
|
|
171
171
|
case 'gauge':
|
|
172
172
|
case 'updown_counter':
|
|
173
173
|
// Both gauge and updown_counter map to prom-client Gauge
|
|
174
|
-
|
|
174
|
+
Instrument = new Gauge({
|
|
175
175
|
name,
|
|
176
176
|
help,
|
|
177
177
|
labelNames,
|
|
178
|
-
registers: [this.
|
|
178
|
+
registers: [this.Registry],
|
|
179
179
|
});
|
|
180
180
|
// Initialize running totals map for this metric
|
|
181
181
|
if (type === 'updown_counter') {
|
|
182
|
-
this.
|
|
182
|
+
this.GaugeValues.set(name, new Map());
|
|
183
183
|
}
|
|
184
184
|
break;
|
|
185
185
|
default:
|
|
186
186
|
throw new Error(`Unsupported metric type "${type}" for descriptor "${name}"`);
|
|
187
187
|
}
|
|
188
|
-
this.
|
|
189
|
-
this.
|
|
188
|
+
this.Instruments.set(name, Instrument);
|
|
189
|
+
this.Pending.set(name, []);
|
|
190
190
|
}
|
|
191
191
|
/**
|
|
192
192
|
* Buffer a metric value to be flushed on next getMetrics() call
|
|
@@ -211,19 +211,19 @@ let PrometheusExporter = class PrometheusExporter {
|
|
|
211
211
|
* });
|
|
212
212
|
* ```
|
|
213
213
|
*/
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
const
|
|
217
|
-
if (
|
|
218
|
-
|
|
214
|
+
OnMetricRecorded(value) {
|
|
215
|
+
const MetricName = value.descriptor.name;
|
|
216
|
+
const PendingArray = this.Pending.get(MetricName);
|
|
217
|
+
if (PendingArray) {
|
|
218
|
+
PendingArray.push(value);
|
|
219
219
|
// Cap pending array to prevent unbounded memory growth
|
|
220
|
-
if (
|
|
221
|
-
|
|
220
|
+
if (PendingArray.length > PrometheusExporter_1.MAX_PENDING_PER_METRIC) {
|
|
221
|
+
PendingArray.shift();
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
224
|
else {
|
|
225
225
|
// Warn if metric recorded before descriptor registration (data will be lost)
|
|
226
|
-
this.
|
|
226
|
+
this.Logger.warn(`Metric recorded before descriptor registration: ${MetricName}`);
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
/**
|
|
@@ -256,94 +256,94 @@ let PrometheusExporter = class PrometheusExporter {
|
|
|
256
256
|
* // http_request_duration_seconds_bucket{le="0.01",...} 5
|
|
257
257
|
* ```
|
|
258
258
|
*/
|
|
259
|
-
async
|
|
259
|
+
async GetMetrics() {
|
|
260
260
|
// Flush all pending values into prom-client instruments
|
|
261
261
|
// Use atomic swap pattern: capture current values and replace with empty array
|
|
262
262
|
// to prevent loss of metrics recorded concurrently during flush
|
|
263
|
-
for (const [
|
|
263
|
+
for (const [MetricName, PendingValues] of this.Pending.entries()) {
|
|
264
264
|
// Atomically swap pending array with a fresh one
|
|
265
|
-
this.
|
|
266
|
-
if (
|
|
265
|
+
this.Pending.set(MetricName, []);
|
|
266
|
+
if (PendingValues.length === 0) {
|
|
267
267
|
continue;
|
|
268
268
|
}
|
|
269
|
-
const
|
|
270
|
-
if (!
|
|
269
|
+
const Instrument = this.Instruments.get(MetricName);
|
|
270
|
+
if (!Instrument) {
|
|
271
271
|
// Instrument not yet created, skip pending values
|
|
272
272
|
continue;
|
|
273
273
|
}
|
|
274
274
|
// Record all pending values into the appropriate instrument
|
|
275
|
-
if (
|
|
275
|
+
if (Instrument instanceof Counter) {
|
|
276
276
|
// Counter: increment by value for each pending entry
|
|
277
|
-
for (const
|
|
277
|
+
for (const MetricValue of PendingValues) {
|
|
278
278
|
try {
|
|
279
|
-
|
|
279
|
+
Instrument.inc(MetricValue.labels, MetricValue.value);
|
|
280
280
|
}
|
|
281
281
|
catch (recordError) {
|
|
282
|
-
this.
|
|
282
|
+
this.Logger.warn(`Failed to record metric value for "${MetricName}": ${getErrorMessage(recordError)}`);
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
|
-
else if (
|
|
286
|
+
else if (Instrument instanceof Histogram) {
|
|
287
287
|
// Histogram: observe value for each pending entry
|
|
288
|
-
for (const
|
|
288
|
+
for (const MetricValue of PendingValues) {
|
|
289
289
|
try {
|
|
290
|
-
|
|
290
|
+
Instrument.observe(MetricValue.labels, MetricValue.value);
|
|
291
291
|
}
|
|
292
292
|
catch (recordError) {
|
|
293
|
-
this.
|
|
293
|
+
this.Logger.warn(`Failed to record metric value for "${MetricName}": ${getErrorMessage(recordError)}`);
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
|
-
else if (
|
|
297
|
+
else if (Instrument instanceof Gauge) {
|
|
298
298
|
// Gauge: set values directly per label set
|
|
299
299
|
// updown_counter: accumulate values per label set and maintain running total
|
|
300
|
-
const
|
|
301
|
-
for (const
|
|
302
|
-
const
|
|
303
|
-
const
|
|
304
|
-
if (
|
|
305
|
-
|
|
300
|
+
const AccumulatedValues = new Map();
|
|
301
|
+
for (const MetricValue of PendingValues) {
|
|
302
|
+
const LabelKey = PrometheusExporter_1.NormalizeLabelKey(MetricValue.labels);
|
|
303
|
+
const Existing = AccumulatedValues.get(LabelKey);
|
|
304
|
+
if (Existing) {
|
|
305
|
+
Existing.value += MetricValue.value;
|
|
306
306
|
}
|
|
307
307
|
else {
|
|
308
|
-
|
|
309
|
-
labels:
|
|
310
|
-
value:
|
|
308
|
+
AccumulatedValues.set(LabelKey, {
|
|
309
|
+
labels: MetricValue.labels,
|
|
310
|
+
value: MetricValue.value,
|
|
311
311
|
});
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
314
|
// Get running totals map for this metric (if it exists, it's an updown_counter)
|
|
315
|
-
const
|
|
315
|
+
const RunningTotals = this.GaugeValues.get(MetricName);
|
|
316
316
|
// Apply accumulated values to the gauge (iterate only through unique label sets)
|
|
317
|
-
for (const { labels, value:
|
|
317
|
+
for (const { labels, value: AccumulatedValue } of AccumulatedValues.values()) {
|
|
318
318
|
try {
|
|
319
|
-
let
|
|
319
|
+
let FinalValue = AccumulatedValue;
|
|
320
320
|
// For updown_counters, add to running total; for regular gauges, use value directly
|
|
321
|
-
if (
|
|
322
|
-
const
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
321
|
+
if (RunningTotals) {
|
|
322
|
+
const NormalizedKey = PrometheusExporter_1.NormalizeLabelKey(labels);
|
|
323
|
+
const CurrentTotal = RunningTotals.get(NormalizedKey) ?? 0;
|
|
324
|
+
FinalValue = CurrentTotal + AccumulatedValue;
|
|
325
|
+
RunningTotals.set(NormalizedKey, FinalValue);
|
|
326
326
|
}
|
|
327
327
|
// Convert number values to strings if needed for prom-client
|
|
328
|
-
const
|
|
329
|
-
for (const [
|
|
330
|
-
|
|
328
|
+
const LabelsForProm = {};
|
|
329
|
+
for (const [Key, Val] of Object.entries(labels)) {
|
|
330
|
+
LabelsForProm[Key] = String(Val);
|
|
331
331
|
}
|
|
332
|
-
|
|
332
|
+
Instrument.set(LabelsForProm, FinalValue);
|
|
333
333
|
}
|
|
334
334
|
catch (recordError) {
|
|
335
|
-
this.
|
|
335
|
+
this.Logger.warn(`Failed to record metric value for "${MetricName}": ${getErrorMessage(recordError)}`);
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
340
|
// Return metrics in Prometheus text format
|
|
341
341
|
try {
|
|
342
|
-
return await this.
|
|
342
|
+
return await this.Registry.metrics();
|
|
343
343
|
}
|
|
344
344
|
catch (error) {
|
|
345
|
-
const
|
|
346
|
-
this.
|
|
345
|
+
const Message = getErrorMessage(error);
|
|
346
|
+
this.Logger.error(`Failed to generate Prometheus metrics: ${Message}`);
|
|
347
347
|
throw error;
|
|
348
348
|
}
|
|
349
349
|
}
|
|
@@ -365,11 +365,11 @@ let PrometheusExporter = class PrometheusExporter {
|
|
|
365
365
|
* ```
|
|
366
366
|
*/
|
|
367
367
|
// eslint-disable-next-line require-await
|
|
368
|
-
async
|
|
369
|
-
this.
|
|
370
|
-
this.
|
|
371
|
-
this.
|
|
372
|
-
this.
|
|
368
|
+
async Shutdown() {
|
|
369
|
+
this.Registry.clear();
|
|
370
|
+
this.Instruments.clear();
|
|
371
|
+
this.Pending.clear();
|
|
372
|
+
this.GaugeValues.clear();
|
|
373
373
|
}
|
|
374
374
|
};
|
|
375
375
|
PrometheusExporter = PrometheusExporter_1 = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus.exporter.js","sourceRoot":"","sources":["../src/prometheus.exporter.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,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CAAC;YACvE,MAAM,KAAK,CAAC;QACb,CAAC;IACF,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,yCAAyC;IAClC,KAAK,CAAC,QAAQ;QACpB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;;AA1WW,kBAAkB;IAD9B,UAAU,EAAE;;GACA,kBAAkB,CA2W9B"}
|
|
@@ -35,8 +35,8 @@ import { PrometheusExporter } from './prometheus.exporter.js';
|
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
37
|
export declare class PrometheusModule implements OnModuleInit, OnApplicationShutdown {
|
|
38
|
-
private readonly
|
|
39
|
-
private readonly
|
|
38
|
+
private readonly Exporter;
|
|
39
|
+
private readonly Registry;
|
|
40
40
|
/**
|
|
41
41
|
* Create a global PrometheusModule with automatic registration
|
|
42
42
|
*
|
|
@@ -53,7 +53,7 @@ export declare class PrometheusModule implements OnModuleInit, OnApplicationShut
|
|
|
53
53
|
* export class AppModule {}
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
|
-
static
|
|
56
|
+
static ForRoot(): DynamicModule;
|
|
57
57
|
constructor(exporter: PrometheusExporter, registry: InstrumentationRegistry);
|
|
58
58
|
/**
|
|
59
59
|
* Initialize the module and register the Prometheus exporter
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus.module.d.ts","sourceRoot":"","sources":["../src/prometheus.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,YAAY,EAAE,qBAAqB,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACzG,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAMa,gBAAiB,YAAW,YAAY,EAAE,qBAAqB;
|
|
1
|
+
{"version":3,"file":"prometheus.module.d.ts","sourceRoot":"","sources":["../src/prometheus.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,YAAY,EAAE,qBAAqB,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACzG,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAMa,gBAAiB,YAAW,YAAY,EAAE,qBAAqB;IAC3E,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0B;IAEnD;;;;;;;;;;;;;;;OAeG;WACW,OAAO,IAAI,aAAa;gBAOrC,QAAQ,EAAE,kBAAkB,EAC5B,QAAQ,EAAE,uBAAuB;IAMlC;;;;;;;;;;;;;;OAcG;IACI,YAAY,IAAI,IAAI;IAI3B;;;;;;;;;;;;OAYG;IACU,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;CAGnD"}
|
|
@@ -46,8 +46,8 @@ import { MetricsController } from './controllers/metrics.controller.js';
|
|
|
46
46
|
* ```
|
|
47
47
|
*/
|
|
48
48
|
let PrometheusModule = PrometheusModule_1 = class PrometheusModule {
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
Exporter;
|
|
50
|
+
Registry;
|
|
51
51
|
/**
|
|
52
52
|
* Create a global PrometheusModule with automatic registration
|
|
53
53
|
*
|
|
@@ -64,14 +64,14 @@ let PrometheusModule = PrometheusModule_1 = class PrometheusModule {
|
|
|
64
64
|
* export class AppModule {}
|
|
65
65
|
* ```
|
|
66
66
|
*/
|
|
67
|
-
static
|
|
67
|
+
static ForRoot() {
|
|
68
68
|
return {
|
|
69
69
|
module: PrometheusModule_1,
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
constructor(exporter, registry) {
|
|
73
|
-
this.
|
|
74
|
-
this.
|
|
73
|
+
this.Exporter = exporter;
|
|
74
|
+
this.Registry = registry;
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
77
|
* Initialize the module and register the Prometheus exporter
|
|
@@ -89,7 +89,7 @@ let PrometheusModule = PrometheusModule_1 = class PrometheusModule {
|
|
|
89
89
|
* ```
|
|
90
90
|
*/
|
|
91
91
|
onModuleInit() {
|
|
92
|
-
this.
|
|
92
|
+
this.Registry.RegisterExporter(this.Exporter);
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
95
|
* Clean up resources on application shutdown
|
|
@@ -105,7 +105,7 @@ let PrometheusModule = PrometheusModule_1 = class PrometheusModule {
|
|
|
105
105
|
* ```
|
|
106
106
|
*/
|
|
107
107
|
async onApplicationShutdown() {
|
|
108
|
-
await this.
|
|
108
|
+
await this.Exporter.Shutdown();
|
|
109
109
|
}
|
|
110
110
|
};
|
|
111
111
|
PrometheusModule = PrometheusModule_1 = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus.module.js","sourceRoot":"","sources":["../src/prometheus.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAA2D,MAAM,gBAAgB,CAAC;AACzG,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAOI,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;
|
|
1
|
+
{"version":3,"file":"prometheus.module.js","sourceRoot":"","sources":["../src/prometheus.module.ts"],"names":[],"mappings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estjs-prometheus",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0-dev.f44b25c",
|
|
5
5
|
"description": "NestJS Prometheus metrics module with endpoint controller",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./build/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"xss": ">=1.0.0"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@pawells/nestjs-shared": "
|
|
43
|
+
"@pawells/nestjs-shared": "2.0.0-dev.f44b25c"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@nestjs/common": "^11.1.17",
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
"class-validator": "^0.15.1",
|
|
53
53
|
"compression": "^1.8.1",
|
|
54
54
|
"csrf-csrf": "^4.0.3",
|
|
55
|
-
"express": "^5.
|
|
55
|
+
"express": "^5.2.1",
|
|
56
56
|
"helmet": "^8.1.0",
|
|
57
|
-
"joi": "^18.
|
|
57
|
+
"joi": "^18.1.2",
|
|
58
58
|
"prom-client": "^15.1.3",
|
|
59
59
|
"reflect-metadata": "^0.2.2",
|
|
60
60
|
"rxjs": "^7.8.2",
|