@promster/undici 15.0.0
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/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/pool-metrics.d.ts +16 -0
- package/dist/promster-undici.cjs.d.ts +2 -0
- package/dist/promster-undici.cjs.dev.js +64 -0
- package/dist/promster-undici.cjs.js +7 -0
- package/dist/promster-undici.cjs.prod.js +64 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 suǝʞǝǝpʇ
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<b style="font-size: 25px">⏰ Promster - Measure undici pool stats with Prometheus 🚦</b>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
### `@promster/undici`
|
|
6
|
+
|
|
7
|
+
This repository is part of the `promster` mono repository. Please head [here](https://github.com/tdeekens/promster) for more information.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createPoolMetricsExporter, observedPools } from "./pool-metrics.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Pool } from 'undici';
|
|
2
|
+
type TPoolsMetricsExporterOptions = {
|
|
3
|
+
metricPrefix?: string;
|
|
4
|
+
};
|
|
5
|
+
export declare class ObservedPools {
|
|
6
|
+
private pools;
|
|
7
|
+
constructor(initialPools?: Record<string, Pool>);
|
|
8
|
+
add(origin: string, pool: Pool): void;
|
|
9
|
+
addMany(pools: Record<string, Pool>): void;
|
|
10
|
+
remove(origin: string): boolean;
|
|
11
|
+
get(origin: string): Pool | undefined;
|
|
12
|
+
[Symbol.iterator](): IterableIterator<[string, Pool]>;
|
|
13
|
+
}
|
|
14
|
+
declare const observedPools: ObservedPools;
|
|
15
|
+
declare function createPoolMetricsExporter(pools: Record<string, Pool>, options?: TPoolsMetricsExporterOptions): void;
|
|
16
|
+
export { createPoolMetricsExporter, observedPools, type TPoolsMetricsExporterOptions, };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export * from "./declarations/src/index.js";
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvbXN0ZXItdW5kaWNpLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi9kZWNsYXJhdGlvbnMvc3JjL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var metrics = require('@promster/metrics');
|
|
6
|
+
|
|
7
|
+
// Define the stats we want to expose from undici Pool.stats
|
|
8
|
+
// See: https://github.com/nodejs/undici/blob/main/docs/docs/api/PoolStats.md
|
|
9
|
+
|
|
10
|
+
class ObservedPools {
|
|
11
|
+
constructor(initialPools) {
|
|
12
|
+
this.pools = new Map();
|
|
13
|
+
if (initialPools) {
|
|
14
|
+
this.addMany(initialPools);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
add(origin, pool) {
|
|
18
|
+
this.pools.set(origin, pool);
|
|
19
|
+
}
|
|
20
|
+
addMany(pools) {
|
|
21
|
+
for (const [origin, pool] of Object.entries(pools)) {
|
|
22
|
+
this.add(origin, pool);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
remove(origin) {
|
|
26
|
+
return this.pools.delete(origin);
|
|
27
|
+
}
|
|
28
|
+
get(origin) {
|
|
29
|
+
return this.pools.get(origin);
|
|
30
|
+
}
|
|
31
|
+
[Symbol.iterator]() {
|
|
32
|
+
return this.pools.entries();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const observedPools = new ObservedPools();
|
|
36
|
+
function createPoolMetricsExporter(pools, options) {
|
|
37
|
+
var _options$metricPrefix;
|
|
38
|
+
const metricName = `${(_options$metricPrefix = options === null || options === void 0 ? void 0 : options.metricPrefix) !== null && _options$metricPrefix !== void 0 ? _options$metricPrefix : ''}nodejs_undici_pool_stats`;
|
|
39
|
+
observedPools.addMany(pools);
|
|
40
|
+
new metrics.Prometheus.Gauge({
|
|
41
|
+
name: metricName,
|
|
42
|
+
help: 'Statistics for Undici connection pools. See https://github.com/nodejs/undici/blob/main/docs/docs/api/PoolStats.md',
|
|
43
|
+
labelNames: ['origin', 'stat_name'],
|
|
44
|
+
registers: [metrics.defaultRegister],
|
|
45
|
+
collect() {
|
|
46
|
+
for (const [origin, pool] of observedPools) {
|
|
47
|
+
const stats = pool.stats;
|
|
48
|
+
|
|
49
|
+
// If the pool has made no requests, it will not have stats
|
|
50
|
+
if (!stats) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
for (const [statName, value] of Object.entries(stats)) {
|
|
54
|
+
if (typeof value === 'number' && !Number.isNaN(value)) {
|
|
55
|
+
this.labels(origin, statName).set(value);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
exports.createPoolMetricsExporter = createPoolMetricsExporter;
|
|
64
|
+
exports.observedPools = observedPools;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var metrics = require('@promster/metrics');
|
|
6
|
+
|
|
7
|
+
// Define the stats we want to expose from undici Pool.stats
|
|
8
|
+
// See: https://github.com/nodejs/undici/blob/main/docs/docs/api/PoolStats.md
|
|
9
|
+
|
|
10
|
+
class ObservedPools {
|
|
11
|
+
constructor(initialPools) {
|
|
12
|
+
this.pools = new Map();
|
|
13
|
+
if (initialPools) {
|
|
14
|
+
this.addMany(initialPools);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
add(origin, pool) {
|
|
18
|
+
this.pools.set(origin, pool);
|
|
19
|
+
}
|
|
20
|
+
addMany(pools) {
|
|
21
|
+
for (const [origin, pool] of Object.entries(pools)) {
|
|
22
|
+
this.add(origin, pool);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
remove(origin) {
|
|
26
|
+
return this.pools.delete(origin);
|
|
27
|
+
}
|
|
28
|
+
get(origin) {
|
|
29
|
+
return this.pools.get(origin);
|
|
30
|
+
}
|
|
31
|
+
[Symbol.iterator]() {
|
|
32
|
+
return this.pools.entries();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const observedPools = new ObservedPools();
|
|
36
|
+
function createPoolMetricsExporter(pools, options) {
|
|
37
|
+
var _options$metricPrefix;
|
|
38
|
+
const metricName = `${(_options$metricPrefix = options === null || options === void 0 ? void 0 : options.metricPrefix) !== null && _options$metricPrefix !== void 0 ? _options$metricPrefix : ''}nodejs_undici_pool_stats`;
|
|
39
|
+
observedPools.addMany(pools);
|
|
40
|
+
new metrics.Prometheus.Gauge({
|
|
41
|
+
name: metricName,
|
|
42
|
+
help: 'Statistics for Undici connection pools. See https://github.com/nodejs/undici/blob/main/docs/docs/api/PoolStats.md',
|
|
43
|
+
labelNames: ['origin', 'stat_name'],
|
|
44
|
+
registers: [metrics.defaultRegister],
|
|
45
|
+
collect() {
|
|
46
|
+
for (const [origin, pool] of observedPools) {
|
|
47
|
+
const stats = pool.stats;
|
|
48
|
+
|
|
49
|
+
// If the pool has made no requests, it will not have stats
|
|
50
|
+
if (!stats) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
for (const [statName, value] of Object.entries(stats)) {
|
|
54
|
+
if (typeof value === 'number' && !Number.isNaN(value)) {
|
|
55
|
+
this.labels(origin, statName).set(value);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
exports.createPoolMetricsExporter = createPoolMetricsExporter;
|
|
64
|
+
exports.observedPools = observedPools;
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@promster/undici",
|
|
3
|
+
"version": "15.0.0",
|
|
4
|
+
"description": "Undici server integrations of promster",
|
|
5
|
+
"main": "dist/promster-undici.cjs.js",
|
|
6
|
+
"typings": "dist/promster-undici.cjs.d.ts",
|
|
7
|
+
"types": "dist/promster-undici.cjs.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"readme.md",
|
|
10
|
+
"package.json",
|
|
11
|
+
"LICENSE",
|
|
12
|
+
"dist/**",
|
|
13
|
+
"modules/**"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=20",
|
|
17
|
+
"pnpm": ">=8"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/tdeekens/promster.git",
|
|
25
|
+
"directory": "packages/undici"
|
|
26
|
+
},
|
|
27
|
+
"author": "Tobias Deekens <nerd@tdeekens.name>",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/tdeekens/promster/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/tdeekens/promster#readme",
|
|
33
|
+
"keywords": [
|
|
34
|
+
"metrics",
|
|
35
|
+
"continousdelivery",
|
|
36
|
+
"prometheus",
|
|
37
|
+
"undici"
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"merge-options": "3.0.4",
|
|
41
|
+
"tslib": "2.6.3",
|
|
42
|
+
"@promster/metrics": "15.0.0",
|
|
43
|
+
"@promster/types": "15.0.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "20.16.13",
|
|
47
|
+
"prom-client": "15.1.3",
|
|
48
|
+
"typescript": "5.7.3",
|
|
49
|
+
"parse-prometheus-text-format": "1.1.1",
|
|
50
|
+
"undici": "7.7.0",
|
|
51
|
+
"express": "4.21.2",
|
|
52
|
+
"@promster/server": "15.0.0",
|
|
53
|
+
"@promster/express": "15.0.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"prom-client": "13.x.x || 14.x || 15.x",
|
|
57
|
+
"undici": "7.x.x"
|
|
58
|
+
}
|
|
59
|
+
}
|