@promster/undici 15.0.1 → 15.1.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.
@@ -1 +1 @@
1
- export { createPoolMetricsExporter, addObservedPool } from "./pool-metrics.js";
1
+ export { createPoolMetricsExporter, addObservedPool, supportedPoolStats, } from "./pool-metrics.js";
@@ -12,5 +12,6 @@ export declare class ObservedPools {
12
12
  [Symbol.iterator](): IterableIterator<[string, Pool]>;
13
13
  }
14
14
  declare function addObservedPool(origin: string, pool: Pool): void;
15
+ declare const supportedPoolStats: string[];
15
16
  declare function createPoolMetricsExporter(initialPools?: Record<string, Pool>, options?: TPoolsMetricsExporterOptions): void;
16
- export { createPoolMetricsExporter, addObservedPool, type TPoolsMetricsExporterOptions, };
17
+ export { createPoolMetricsExporter, supportedPoolStats, addObservedPool, type TPoolsMetricsExporterOptions, };
@@ -36,34 +36,37 @@ const observedPools = new ObservedPools();
36
36
  function addObservedPool(origin, pool) {
37
37
  observedPools.add(origin, pool);
38
38
  }
39
+ const supportedPoolStats = ['connected', 'free', 'pending', 'queued', 'running', 'size'];
39
40
  function createPoolMetricsExporter(initialPools, options) {
40
41
  var _options$metricPrefix;
41
- const metricName = `${(_options$metricPrefix = options === null || options === void 0 ? void 0 : options.metricPrefix) !== null && _options$metricPrefix !== void 0 ? _options$metricPrefix : ''}nodejs_undici_pool_stats`;
42
+ const metricName = `${(_options$metricPrefix = options === null || options === void 0 ? void 0 : options.metricPrefix) !== null && _options$metricPrefix !== void 0 ? _options$metricPrefix : ''}nodejs_undici_pool`;
42
43
  if (initialPools) {
43
44
  observedPools.addMany(initialPools);
44
45
  }
45
- new metrics.Prometheus.Gauge({
46
- name: metricName,
47
- help: 'Statistics for Undici connection pools. See https://github.com/nodejs/undici/blob/main/docs/docs/api/PoolStats.md',
48
- labelNames: ['origin', 'stat_name'],
49
- registers: [metrics.defaultRegister],
50
- collect() {
51
- for (const [origin, pool] of observedPools) {
52
- const stats = pool.stats;
46
+ for (const supportedStat of supportedPoolStats) {
47
+ new metrics.Prometheus.Gauge({
48
+ name: `${metricName}_${supportedStat}`,
49
+ help: `Statistics for Undici connection pools ${supportedStat} stat. See https://github.com/nodejs/undici/blob/main/docs/docs/api/PoolStats.md`,
50
+ labelNames: ['origin'],
51
+ registers: [metrics.defaultRegister],
52
+ collect() {
53
+ for (const [origin, pool] of observedPools) {
54
+ const stats = pool.stats;
53
55
 
54
- // If the pool has made no requests, it will not have stats
55
- if (!stats) {
56
- continue;
57
- }
58
- for (const [statName, value] of Object.entries(stats)) {
59
- if (typeof value === 'number' && !Number.isNaN(value)) {
60
- this.labels(origin, statName).set(value);
56
+ // If the pool has made no requests, it will not have stats
57
+ if (!stats) {
58
+ continue;
59
+ }
60
+ const statValue = stats[supportedStat];
61
+ if (typeof statValue === 'number' && !Number.isNaN(statValue)) {
62
+ this.labels(origin).set(statValue);
61
63
  }
62
64
  }
63
65
  }
64
- }
65
- });
66
+ });
67
+ }
66
68
  }
67
69
 
68
70
  exports.addObservedPool = addObservedPool;
69
71
  exports.createPoolMetricsExporter = createPoolMetricsExporter;
72
+ exports.supportedPoolStats = supportedPoolStats;
@@ -36,34 +36,37 @@ const observedPools = new ObservedPools();
36
36
  function addObservedPool(origin, pool) {
37
37
  observedPools.add(origin, pool);
38
38
  }
39
+ const supportedPoolStats = ['connected', 'free', 'pending', 'queued', 'running', 'size'];
39
40
  function createPoolMetricsExporter(initialPools, options) {
40
41
  var _options$metricPrefix;
41
- const metricName = `${(_options$metricPrefix = options === null || options === void 0 ? void 0 : options.metricPrefix) !== null && _options$metricPrefix !== void 0 ? _options$metricPrefix : ''}nodejs_undici_pool_stats`;
42
+ const metricName = `${(_options$metricPrefix = options === null || options === void 0 ? void 0 : options.metricPrefix) !== null && _options$metricPrefix !== void 0 ? _options$metricPrefix : ''}nodejs_undici_pool`;
42
43
  if (initialPools) {
43
44
  observedPools.addMany(initialPools);
44
45
  }
45
- new metrics.Prometheus.Gauge({
46
- name: metricName,
47
- help: 'Statistics for Undici connection pools. See https://github.com/nodejs/undici/blob/main/docs/docs/api/PoolStats.md',
48
- labelNames: ['origin', 'stat_name'],
49
- registers: [metrics.defaultRegister],
50
- collect() {
51
- for (const [origin, pool] of observedPools) {
52
- const stats = pool.stats;
46
+ for (const supportedStat of supportedPoolStats) {
47
+ new metrics.Prometheus.Gauge({
48
+ name: `${metricName}_${supportedStat}`,
49
+ help: `Statistics for Undici connection pools ${supportedStat} stat. See https://github.com/nodejs/undici/blob/main/docs/docs/api/PoolStats.md`,
50
+ labelNames: ['origin'],
51
+ registers: [metrics.defaultRegister],
52
+ collect() {
53
+ for (const [origin, pool] of observedPools) {
54
+ const stats = pool.stats;
53
55
 
54
- // If the pool has made no requests, it will not have stats
55
- if (!stats) {
56
- continue;
57
- }
58
- for (const [statName, value] of Object.entries(stats)) {
59
- if (typeof value === 'number' && !Number.isNaN(value)) {
60
- this.labels(origin, statName).set(value);
56
+ // If the pool has made no requests, it will not have stats
57
+ if (!stats) {
58
+ continue;
59
+ }
60
+ const statValue = stats[supportedStat];
61
+ if (typeof statValue === 'number' && !Number.isNaN(statValue)) {
62
+ this.labels(origin).set(statValue);
61
63
  }
62
64
  }
63
65
  }
64
- }
65
- });
66
+ });
67
+ }
66
68
  }
67
69
 
68
70
  exports.addObservedPool = addObservedPool;
69
71
  exports.createPoolMetricsExporter = createPoolMetricsExporter;
72
+ exports.supportedPoolStats = supportedPoolStats;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promster/undici",
3
- "version": "15.0.1",
3
+ "version": "15.1.0",
4
4
  "description": "Undici server integrations of promster",
5
5
  "main": "dist/promster-undici.cjs.js",
6
6
  "typings": "dist/promster-undici.cjs.d.ts",
@@ -39,8 +39,8 @@
39
39
  "dependencies": {
40
40
  "merge-options": "3.0.4",
41
41
  "tslib": "2.6.3",
42
- "@promster/metrics": "15.0.1",
43
- "@promster/types": "15.0.1"
42
+ "@promster/metrics": "15.1.0",
43
+ "@promster/types": "15.1.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/node": "20.16.13",
@@ -49,8 +49,8 @@
49
49
  "parse-prometheus-text-format": "1.1.1",
50
50
  "undici": "7.7.0",
51
51
  "express": "4.21.2",
52
- "@promster/server": "15.0.1",
53
- "@promster/express": "15.0.1"
52
+ "@promster/server": "15.1.0",
53
+ "@promster/express": "15.1.0"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "prom-client": "13.x.x || 14.x || 15.x",