@balena/node-metrics-gatherer 6.1.1 → 6.1.2
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/.versionbot/CHANGELOG.yml +19 -1
- package/CHANGELOG.md +6 -0
- package/out/collectors/api/collect.js +19 -2
- package/out/collectors/api/collect.js.map +1 -1
- package/out/collectors/api/describe.js +4 -0
- package/out/collectors/api/describe.js.map +1 -1
- package/out/config.js +4 -0
- package/out/config.js.map +1 -1
- package/out/enums.js +1 -0
- package/out/enums.js.map +1 -1
- package/out/metrics-gatherer.d.ts +7 -2
- package/out/metrics-gatherer.js +52 -17
- package/out/metrics-gatherer.js.map +1 -1
- package/out/types.d.ts +2 -2
- package/out/types.js +1 -0
- package/out/types.js.map +1 -1
- package/package.json +3 -2
- package/src/collectors/api/collect.ts +1 -1
- package/src/metrics-gatherer.ts +3 -3
- package/src/types.ts +2 -2
- package/test/api-collector.spec.ts +2 -2
- package/tsconfig.json +2 -7
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
- commits:
|
|
2
|
+
- subject: Include comments in the generated output to keep jsdoc intact
|
|
3
|
+
hash: a2f651f1bcdd4b4078dc0e9c64d3fffc8843f581
|
|
4
|
+
body: ""
|
|
5
|
+
footer:
|
|
6
|
+
Change-type: patch
|
|
7
|
+
change-type: patch
|
|
8
|
+
author: Pagan Gazzard
|
|
9
|
+
- subject: Switch tsconfig module to node18
|
|
10
|
+
hash: b0681292d3f20571c3af63cd509140682ac6f402
|
|
11
|
+
body: ""
|
|
12
|
+
footer:
|
|
13
|
+
Change-type: patch
|
|
14
|
+
change-type: patch
|
|
15
|
+
author: Pagan Gazzard
|
|
16
|
+
version: 6.1.2
|
|
17
|
+
title: ""
|
|
18
|
+
date: 2025-11-26T16:27:56.909Z
|
|
1
19
|
- commits:
|
|
2
20
|
- subject: Avoid closure for onFinish handlers
|
|
3
21
|
hash: 7eb4b51838a970f1629ed95d5bf82a700844a923
|
|
@@ -8,7 +26,7 @@
|
|
|
8
26
|
author: Pagan Gazzard
|
|
9
27
|
version: 6.1.1
|
|
10
28
|
title: ""
|
|
11
|
-
date: 2025-10-
|
|
29
|
+
date: 2025-10-17T15:20:25.285Z
|
|
12
30
|
- commits:
|
|
13
31
|
- subject: Update to prom-client 15.x
|
|
14
32
|
hash: 1791a4e229c522f308e47a5ee497744065ecffaa
|
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file
|
|
|
4
4
|
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
|
|
5
5
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
6
6
|
|
|
7
|
+
# v6.1.2
|
|
8
|
+
## (2025-11-26)
|
|
9
|
+
|
|
10
|
+
* Include comments in the generated output to keep jsdoc intact [Pagan Gazzard]
|
|
11
|
+
* Switch tsconfig module to node18 [Pagan Gazzard]
|
|
12
|
+
|
|
7
13
|
# v6.1.1
|
|
8
14
|
## (2025-10-17)
|
|
9
15
|
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.collectAPIMetrics = void 0;
|
|
4
|
-
const
|
|
7
|
+
const on_finished_1 = __importDefault(require("on-finished"));
|
|
5
8
|
const describe_1 = require("./describe");
|
|
6
9
|
const collectAPIMetrics = (metrics) => {
|
|
7
10
|
(0, describe_1.describeAPIMetricsOnce)(metrics);
|
|
11
|
+
// it may be necessary to modify the request object in various ways, this can
|
|
12
|
+
// be done in this function. For example, a `_metrics_gatherer` object is
|
|
13
|
+
// added to req and req.connection for the purposes of metrics observing functions
|
|
8
14
|
const modifyReq = (req) => {
|
|
9
15
|
var _a;
|
|
10
16
|
var _b;
|
|
@@ -13,6 +19,15 @@ const collectAPIMetrics = (metrics) => {
|
|
|
13
19
|
};
|
|
14
20
|
(_a = (_b = req.connection)._metrics_gatherer) !== null && _a !== void 0 ? _a : (_b._metrics_gatherer = {});
|
|
15
21
|
};
|
|
22
|
+
// A specific sequence of steps is used to keep track of the changing values of
|
|
23
|
+
// req.connection.bytesRead and req.connection.bytesWritten
|
|
24
|
+
//
|
|
25
|
+
// These two quantities are observed when the request arrives and when it
|
|
26
|
+
// has finished to subtract the difference, rather than simply observing them
|
|
27
|
+
// when the request has finished, because the net.Socket objects (as
|
|
28
|
+
// `.connection` on Request objects) are re-used by express, and so
|
|
29
|
+
// connection.bytesRead will, at the very start of the request, give us the
|
|
30
|
+
// bytesRead/bytesWritten by the last request to use the same net.Socket object.
|
|
16
31
|
const observeBytesRW = (req) => {
|
|
17
32
|
var _a, _b;
|
|
18
33
|
const bytesReadPreviously = (_a = req.connection._metrics_gatherer.bytesRead) !== null && _a !== void 0 ? _a : 0;
|
|
@@ -27,6 +42,7 @@ const collectAPIMetrics = (metrics) => {
|
|
|
27
42
|
metrics.histogram('api_bytes_written', bytesWrittenDelta, req._metrics_gatherer.labels);
|
|
28
43
|
};
|
|
29
44
|
};
|
|
45
|
+
// observe the request latency using process.hrtime
|
|
30
46
|
const observeLatency = (req) => {
|
|
31
47
|
const t0 = process.hrtime();
|
|
32
48
|
return () => {
|
|
@@ -35,11 +51,12 @@ const collectAPIMetrics = (metrics) => {
|
|
|
35
51
|
metrics.histogram('api_latency_milliseconds', duration, req._metrics_gatherer.labels);
|
|
36
52
|
};
|
|
37
53
|
};
|
|
54
|
+
// attach a middleware to all requests to observe various metrics
|
|
38
55
|
return (req, res, next) => {
|
|
39
56
|
modifyReq(req);
|
|
40
57
|
metrics.counter('api_arrival_total', 1, req._metrics_gatherer.labels);
|
|
41
58
|
const onFinishFuncs = [observeBytesRW(req), observeLatency(req)];
|
|
42
|
-
|
|
59
|
+
(0, on_finished_1.default)(res, () => {
|
|
43
60
|
req._metrics_gatherer.labels.state = req.aborted
|
|
44
61
|
? 'aborted'
|
|
45
62
|
: 'completed';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collect.js","sourceRoot":"","sources":["../../../src/collectors/api/collect.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"collect.js","sourceRoot":"","sources":["../../../src/collectors/api/collect.ts"],"names":[],"mappings":";;;;;;AACA,8DAAqC;AAGrC,yCAAoD;AAE7C,MAAM,iBAAiB,GAAG,CAChC,OAAwB,EACsC,EAAE;IAChE,IAAA,iCAAsB,EAAC,OAAO,CAAC,CAAC;IAEhC,6EAA6E;IAC7E,yEAAyE;IACzE,kFAAkF;IAClF,MAAM,SAAS,GAAG,CAAC,GAAY,EAAE,EAAE;;;QAClC,GAAG,CAAC,iBAAiB,GAAG;YACvB,MAAM,EAAE,EAAE;SACV,CAAC;QACF,YAAA,GAAG,CAAC,UAAU,EAAC,iBAAiB,uCAAjB,iBAAiB,GAAK,EAAE,EAAC;IACzC,CAAC,CAAC;IAEF,+EAA+E;IAC/E,2DAA2D;IAC3D,EAAE;IACF,yEAAyE;IACzE,6EAA6E;IAC7E,oEAAoE;IACpE,mEAAmE;IACnE,2EAA2E;IAC3E,gFAAgF;IAChF,MAAM,cAAc,GAAG,CAAC,GAAY,EAAgB,EAAE;;QACrD,MAAM,mBAAmB,GACxB,MAAA,GAAG,CAAC,UAAU,CAAC,iBAAkB,CAAC,SAAS,mCAAI,CAAC,CAAC;QAClD,MAAM,sBAAsB,GAC3B,MAAA,GAAG,CAAC,UAAU,CAAC,iBAAkB,CAAC,YAAY,mCAAI,CAAC,CAAC;QACrD,OAAO,GAAG,EAAE;YACX,MAAM,cAAc,GAAG,GAAG,CAAC,UAAU,CAAC,SAAS,GAAG,mBAAmB,CAAC;YACtE,MAAM,iBAAiB,GACtB,GAAG,CAAC,UAAU,CAAC,YAAY,GAAG,sBAAsB,CAAC;YACtD,GAAG,CAAC,UAAU,CAAC,iBAAkB,CAAC,SAAS,GAAG,GAAG,CAAC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GAAG,CAAC,OAAO;gBAC/C,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,WAAW,CAAC;YACf,GAAG,CAAC,iBAAiB,CAAC,MAAM,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC;YAC/D,KAAK,MAAM,CAAC,IAAI,aAAa,EAAE,CAAC;gBAC/B,CAAC,EAAE,CAAC;YACL,CAAC;QACF,CAAC,CAAC,CAAC;QACH,IAAI,EAAE,CAAC;IACR,CAAC,CAAC;AACH,CAAC,CAAC;AA/EW,QAAA,iBAAiB,qBA+E5B"}
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.describeAPIMetricsOnce = void 0;
|
|
4
4
|
const config_1 = require("../../config");
|
|
5
|
+
// some or none of these labels may be actually used in the calls to observe
|
|
6
|
+
// metrics data points, but we need to specify them all up-front so that
|
|
7
|
+
// they don't appear by "surprise" to the prometheus client library, which will
|
|
8
|
+
// cause a thrown error. See: https://github.com/siimon/prom-client/issues/298
|
|
5
9
|
const commonLabels = [
|
|
6
10
|
'queueName',
|
|
7
11
|
'userAgent',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"describe.js","sourceRoot":"","sources":["../../../src/collectors/api/describe.ts"],"names":[],"mappings":";;;AAEA,yCAA8D;
|
|
1
|
+
{"version":3,"file":"describe.js","sourceRoot":"","sources":["../../../src/collectors/api/describe.ts"],"names":[],"mappings":";;;AAEA,yCAA8D;AAE9D,4EAA4E;AAC5E,wEAAwE;AACxE,+EAA+E;AAC/E,8EAA8E;AAC9E,MAAM,YAAY,GAAG;IACpB,WAAW;IACX,WAAW;IACX,YAAY;IACZ,OAAO;IACP,YAAY;CACZ,CAAC;AAEF,IAAI,SAAS,GAAG,KAAK,CAAC;AAEf,MAAM,sBAAsB,GAAG,CAAC,OAAwB,EAAE,EAAE;IAClE,IAAI,SAAS,EAAE,CAAC;QACf,OAAO;IACR,CAAC;IACD,SAAS,GAAG,IAAI,CAAC;IAEjB,OAAO,CAAC,QAAQ,CAAC,OAAO,CACvB,mBAAmB,EACnB,+BAA+B,EAC/B;QACC,UAAU,EAAE,CAAC,GAAG,YAAY,CAAC;KAC7B,CACD,CAAC;IAEF,OAAO,CAAC,QAAQ,CAAC,SAAS,CACzB,gBAAgB,EAChB,wDAAwD,EACxD;QACC,OAAO,EAAE,uBAAc;QACvB,UAAU,EAAE,CAAC,GAAG,YAAY,CAAC;KAC7B,CACD,CAAC;IAEF,OAAO,CAAC,QAAQ,CAAC,SAAS,CACzB,mBAAmB,EACnB,2DAA2D,EAC3D;QACC,OAAO,EAAE,uBAAc;QACvB,UAAU,EAAE,CAAC,GAAG,YAAY,CAAC;KAC7B,CACD,CAAC;IAEF,OAAO,CAAC,QAAQ,CAAC,SAAS,CACzB,qBAAqB,EACrB,yEAAyE,EACzE;QACC,OAAO,EAAE,uBAAc;QACvB,UAAU,EAAE,CAAC,GAAG,YAAY,CAAC;KAC7B,CACD,CAAC;AACH,CAAC,CAAC;AAxCW,QAAA,sBAAsB,0BAwCjC"}
|
package/out/config.js
CHANGED
|
@@ -3,6 +3,10 @@ var _a, _b, _c, _d;
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.bytesRWBuckets = exports.latencyBuckets = void 0;
|
|
5
5
|
const prom_client_1 = require("prom-client");
|
|
6
|
+
// from 4 ms up to ~65 seconds, sqrt2 factor
|
|
7
|
+
// allows specification via env-var as comma-separated values
|
|
6
8
|
exports.latencyBuckets = (_b = (_a = process.env['NODE_METRICS_GATHERER_LATENCY_BUCKETS']) === null || _a === void 0 ? void 0 : _a.split(',').map((s) => parseInt(s, 10))) !== null && _b !== void 0 ? _b : (0, prom_client_1.exponentialBuckets)(0.004, Math.SQRT2, 29).map(Math.round);
|
|
9
|
+
// from 256 bytes up to 4GB, sqrt2 factor
|
|
10
|
+
// allows specification via env-var as comma-separated values
|
|
7
11
|
exports.bytesRWBuckets = (_d = (_c = process.env['NODE_METRICS_GATHERER_BYTES_RW_BUCKETS']) === null || _c === void 0 ? void 0 : _c.split(',').map((s) => parseInt(s, 10))) !== null && _d !== void 0 ? _d : (0, prom_client_1.exponentialBuckets)(256, Math.SQRT2, 49).map(Math.round);
|
|
8
12
|
//# sourceMappingURL=config.js.map
|
package/out/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;AAAA,6CAAiD;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;AAAA,6CAAiD;AAEjD,4CAA4C;AAC5C,6DAA6D;AAChD,QAAA,cAAc,GAC1B,MAAA,MAAA,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,0CACjD,KAAK,CAAC,GAAG,EACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,mCAC7B,IAAA,gCAAkB,EAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAE3D,yCAAyC;AACzC,6DAA6D;AAChD,QAAA,cAAc,GAC1B,MAAA,MAAA,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,0CAClD,KAAK,CAAC,GAAG,EACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,mCAC7B,IAAA,gCAAkB,EAAC,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC"}
|
package/out/enums.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AggregatorStrategy = void 0;
|
|
4
|
+
// see: https://github.com/siimon/prom-client#usage-with-nodejss-cluster-module
|
|
4
5
|
var AggregatorStrategy;
|
|
5
6
|
(function (AggregatorStrategy) {
|
|
6
7
|
AggregatorStrategy["SUM"] = "sum";
|
package/out/enums.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enums.js","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"enums.js","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":";;;AAAA,+EAA+E;AAC/E,IAAY,kBAOX;AAPD,WAAY,kBAAkB;IAC7B,iCAAW,CAAA;IACX,qCAAe,CAAA;IACf,iCAAW,CAAA;IACX,iCAAW,CAAA;IACX,yCAAmB,CAAA;IACnB,mCAAa,CAAA;AACd,CAAC,EAPW,kBAAkB,kCAAlB,kBAAkB,QAO7B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import prometheus from 'prom-client';
|
|
3
3
|
import { TypedError } from 'typed-error';
|
|
4
4
|
import type { AuthTestFunc, CustomParams, LabelSet, MetricsMetaMap } from './types';
|
|
5
5
|
export declare class MetricsGathererError extends TypedError {
|
|
@@ -30,6 +30,11 @@ export declare class MetricsGatherer {
|
|
|
30
30
|
reset(name?: string): void;
|
|
31
31
|
exportOn(port: number, path?: string, requestHandler?: express.Handler): void;
|
|
32
32
|
requestHandler(authTest?: AuthTestFunc): express.Handler;
|
|
33
|
+
/**
|
|
34
|
+
* Create an express request handler given an auth test function which is suitable
|
|
35
|
+
* for use in a context where we're using node's `cluster` module.
|
|
36
|
+
* Note: This *must* be paired with an `aggregateRequestWorker()` call on all workers
|
|
37
|
+
*/
|
|
33
38
|
aggregateRequestHandler(authTest?: AuthTestFunc): express.Handler;
|
|
34
39
|
aggregateRequestWorker(): void;
|
|
35
40
|
collectDefaultMetrics(): void;
|
package/out/metrics-gatherer.js
CHANGED
|
@@ -8,27 +8,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.MetricsGatherer = exports.MetricsGathererError = void 0;
|
|
13
|
-
const
|
|
14
|
-
const
|
|
16
|
+
const express_1 = __importDefault(require("express"));
|
|
17
|
+
const prom_client_1 = __importDefault(require("prom-client"));
|
|
15
18
|
const typed_error_1 = require("typed-error");
|
|
16
|
-
const
|
|
17
|
-
const debug =
|
|
19
|
+
const debug_1 = __importDefault(require("debug"));
|
|
20
|
+
const debug = (0, debug_1.default)('node-metrics-gatherer');
|
|
18
21
|
const collect_1 = require("./collectors/api/collect");
|
|
19
22
|
const types_1 = require("./types");
|
|
20
23
|
class MetricsGathererError extends typed_error_1.TypedError {
|
|
21
24
|
}
|
|
22
25
|
exports.MetricsGathererError = MetricsGathererError;
|
|
23
26
|
const constructors = {
|
|
24
|
-
gauge: new types_1.MetricConstructor(
|
|
25
|
-
counter: new types_1.MetricConstructor(
|
|
26
|
-
summary: new types_1.MetricConstructor(
|
|
27
|
-
histogram: new types_1.MetricConstructor(
|
|
27
|
+
gauge: new types_1.MetricConstructor(prom_client_1.default.Gauge),
|
|
28
|
+
counter: new types_1.MetricConstructor(prom_client_1.default.Counter),
|
|
29
|
+
summary: new types_1.MetricConstructor(prom_client_1.default.Summary),
|
|
30
|
+
histogram: new types_1.MetricConstructor(prom_client_1.default.Histogram),
|
|
28
31
|
};
|
|
29
32
|
class MetricsGatherer {
|
|
30
33
|
constructor() {
|
|
31
|
-
this.client =
|
|
34
|
+
this.client = prom_client_1.default;
|
|
32
35
|
this.initState();
|
|
33
36
|
this.setupDescribe();
|
|
34
37
|
}
|
|
@@ -64,6 +67,7 @@ class MetricsGatherer {
|
|
|
64
67
|
};
|
|
65
68
|
}
|
|
66
69
|
}
|
|
70
|
+
// observe a gauge metric
|
|
67
71
|
gauge(name, val, labels = {}) {
|
|
68
72
|
try {
|
|
69
73
|
this.ensureExists('gauge', name, labels);
|
|
@@ -73,9 +77,13 @@ class MetricsGatherer {
|
|
|
73
77
|
this.err(e);
|
|
74
78
|
}
|
|
75
79
|
}
|
|
80
|
+
// increment a counter or gauge
|
|
76
81
|
inc(name, val = 1, labels = {}) {
|
|
77
82
|
var _a, _b;
|
|
78
83
|
try {
|
|
84
|
+
// ensure either that this metric already exists, or if not
|
|
85
|
+
// create either a counter if `_total` suffix is found, or
|
|
86
|
+
// a gauge otherwise
|
|
79
87
|
const kind = (_b = (_a = this.meta[name]) === null || _a === void 0 ? void 0 : _a.kind) !== null && _b !== void 0 ? _b : (name.endsWith('_total') ? 'counter' : 'gauge');
|
|
80
88
|
this.ensureExists(kind, name, labels);
|
|
81
89
|
if (!this.checkMetricType(name, ['gauge', 'counter'])) {
|
|
@@ -92,8 +100,10 @@ class MetricsGatherer {
|
|
|
92
100
|
this.err(e);
|
|
93
101
|
}
|
|
94
102
|
}
|
|
103
|
+
// decrement a gauge
|
|
95
104
|
dec(name, val = 1, labels = {}) {
|
|
96
105
|
try {
|
|
106
|
+
// ensure either that this metric already exists, or if not, create a gauge
|
|
97
107
|
this.ensureExists('gauge', name, labels);
|
|
98
108
|
if (!this.checkMetricType(name, ['gauge'])) {
|
|
99
109
|
throw new MetricsGathererError(`Tried to decrement non-gauge metric ${name}`);
|
|
@@ -104,6 +114,7 @@ class MetricsGatherer {
|
|
|
104
114
|
this.err(e);
|
|
105
115
|
}
|
|
106
116
|
}
|
|
117
|
+
// observe a counter metric
|
|
107
118
|
counter(name, val = 1, labels = {}) {
|
|
108
119
|
try {
|
|
109
120
|
this.ensureExists('counter', name, labels);
|
|
@@ -113,6 +124,7 @@ class MetricsGatherer {
|
|
|
113
124
|
this.err(e);
|
|
114
125
|
}
|
|
115
126
|
}
|
|
127
|
+
// observe a summary metric
|
|
116
128
|
summary(name, val, labels = {}, customParams = {}) {
|
|
117
129
|
try {
|
|
118
130
|
this.ensureExists('summary', name, labels, customParams);
|
|
@@ -122,6 +134,7 @@ class MetricsGatherer {
|
|
|
122
134
|
this.err(e);
|
|
123
135
|
}
|
|
124
136
|
}
|
|
137
|
+
// observe a histogram metric
|
|
125
138
|
histogram(name, val, labels = {}, customParams = {}) {
|
|
126
139
|
try {
|
|
127
140
|
this.ensureExists('histogram', name, labels, customParams);
|
|
@@ -131,6 +144,7 @@ class MetricsGatherer {
|
|
|
131
144
|
this.err(e);
|
|
132
145
|
}
|
|
133
146
|
}
|
|
147
|
+
// observe both a histogram and a summary, adding suffixes to differentiate
|
|
134
148
|
histogramSummary(name, val, labels = {}) {
|
|
135
149
|
try {
|
|
136
150
|
this.histogram(`${name}_hist`, val, labels);
|
|
@@ -140,6 +154,7 @@ class MetricsGatherer {
|
|
|
140
154
|
this.err(e);
|
|
141
155
|
}
|
|
142
156
|
}
|
|
157
|
+
// check that a metric is of the given type(s)
|
|
143
158
|
checkMetricType(name, kinds) {
|
|
144
159
|
try {
|
|
145
160
|
return kinds.includes(this.meta[name].kind);
|
|
@@ -156,23 +171,29 @@ class MetricsGatherer {
|
|
|
156
171
|
exists(name) {
|
|
157
172
|
return this.getMetric(name) != null;
|
|
158
173
|
}
|
|
174
|
+
// used declaratively to ensure a given metric of a certain kind exists
|
|
159
175
|
ensureExists(kind, name, labels = {}, customParams = {}) {
|
|
176
|
+
// if exists, bail early
|
|
160
177
|
if (this.metrics[kind][name] != null) {
|
|
161
178
|
return;
|
|
162
179
|
}
|
|
180
|
+
// if no meta, describe by default to satisfy prometheus
|
|
163
181
|
if (!this.meta[name]) {
|
|
164
182
|
this.describe[kind](name, `undescribed ${kind} metric`, Object.assign({ labelNames: Object.keys(labels) }, customParams));
|
|
165
183
|
}
|
|
166
184
|
else if (this.meta[name].kind !== kind) {
|
|
185
|
+
// if name already associated with another kind, throw error
|
|
167
186
|
throw new MetricsGathererError(`tried to use ${name} twice - first as ` +
|
|
168
187
|
`${this.meta[name].kind}, then as ${kind}`);
|
|
169
188
|
}
|
|
189
|
+
// create prometheus.Metric instance
|
|
170
190
|
this.metrics[kind][name] = constructors[kind].create(Object.assign(Object.assign({ name, help: this.meta[name].help, labelNames: Object.keys(labels) }, customParams), this.meta[name].customParams));
|
|
171
191
|
}
|
|
192
|
+
// reset the metrics or only a given metric if name supplied
|
|
172
193
|
reset(name) {
|
|
173
194
|
try {
|
|
174
195
|
if (!name) {
|
|
175
|
-
|
|
196
|
+
prom_client_1.default.register.resetMetrics();
|
|
176
197
|
}
|
|
177
198
|
else {
|
|
178
199
|
const metric = this.getMetric(name);
|
|
@@ -185,22 +206,30 @@ class MetricsGatherer {
|
|
|
185
206
|
this.err(e);
|
|
186
207
|
}
|
|
187
208
|
}
|
|
209
|
+
// create an express app listening on a given port, responding with the given
|
|
210
|
+
// requesthandler
|
|
188
211
|
exportOn(port, path = '/metrics', requestHandler) {
|
|
189
|
-
const app =
|
|
212
|
+
const app = (0, express_1.default)();
|
|
190
213
|
app.use(path, requestHandler !== null && requestHandler !== void 0 ? requestHandler : this.requestHandler());
|
|
191
214
|
app.listen(port);
|
|
192
215
|
}
|
|
216
|
+
// create an express request handler given an auth test function
|
|
193
217
|
requestHandler(authTest) {
|
|
194
218
|
return (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
195
219
|
if (authTest && !authTest(req)) {
|
|
196
220
|
return res.status(403).send();
|
|
197
221
|
}
|
|
198
222
|
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
199
|
-
res.end(yield
|
|
223
|
+
res.end(yield prom_client_1.default.register.metrics());
|
|
200
224
|
});
|
|
201
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Create an express request handler given an auth test function which is suitable
|
|
228
|
+
* for use in a context where we're using node's `cluster` module.
|
|
229
|
+
* Note: This *must* be paired with an `aggregateRequestWorker()` call on all workers
|
|
230
|
+
*/
|
|
202
231
|
aggregateRequestHandler(authTest) {
|
|
203
|
-
const aggregatorRegistry = new
|
|
232
|
+
const aggregatorRegistry = new prom_client_1.default.AggregatorRegistry();
|
|
204
233
|
return (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
205
234
|
if (authTest && !authTest(req)) {
|
|
206
235
|
return res.status(403).send();
|
|
@@ -217,19 +246,24 @@ class MetricsGatherer {
|
|
|
217
246
|
});
|
|
218
247
|
}
|
|
219
248
|
aggregateRequestWorker() {
|
|
220
|
-
|
|
249
|
+
// Ensure the worker listener is registered by instantiating the class
|
|
250
|
+
// tslint:disable-next-line:no-unused-expression-chai
|
|
251
|
+
new prom_client_1.default.AggregatorRegistry();
|
|
221
252
|
}
|
|
253
|
+
// collect default metrics (underlying prom-client)
|
|
222
254
|
collectDefaultMetrics() {
|
|
223
|
-
|
|
255
|
+
prom_client_1.default.collectDefaultMetrics();
|
|
224
256
|
}
|
|
257
|
+
// collect generic API metrics given an express app
|
|
225
258
|
collectAPIMetrics(app) {
|
|
226
259
|
app.use((0, collect_1.collectAPIMetrics)(this));
|
|
227
260
|
return app;
|
|
228
261
|
}
|
|
262
|
+
// get the prometheus output
|
|
229
263
|
output() {
|
|
230
264
|
return __awaiter(this, void 0, void 0, function* () {
|
|
231
265
|
try {
|
|
232
|
-
return yield
|
|
266
|
+
return yield prom_client_1.default.register.metrics();
|
|
233
267
|
}
|
|
234
268
|
catch (e) {
|
|
235
269
|
this.err(e);
|
|
@@ -237,9 +271,10 @@ class MetricsGatherer {
|
|
|
237
271
|
}
|
|
238
272
|
});
|
|
239
273
|
}
|
|
274
|
+
// clear all metrics
|
|
240
275
|
clear() {
|
|
241
276
|
try {
|
|
242
|
-
|
|
277
|
+
prom_client_1.default.register.clear();
|
|
243
278
|
this.initState();
|
|
244
279
|
}
|
|
245
280
|
catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics-gatherer.js","sourceRoot":"","sources":["../src/metrics-gatherer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"metrics-gatherer.js","sourceRoot":"","sources":["../src/metrics-gatherer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAA8B;AAC9B,8DAAqC;AACrC,6CAAyC;AAEzC,kDAA0B;AAC1B,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,uBAAuB,CAAC,CAAC;AAE7C,sDAA6D;AAU7D,mCAA4C;AAE5C,MAAa,oBAAqB,SAAQ,wBAAU;CAAG;AAAvD,oDAAuD;AAEvD,MAAM,YAAY,GAAG;IACpB,KAAK,EAAE,IAAI,yBAAiB,CAAC,qBAAU,CAAC,KAAK,CAAC;IAC9C,OAAO,EAAE,IAAI,yBAAiB,CAAC,qBAAU,CAAC,OAAO,CAAC;IAClD,OAAO,EAAE,IAAI,yBAAiB,CAAC,qBAAU,CAAC,OAAO,CAAC;IAClD,SAAS,EAAE,IAAI,yBAAiB,CAAC,qBAAU,CAAC,SAAS,CAAC;CACtD,CAAC;AAUF,MAAa,eAAe;IAO3B;QAFO,WAAM,GAAG,qBAAU,CAAC;QAG1B,IAAI,CAAC,SAAS,EAAE,CAAC;QACjB,IAAI,CAAC,aAAa,EAAE,CAAC;IACtB,CAAC;IAEO,SAAS;QAChB,IAAI,CAAC;YACJ,IAAI,CAAC,OAAO,GAAG;gBACd,KAAK,EAAE,EAAE;gBACT,OAAO,EAAE,EAAE;gBACX,SAAS,EAAE,EAAE;gBACb,OAAO,EAAE,EAAE;aACX,CAAC;YACF,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;YACf,IAAI,CAAC,kBAAkB,GAAG,CAAC,CAAC;QAC7B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACb,CAAC;IACF,CAAC;I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"}
|
package/out/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
1
|
+
import type express from 'express';
|
|
2
|
+
import type prometheus from 'prom-client';
|
|
3
3
|
import type { AggregatorStrategy } from './enums';
|
|
4
4
|
export interface LabelSet {
|
|
5
5
|
[name: string]: string;
|
package/out/types.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MetricConstructor = void 0;
|
|
4
|
+
// weird class to allow polymorphism over constructors yielding type Metric
|
|
4
5
|
class MetricConstructor {
|
|
5
6
|
constructor(construct) {
|
|
6
7
|
this.construct = construct;
|
package/out/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAeA,2EAA2E;AAC3E,MAAa,iBAAiB;IAI7B,YAAmB,SAAmD;QAAnD,cAAS,GAAT,SAAS,CAA0C;IAAG,CAAC;IACnE,MAAM,CAAC,GAAG,IAAO;QACvB,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC;IACpC,CAAC;CACD;AARD,8CAQC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@balena/node-metrics-gatherer",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.2",
|
|
4
4
|
"description": "gather / export prometheus metrics easily in nodejs",
|
|
5
5
|
"main": "out/index.js",
|
|
6
|
+
"type": "commonjs",
|
|
6
7
|
"types": "out/index.d.ts",
|
|
7
8
|
"scripts": {
|
|
8
9
|
"test": "npm run lint && npm run prepare && mocha --exit -r ts-node/register/transpile-only test/*.spec.ts",
|
|
@@ -41,6 +42,6 @@
|
|
|
41
42
|
"typescript": "^5.9.3"
|
|
42
43
|
},
|
|
43
44
|
"versionist": {
|
|
44
|
-
"publishedAt": "2025-
|
|
45
|
+
"publishedAt": "2025-11-26T16:27:56.982Z"
|
|
45
46
|
}
|
|
46
47
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NextFunction, Request, Response } from 'express';
|
|
2
|
-
import
|
|
2
|
+
import onFinished from 'on-finished';
|
|
3
3
|
|
|
4
4
|
import type { MetricsGatherer } from '../../metrics-gatherer';
|
|
5
5
|
import { describeAPIMetricsOnce } from './describe';
|
package/src/metrics-gatherer.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import prometheus from 'prom-client';
|
|
3
3
|
import { TypedError } from 'typed-error';
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import Debug from 'debug';
|
|
6
6
|
const debug = Debug('node-metrics-gatherer');
|
|
7
7
|
|
|
8
8
|
import { collectAPIMetrics } from './collectors/api/collect';
|
package/src/types.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// TODO
|
|
2
|
-
import
|
|
2
|
+
import chai from 'chai';
|
|
3
3
|
import { expect } from 'chai';
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
5
5
|
import chaiHttp = require('chai-http');
|
|
6
6
|
import 'mocha';
|
|
7
7
|
|
|
8
8
|
import { json } from 'body-parser';
|
|
9
|
-
import
|
|
9
|
+
import express from 'express';
|
|
10
10
|
|
|
11
11
|
import { metrics } from '../src';
|
|
12
12
|
|
package/tsconfig.json
CHANGED
|
@@ -2,21 +2,16 @@
|
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"declaration": true,
|
|
4
4
|
"outDir": "out",
|
|
5
|
-
"module": "
|
|
5
|
+
"module": "node18",
|
|
6
6
|
"target": "es2015",
|
|
7
7
|
"strict": true,
|
|
8
8
|
"strictPropertyInitialization": false,
|
|
9
9
|
"noUnusedParameters": true,
|
|
10
10
|
"noUnusedLocals": true,
|
|
11
11
|
"preserveConstEnums": true,
|
|
12
|
-
"removeComments": true,
|
|
13
12
|
"resolveJsonModule": true,
|
|
14
13
|
"sourceMap": true,
|
|
15
|
-
"skipLibCheck": true
|
|
16
|
-
"lib": [
|
|
17
|
-
"es7",
|
|
18
|
-
"dom"
|
|
19
|
-
]
|
|
14
|
+
"skipLibCheck": true
|
|
20
15
|
},
|
|
21
16
|
"include": [
|
|
22
17
|
"src/**/*.ts",
|