@promster/undici 15.4.0 → 15.4.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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { addObservedAgent, createAgentMetricsExporter, supportedAgentStats, } from "./agent-metrics.js";
|
|
2
|
+
export { addObservedPool, createPoolMetricsExporter, observedPoolFactory, supportedPoolStats, } from "./pool-metrics.js";
|
|
@@ -5,6 +5,80 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var metrics = require('@promster/metrics');
|
|
6
6
|
var undici = require('undici');
|
|
7
7
|
|
|
8
|
+
class ObservedAgents {
|
|
9
|
+
constructor(initialAgents) {
|
|
10
|
+
this.agents = [];
|
|
11
|
+
if (initialAgents) {
|
|
12
|
+
this.addMany(initialAgents);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
add(agent) {
|
|
16
|
+
this.agents.push(agent);
|
|
17
|
+
return agent;
|
|
18
|
+
}
|
|
19
|
+
addMany(agents) {
|
|
20
|
+
this.agents.push(...agents);
|
|
21
|
+
}
|
|
22
|
+
remove(agent) {
|
|
23
|
+
const index = this.agents.indexOf(agent);
|
|
24
|
+
if (index !== -1) {
|
|
25
|
+
this.agents.splice(index, 1);
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
get size() {
|
|
31
|
+
return this.agents.length;
|
|
32
|
+
}
|
|
33
|
+
[Symbol.iterator]() {
|
|
34
|
+
return this.agents.values();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const observedAgents = new ObservedAgents();
|
|
38
|
+
function addObservedAgent(agent) {
|
|
39
|
+
return observedAgents.add(agent);
|
|
40
|
+
}
|
|
41
|
+
const supportedAgentStats = ['connected', 'free', 'pending', 'queued', 'running', 'size'];
|
|
42
|
+
function createAgentMetricsExporter(initialAgents, options) {
|
|
43
|
+
var _options$metricPrefix;
|
|
44
|
+
const metricName = `${(_options$metricPrefix = options === null || options === void 0 ? void 0 : options.metricPrefix) !== null && _options$metricPrefix !== void 0 ? _options$metricPrefix : ''}nodejs_undici_agent`;
|
|
45
|
+
if (initialAgents) {
|
|
46
|
+
observedAgents.addMany(initialAgents);
|
|
47
|
+
}
|
|
48
|
+
new metrics.Prometheus.Gauge({
|
|
49
|
+
name: `${metricName}s_total`,
|
|
50
|
+
help: 'Number of Undici agents.',
|
|
51
|
+
registers: [metrics.defaultRegister],
|
|
52
|
+
collect() {
|
|
53
|
+
this.set(observedAgents.size);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
for (const supportedStat of supportedAgentStats) {
|
|
57
|
+
new metrics.Prometheus.Gauge({
|
|
58
|
+
name: `${metricName}_${supportedStat}`,
|
|
59
|
+
help: `Statistics for Undici agents ${supportedStat} stat. See https://github.com/nodejs/undici/blob/main/docs/docs/api/Agent.md#agentstats`,
|
|
60
|
+
labelNames: ['origin'],
|
|
61
|
+
registers: [metrics.defaultRegister],
|
|
62
|
+
collect() {
|
|
63
|
+
for (const agent of observedAgents) {
|
|
64
|
+
// If the agent has made no requests, it will not have stats
|
|
65
|
+
if (!agent.stats) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
for (const [origin, stats] of Object.entries(agent.stats)) {
|
|
69
|
+
// Client stats do not have free property
|
|
70
|
+
// @ts-expect-error
|
|
71
|
+
const statValue = stats[supportedStat];
|
|
72
|
+
if (typeof statValue === 'number' && !Number.isNaN(statValue)) {
|
|
73
|
+
this.labels(origin).set(statValue);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
8
82
|
class ObservedPools {
|
|
9
83
|
constructor(initialPools) {
|
|
10
84
|
this.pools = new Map();
|
|
@@ -83,80 +157,6 @@ function createPoolMetricsExporter(initialPools, options) {
|
|
|
83
157
|
}
|
|
84
158
|
}
|
|
85
159
|
|
|
86
|
-
class ObservedAgents {
|
|
87
|
-
constructor(initialAgents) {
|
|
88
|
-
this.agents = [];
|
|
89
|
-
if (initialAgents) {
|
|
90
|
-
this.addMany(initialAgents);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
add(agent) {
|
|
94
|
-
this.agents.push(agent);
|
|
95
|
-
return agent;
|
|
96
|
-
}
|
|
97
|
-
addMany(agents) {
|
|
98
|
-
this.agents.push(...agents);
|
|
99
|
-
}
|
|
100
|
-
remove(agent) {
|
|
101
|
-
const index = this.agents.indexOf(agent);
|
|
102
|
-
if (index !== -1) {
|
|
103
|
-
this.agents.splice(index, 1);
|
|
104
|
-
return true;
|
|
105
|
-
}
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
get size() {
|
|
109
|
-
return this.agents.length;
|
|
110
|
-
}
|
|
111
|
-
[Symbol.iterator]() {
|
|
112
|
-
return this.agents.values();
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
const observedAgents = new ObservedAgents();
|
|
116
|
-
function addObservedAgent(agent) {
|
|
117
|
-
return observedAgents.add(agent);
|
|
118
|
-
}
|
|
119
|
-
const supportedAgentStats = ['connected', 'free', 'pending', 'queued', 'running', 'size'];
|
|
120
|
-
function createAgentMetricsExporter(initialAgents, options) {
|
|
121
|
-
var _options$metricPrefix;
|
|
122
|
-
const metricName = `${(_options$metricPrefix = options === null || options === void 0 ? void 0 : options.metricPrefix) !== null && _options$metricPrefix !== void 0 ? _options$metricPrefix : ''}nodejs_undici_agent`;
|
|
123
|
-
if (initialAgents) {
|
|
124
|
-
observedAgents.addMany(initialAgents);
|
|
125
|
-
}
|
|
126
|
-
new metrics.Prometheus.Gauge({
|
|
127
|
-
name: `${metricName}s_total`,
|
|
128
|
-
help: 'Number of Undici agents.',
|
|
129
|
-
registers: [metrics.defaultRegister],
|
|
130
|
-
collect() {
|
|
131
|
-
this.set(observedAgents.size);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
for (const supportedStat of supportedAgentStats) {
|
|
135
|
-
new metrics.Prometheus.Gauge({
|
|
136
|
-
name: `${metricName}_${supportedStat}`,
|
|
137
|
-
help: `Statistics for Undici agents ${supportedStat} stat. See https://github.com/nodejs/undici/blob/main/docs/docs/api/Agent.md#agentstats`,
|
|
138
|
-
labelNames: ['origin'],
|
|
139
|
-
registers: [metrics.defaultRegister],
|
|
140
|
-
collect() {
|
|
141
|
-
for (const agent of observedAgents) {
|
|
142
|
-
// If the agent has made no requests, it will not have stats
|
|
143
|
-
if (!agent.stats) {
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
for (const [origin, stats] of Object.entries(agent.stats)) {
|
|
147
|
-
// Client stats do not have free property
|
|
148
|
-
// @ts-expect-error
|
|
149
|
-
const statValue = stats[supportedStat];
|
|
150
|
-
if (typeof statValue === 'number' && !Number.isNaN(statValue)) {
|
|
151
|
-
this.labels(origin).set(statValue);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
160
|
exports.addObservedAgent = addObservedAgent;
|
|
161
161
|
exports.addObservedPool = addObservedPool;
|
|
162
162
|
exports.createAgentMetricsExporter = createAgentMetricsExporter;
|
|
@@ -5,6 +5,80 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var metrics = require('@promster/metrics');
|
|
6
6
|
var undici = require('undici');
|
|
7
7
|
|
|
8
|
+
class ObservedAgents {
|
|
9
|
+
constructor(initialAgents) {
|
|
10
|
+
this.agents = [];
|
|
11
|
+
if (initialAgents) {
|
|
12
|
+
this.addMany(initialAgents);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
add(agent) {
|
|
16
|
+
this.agents.push(agent);
|
|
17
|
+
return agent;
|
|
18
|
+
}
|
|
19
|
+
addMany(agents) {
|
|
20
|
+
this.agents.push(...agents);
|
|
21
|
+
}
|
|
22
|
+
remove(agent) {
|
|
23
|
+
const index = this.agents.indexOf(agent);
|
|
24
|
+
if (index !== -1) {
|
|
25
|
+
this.agents.splice(index, 1);
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
get size() {
|
|
31
|
+
return this.agents.length;
|
|
32
|
+
}
|
|
33
|
+
[Symbol.iterator]() {
|
|
34
|
+
return this.agents.values();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const observedAgents = new ObservedAgents();
|
|
38
|
+
function addObservedAgent(agent) {
|
|
39
|
+
return observedAgents.add(agent);
|
|
40
|
+
}
|
|
41
|
+
const supportedAgentStats = ['connected', 'free', 'pending', 'queued', 'running', 'size'];
|
|
42
|
+
function createAgentMetricsExporter(initialAgents, options) {
|
|
43
|
+
var _options$metricPrefix;
|
|
44
|
+
const metricName = `${(_options$metricPrefix = options === null || options === void 0 ? void 0 : options.metricPrefix) !== null && _options$metricPrefix !== void 0 ? _options$metricPrefix : ''}nodejs_undici_agent`;
|
|
45
|
+
if (initialAgents) {
|
|
46
|
+
observedAgents.addMany(initialAgents);
|
|
47
|
+
}
|
|
48
|
+
new metrics.Prometheus.Gauge({
|
|
49
|
+
name: `${metricName}s_total`,
|
|
50
|
+
help: 'Number of Undici agents.',
|
|
51
|
+
registers: [metrics.defaultRegister],
|
|
52
|
+
collect() {
|
|
53
|
+
this.set(observedAgents.size);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
for (const supportedStat of supportedAgentStats) {
|
|
57
|
+
new metrics.Prometheus.Gauge({
|
|
58
|
+
name: `${metricName}_${supportedStat}`,
|
|
59
|
+
help: `Statistics for Undici agents ${supportedStat} stat. See https://github.com/nodejs/undici/blob/main/docs/docs/api/Agent.md#agentstats`,
|
|
60
|
+
labelNames: ['origin'],
|
|
61
|
+
registers: [metrics.defaultRegister],
|
|
62
|
+
collect() {
|
|
63
|
+
for (const agent of observedAgents) {
|
|
64
|
+
// If the agent has made no requests, it will not have stats
|
|
65
|
+
if (!agent.stats) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
for (const [origin, stats] of Object.entries(agent.stats)) {
|
|
69
|
+
// Client stats do not have free property
|
|
70
|
+
// @ts-expect-error
|
|
71
|
+
const statValue = stats[supportedStat];
|
|
72
|
+
if (typeof statValue === 'number' && !Number.isNaN(statValue)) {
|
|
73
|
+
this.labels(origin).set(statValue);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
8
82
|
class ObservedPools {
|
|
9
83
|
constructor(initialPools) {
|
|
10
84
|
this.pools = new Map();
|
|
@@ -83,80 +157,6 @@ function createPoolMetricsExporter(initialPools, options) {
|
|
|
83
157
|
}
|
|
84
158
|
}
|
|
85
159
|
|
|
86
|
-
class ObservedAgents {
|
|
87
|
-
constructor(initialAgents) {
|
|
88
|
-
this.agents = [];
|
|
89
|
-
if (initialAgents) {
|
|
90
|
-
this.addMany(initialAgents);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
add(agent) {
|
|
94
|
-
this.agents.push(agent);
|
|
95
|
-
return agent;
|
|
96
|
-
}
|
|
97
|
-
addMany(agents) {
|
|
98
|
-
this.agents.push(...agents);
|
|
99
|
-
}
|
|
100
|
-
remove(agent) {
|
|
101
|
-
const index = this.agents.indexOf(agent);
|
|
102
|
-
if (index !== -1) {
|
|
103
|
-
this.agents.splice(index, 1);
|
|
104
|
-
return true;
|
|
105
|
-
}
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
get size() {
|
|
109
|
-
return this.agents.length;
|
|
110
|
-
}
|
|
111
|
-
[Symbol.iterator]() {
|
|
112
|
-
return this.agents.values();
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
const observedAgents = new ObservedAgents();
|
|
116
|
-
function addObservedAgent(agent) {
|
|
117
|
-
return observedAgents.add(agent);
|
|
118
|
-
}
|
|
119
|
-
const supportedAgentStats = ['connected', 'free', 'pending', 'queued', 'running', 'size'];
|
|
120
|
-
function createAgentMetricsExporter(initialAgents, options) {
|
|
121
|
-
var _options$metricPrefix;
|
|
122
|
-
const metricName = `${(_options$metricPrefix = options === null || options === void 0 ? void 0 : options.metricPrefix) !== null && _options$metricPrefix !== void 0 ? _options$metricPrefix : ''}nodejs_undici_agent`;
|
|
123
|
-
if (initialAgents) {
|
|
124
|
-
observedAgents.addMany(initialAgents);
|
|
125
|
-
}
|
|
126
|
-
new metrics.Prometheus.Gauge({
|
|
127
|
-
name: `${metricName}s_total`,
|
|
128
|
-
help: 'Number of Undici agents.',
|
|
129
|
-
registers: [metrics.defaultRegister],
|
|
130
|
-
collect() {
|
|
131
|
-
this.set(observedAgents.size);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
for (const supportedStat of supportedAgentStats) {
|
|
135
|
-
new metrics.Prometheus.Gauge({
|
|
136
|
-
name: `${metricName}_${supportedStat}`,
|
|
137
|
-
help: `Statistics for Undici agents ${supportedStat} stat. See https://github.com/nodejs/undici/blob/main/docs/docs/api/Agent.md#agentstats`,
|
|
138
|
-
labelNames: ['origin'],
|
|
139
|
-
registers: [metrics.defaultRegister],
|
|
140
|
-
collect() {
|
|
141
|
-
for (const agent of observedAgents) {
|
|
142
|
-
// If the agent has made no requests, it will not have stats
|
|
143
|
-
if (!agent.stats) {
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
for (const [origin, stats] of Object.entries(agent.stats)) {
|
|
147
|
-
// Client stats do not have free property
|
|
148
|
-
// @ts-expect-error
|
|
149
|
-
const statValue = stats[supportedStat];
|
|
150
|
-
if (typeof statValue === 'number' && !Number.isNaN(statValue)) {
|
|
151
|
-
this.labels(origin).set(statValue);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
160
|
exports.addObservedAgent = addObservedAgent;
|
|
161
161
|
exports.addObservedPool = addObservedPool;
|
|
162
162
|
exports.createAgentMetricsExporter = createAgentMetricsExporter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promster/undici",
|
|
3
|
-
"version": "15.4.
|
|
3
|
+
"version": "15.4.2",
|
|
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,18 +39,18 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"merge-options": "3.0.4",
|
|
41
41
|
"tslib": "2.6.3",
|
|
42
|
-
"@promster/metrics": "15.4.
|
|
43
|
-
"@promster/types": "15.4.0"
|
|
42
|
+
"@promster/metrics": "15.4.2"
|
|
44
43
|
},
|
|
45
44
|
"devDependencies": {
|
|
46
|
-
"@types/node": "20.
|
|
45
|
+
"@types/node": "20.19.21",
|
|
47
46
|
"prom-client": "15.1.3",
|
|
48
47
|
"typescript": "5.8.3",
|
|
49
48
|
"parse-prometheus-text-format": "1.1.1",
|
|
50
|
-
"undici": "7.
|
|
49
|
+
"undici": "7.16.0",
|
|
51
50
|
"express": "4.21.2",
|
|
52
|
-
"@promster/
|
|
53
|
-
"@promster/
|
|
51
|
+
"@promster/types": "15.4.2",
|
|
52
|
+
"@promster/server": "15.4.2",
|
|
53
|
+
"@promster/express": "15.4.2"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"prom-client": "13.x.x || 14.x || 15.x",
|