hyperswarm-stats 1.3.1 → 1.3.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/index.js +47 -47
- package/package.json +17 -5
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const HyperDhtStats = require('hyperdht-stats')
|
|
2
2
|
|
|
3
3
|
class HyperswarmStats {
|
|
4
|
-
constructor
|
|
4
|
+
constructor(swarm) {
|
|
5
5
|
this.swarm = swarm
|
|
6
6
|
this.dhtStats = new HyperDhtStats(this.swarm.dht)
|
|
7
7
|
|
|
@@ -13,7 +13,7 @@ class HyperswarmStats {
|
|
|
13
13
|
this._fastRecoveriesOfClosedSwarmStreams = 0
|
|
14
14
|
this._rtoCountOfClosedSwarmStreams = 0
|
|
15
15
|
|
|
16
|
-
const onconnection = conn => {
|
|
16
|
+
const onconnection = (conn) => {
|
|
17
17
|
conn.on('close', () => {
|
|
18
18
|
this._bytesTransmittedOverClosedSwarmStreams += conn.rawStream?.bytesTransmitted || 0
|
|
19
19
|
this._packetsTransmittedOverClosedSwarmStreams += conn.rawStream?.packetsTransmitted || 0
|
|
@@ -29,15 +29,15 @@ class HyperswarmStats {
|
|
|
29
29
|
swarm.on('connection', onconnection)
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
get connects
|
|
32
|
+
get connects() {
|
|
33
33
|
return this.swarm.stats.connects
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
get updates
|
|
36
|
+
get updates() {
|
|
37
37
|
return this.swarm.stats.updates
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
getAvgCongestionWindow
|
|
40
|
+
getAvgCongestionWindow() {
|
|
41
41
|
let totalCongestionWindow = 0
|
|
42
42
|
let count = 0
|
|
43
43
|
for (const conn of this.swarm.connections) {
|
|
@@ -50,7 +50,7 @@ class HyperswarmStats {
|
|
|
50
50
|
return totalCongestionWindow / count
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
getAvgMTU
|
|
53
|
+
getAvgMTU() {
|
|
54
54
|
let totalMTU = 0
|
|
55
55
|
let count = 0
|
|
56
56
|
for (const conn of this.swarm.connections) {
|
|
@@ -63,7 +63,7 @@ class HyperswarmStats {
|
|
|
63
63
|
return totalMTU / count
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
getRetransmitsAcrossAllStreams
|
|
66
|
+
getRetransmitsAcrossAllStreams() {
|
|
67
67
|
let countFromCurrentConns = 0
|
|
68
68
|
for (const conn of this.swarm.connections) {
|
|
69
69
|
countFromCurrentConns += conn.rawStream?.retransmits || 0
|
|
@@ -72,7 +72,7 @@ class HyperswarmStats {
|
|
|
72
72
|
return countFromCurrentConns + this._retransmitsOfClosedSwarmStreams
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
getFastRecoveriesAcrossAllStreams
|
|
75
|
+
getFastRecoveriesAcrossAllStreams() {
|
|
76
76
|
let countFromCurrentConns = 0
|
|
77
77
|
for (const conn of this.swarm.connections) {
|
|
78
78
|
countFromCurrentConns += conn.rawStream?.fastRecoveries || 0
|
|
@@ -81,7 +81,7 @@ class HyperswarmStats {
|
|
|
81
81
|
return countFromCurrentConns + this._fastRecoveriesOfClosedSwarmStreams
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
getRTOCountAcrossAllStreams
|
|
84
|
+
getRTOCountAcrossAllStreams() {
|
|
85
85
|
let countFromCurrentConns = 0
|
|
86
86
|
for (const conn of this.swarm.connections) {
|
|
87
87
|
countFromCurrentConns += conn.rawStream?.rtoCount || 0
|
|
@@ -90,7 +90,7 @@ class HyperswarmStats {
|
|
|
90
90
|
return countFromCurrentConns + this._rtoCountOfClosedSwarmStreams
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
getBytesTransmittedAcrossAllStreams
|
|
93
|
+
getBytesTransmittedAcrossAllStreams() {
|
|
94
94
|
let bytesFromCurrentConns = 0
|
|
95
95
|
for (const conn of this.swarm.connections) {
|
|
96
96
|
bytesFromCurrentConns += conn.rawStream?.bytesTransmitted || 0
|
|
@@ -99,7 +99,7 @@ class HyperswarmStats {
|
|
|
99
99
|
return bytesFromCurrentConns + this._bytesTransmittedOverClosedSwarmStreams
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
getBytesReceivedAcrossAllStreams
|
|
102
|
+
getBytesReceivedAcrossAllStreams() {
|
|
103
103
|
let bytesFromCurrentConns = 0
|
|
104
104
|
for (const conn of this.swarm.connections) {
|
|
105
105
|
bytesFromCurrentConns += conn.rawStream?.bytesReceived || 0
|
|
@@ -108,7 +108,7 @@ class HyperswarmStats {
|
|
|
108
108
|
return bytesFromCurrentConns + this._bytesReceivedOverClosedSwarmStreams
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
getPacketsTransmittedAcrossAllStreams
|
|
111
|
+
getPacketsTransmittedAcrossAllStreams() {
|
|
112
112
|
let packetsFromCurrentConns = 0
|
|
113
113
|
for (const conn of this.swarm.connections) {
|
|
114
114
|
packetsFromCurrentConns += conn.rawStream?.packetsTransmitted || 0
|
|
@@ -117,7 +117,7 @@ class HyperswarmStats {
|
|
|
117
117
|
return packetsFromCurrentConns + this._packetsTransmittedOverClosedSwarmStreams
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
getPacketsReceivedAcrossAllStreams
|
|
120
|
+
getPacketsReceivedAcrossAllStreams() {
|
|
121
121
|
let packetsFromCurrentConns = 0
|
|
122
122
|
for (const conn of this.swarm.connections) {
|
|
123
123
|
packetsFromCurrentConns += conn.rawStream?.packetsReceived || 0
|
|
@@ -126,11 +126,11 @@ class HyperswarmStats {
|
|
|
126
126
|
return packetsFromCurrentConns + this._packetsReceivedOverClosedSwarmStreams
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
get nrPeers
|
|
129
|
+
get nrPeers() {
|
|
130
130
|
return this.swarm.peers.size
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
toJson
|
|
133
|
+
toJson() {
|
|
134
134
|
return {
|
|
135
135
|
dht: this.dhtStats.toJson(),
|
|
136
136
|
nrPeers: this.nrPeers,
|
|
@@ -147,7 +147,7 @@ class HyperswarmStats {
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
toString
|
|
150
|
+
toString() {
|
|
151
151
|
return `Hyperswarm Stats
|
|
152
152
|
- hyperswarm_nr_peers: ${this.nrPeers}
|
|
153
153
|
- hyperswarm_client_connections_opened: ${this.connects.client.opened}
|
|
@@ -167,118 +167,118 @@ class HyperswarmStats {
|
|
|
167
167
|
${this.dhtStats.toString()}`
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
registerPrometheusMetrics
|
|
170
|
+
registerPrometheusMetrics(promClient) {
|
|
171
171
|
this.dhtStats.registerPrometheusMetrics(promClient)
|
|
172
172
|
|
|
173
173
|
const self = this
|
|
174
|
-
new promClient.Gauge({
|
|
174
|
+
new promClient.Gauge({
|
|
175
175
|
name: 'hyperswarm_nr_peers',
|
|
176
176
|
help: 'Number of peers this swarm is connected to',
|
|
177
|
-
collect
|
|
177
|
+
collect() {
|
|
178
178
|
this.set(self.nrPeers)
|
|
179
179
|
}
|
|
180
180
|
})
|
|
181
181
|
|
|
182
|
-
new promClient.Gauge({
|
|
182
|
+
new promClient.Gauge({
|
|
183
183
|
name: 'hyperswarm_client_connections_opened',
|
|
184
184
|
help: 'Total number of client connections opened by the swarm',
|
|
185
|
-
collect
|
|
185
|
+
collect() {
|
|
186
186
|
this.set(self.connects.client.opened)
|
|
187
187
|
}
|
|
188
188
|
})
|
|
189
|
-
new promClient.Gauge({
|
|
189
|
+
new promClient.Gauge({
|
|
190
190
|
name: 'hyperswarm_client_connections_closed',
|
|
191
191
|
help: 'Total number of client connections closed by the swarm',
|
|
192
|
-
collect
|
|
192
|
+
collect() {
|
|
193
193
|
this.set(self.connects.client.closed)
|
|
194
194
|
}
|
|
195
195
|
})
|
|
196
|
-
new promClient.Gauge({
|
|
196
|
+
new promClient.Gauge({
|
|
197
197
|
name: 'hyperswarm_client_connections_attempted',
|
|
198
198
|
help: 'Total number of client connections attempted by the swarm',
|
|
199
|
-
collect
|
|
199
|
+
collect() {
|
|
200
200
|
this.set(self.connects.client.attempted)
|
|
201
201
|
}
|
|
202
202
|
})
|
|
203
203
|
|
|
204
|
-
new promClient.Gauge({
|
|
204
|
+
new promClient.Gauge({
|
|
205
205
|
name: 'hyperswarm_server_connections_opened',
|
|
206
206
|
help: 'Total number of server connections opened by the swarm',
|
|
207
|
-
collect
|
|
207
|
+
collect() {
|
|
208
208
|
this.set(self.connects.server.opened)
|
|
209
209
|
}
|
|
210
210
|
})
|
|
211
|
-
new promClient.Gauge({
|
|
211
|
+
new promClient.Gauge({
|
|
212
212
|
name: 'hyperswarm_server_connections_closed',
|
|
213
213
|
help: 'Total number of server connections closed by the swarm',
|
|
214
|
-
collect
|
|
214
|
+
collect() {
|
|
215
215
|
this.set(self.connects.server.closed)
|
|
216
216
|
}
|
|
217
217
|
})
|
|
218
218
|
|
|
219
|
-
new promClient.Gauge({
|
|
219
|
+
new promClient.Gauge({
|
|
220
220
|
name: 'hyperswarm_total_bytes_transmitted_over_swarm_streams',
|
|
221
221
|
help: 'Total bytes transmitted over the streams exposed explicitly by hyperswarm connections',
|
|
222
|
-
collect
|
|
222
|
+
collect() {
|
|
223
223
|
this.set(self.getBytesTransmittedAcrossAllStreams())
|
|
224
224
|
}
|
|
225
225
|
})
|
|
226
|
-
new promClient.Gauge({
|
|
226
|
+
new promClient.Gauge({
|
|
227
227
|
name: 'hyperswarm_total_bytes_received_over_swarm_streams',
|
|
228
228
|
help: 'Total bytes received over the streams exposed explicitly by hyperswarm connections',
|
|
229
|
-
collect
|
|
229
|
+
collect() {
|
|
230
230
|
this.set(self.getBytesReceivedAcrossAllStreams())
|
|
231
231
|
}
|
|
232
232
|
})
|
|
233
|
-
new promClient.Gauge({
|
|
233
|
+
new promClient.Gauge({
|
|
234
234
|
name: 'hyperswarm_total_packets_transmitted_over_swarm_streams',
|
|
235
235
|
help: 'Total packets transmitted over the streams exposed explicitly by hyperswarm connections',
|
|
236
|
-
collect
|
|
236
|
+
collect() {
|
|
237
237
|
this.set(self.getPacketsTransmittedAcrossAllStreams())
|
|
238
238
|
}
|
|
239
239
|
})
|
|
240
|
-
new promClient.Gauge({
|
|
240
|
+
new promClient.Gauge({
|
|
241
241
|
name: 'hyperswarm_total_packets_received_over_swarm_streams',
|
|
242
242
|
help: 'Total packets received over the streams exposed explicitly by hyperswarm connections',
|
|
243
|
-
collect
|
|
243
|
+
collect() {
|
|
244
244
|
this.set(self.getPacketsReceivedAcrossAllStreams())
|
|
245
245
|
}
|
|
246
246
|
})
|
|
247
247
|
|
|
248
|
-
new promClient.Gauge({
|
|
248
|
+
new promClient.Gauge({
|
|
249
249
|
name: 'hyperswarm_avg_congestion_window',
|
|
250
250
|
help: 'Average size of the congestion window (over all hyperswarm connections)',
|
|
251
|
-
collect
|
|
251
|
+
collect() {
|
|
252
252
|
this.set(self.getAvgCongestionWindow())
|
|
253
253
|
}
|
|
254
254
|
})
|
|
255
255
|
|
|
256
|
-
new promClient.Gauge({
|
|
256
|
+
new promClient.Gauge({
|
|
257
257
|
name: 'hyperswarm_avg_mtu',
|
|
258
258
|
help: 'Average size of the Maximum Transmission Unit (over all hyperswarm connections)',
|
|
259
|
-
collect
|
|
259
|
+
collect() {
|
|
260
260
|
this.set(self.getAvgMTU())
|
|
261
261
|
}
|
|
262
262
|
})
|
|
263
263
|
|
|
264
|
-
new promClient.Gauge({
|
|
264
|
+
new promClient.Gauge({
|
|
265
265
|
name: 'hyperswarm_total_retransmits_over_swarm_streams',
|
|
266
266
|
help: 'Total UDX retransmits (after a lost packet), summed across the streams exposed explicitly by hyperswarm connections',
|
|
267
|
-
collect
|
|
267
|
+
collect() {
|
|
268
268
|
this.set(self.getRetransmitsAcrossAllStreams())
|
|
269
269
|
}
|
|
270
270
|
})
|
|
271
|
-
new promClient.Gauge({
|
|
271
|
+
new promClient.Gauge({
|
|
272
272
|
name: 'hyperswarm_total_fast_recoveries_over_swarm_streams',
|
|
273
273
|
help: 'Total UDX fast recoveries summed across the streams exposed explicitly by hyperswarm connections',
|
|
274
|
-
collect
|
|
274
|
+
collect() {
|
|
275
275
|
this.set(self.getFastRecoveriesAcrossAllStreams())
|
|
276
276
|
}
|
|
277
277
|
})
|
|
278
|
-
new promClient.Gauge({
|
|
278
|
+
new promClient.Gauge({
|
|
279
279
|
name: 'hyperswarm_total_rto_count_over_swarm_streams',
|
|
280
280
|
help: 'Total UDX retransmission time-outs, summed across the streams exposed explicitly by hyperswarm connections',
|
|
281
|
-
collect
|
|
281
|
+
collect() {
|
|
282
282
|
this.set(self.getRTOCountAcrossAllStreams())
|
|
283
283
|
}
|
|
284
284
|
})
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hyperswarm-stats",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Hyperswarm stats with prometheus support",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
7
|
+
"format": "prettier --write .",
|
|
8
|
+
"lint": "lunte && prettier --check .",
|
|
9
|
+
"test": "npm run lint && brittle-node test.js",
|
|
10
|
+
"test:bare": "brittle-bare test.js"
|
|
8
11
|
},
|
|
9
12
|
"repository": {
|
|
10
13
|
"type": "git",
|
|
@@ -26,12 +29,21 @@
|
|
|
26
29
|
],
|
|
27
30
|
"devDependencies": {
|
|
28
31
|
"b4a": "^1.6.6",
|
|
29
|
-
"
|
|
32
|
+
"bare-events": "^2.9.2",
|
|
33
|
+
"bare-prom-client": "^15.1.9",
|
|
34
|
+
"brittle": "^4.0.0",
|
|
30
35
|
"hyperswarm": "^4.8.2",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
36
|
+
"lunte": "^1.8.6",
|
|
37
|
+
"prettier": "^3.9.10",
|
|
38
|
+
"prettier-config-holepunch": "^2.0.0"
|
|
33
39
|
},
|
|
34
40
|
"dependencies": {
|
|
35
41
|
"hyperdht-stats": "^1.7.0"
|
|
42
|
+
},
|
|
43
|
+
"imports": {
|
|
44
|
+
"events": {
|
|
45
|
+
"bare": "bare-events",
|
|
46
|
+
"default": "events"
|
|
47
|
+
}
|
|
36
48
|
}
|
|
37
49
|
}
|