hyperswarm-stats 1.0.1 → 1.1.1
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 +88 -169
- package/package.json +5 -1
package/index.js
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
|
+
const HyperDhtStats = require('hyperdht-stats')
|
|
2
|
+
|
|
1
3
|
class HyperswarmStats {
|
|
2
4
|
constructor (swarm) {
|
|
3
5
|
this.swarm = swarm
|
|
6
|
+
this.dhtStats = new HyperDhtStats(this.swarm.dht)
|
|
4
7
|
|
|
5
8
|
this._bytesTransmittedOverClosedSwarmStreams = 0
|
|
6
9
|
this._packetsTransmittedOverClosedSwarmStreams = 0
|
|
7
10
|
this._bytesReceivedOverClosedSwarmStreams = 0
|
|
8
11
|
this._packetsReceivedOverClosedSwarmStreams = 0
|
|
12
|
+
this._retransmitsOfClosedSwarmStreams = 0
|
|
13
|
+
this._fastRecoveriesOfClosedSwarmStreams = 0
|
|
14
|
+
this._rtoCountOfClosedSwarmStreams = 0
|
|
15
|
+
|
|
9
16
|
swarm.on('connection', conn => {
|
|
10
17
|
conn.on('close', () => {
|
|
11
18
|
this._bytesTransmittedOverClosedSwarmStreams += conn.rawStream?.bytesTransmitted || 0
|
|
12
19
|
this._packetsTransmittedOverClosedSwarmStreams += conn.rawStream?.packetsTransmitted || 0
|
|
13
20
|
this._bytesReceivedOverClosedSwarmStreams += conn.rawStream?.bytesReceived || 0
|
|
14
21
|
this._packetsReceivedOverClosedSwarmStreams += conn.rawStream?.packetsReceived || 0
|
|
22
|
+
this._retransmitsOfClosedSwarmStreams += conn.rawStream?.retransmits
|
|
23
|
+
this._fastRecoveriesOfClosedSwarmStreams += conn.rawStream?.fastRecoveries
|
|
24
|
+
this._rtoCountOfClosedSwarmStreams += conn.rawStream?.rtoCount
|
|
15
25
|
})
|
|
16
26
|
})
|
|
17
27
|
}
|
|
@@ -24,12 +34,57 @@ class HyperswarmStats {
|
|
|
24
34
|
return this.swarm.stats.updates
|
|
25
35
|
}
|
|
26
36
|
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
getAvgCongestionWindow () {
|
|
38
|
+
let totalCongestionWindow = 0
|
|
39
|
+
let count = 0
|
|
40
|
+
for (const conn of this.swarm.connections) {
|
|
41
|
+
if (conn.rawStream) {
|
|
42
|
+
count++
|
|
43
|
+
totalCongestionWindow += conn.rawStream.cwnd
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return totalCongestionWindow / count
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
getAvgMTU () {
|
|
51
|
+
let totalMTU = 0
|
|
52
|
+
let count = 0
|
|
53
|
+
for (const conn of this.swarm.connections) {
|
|
54
|
+
if (conn.rawStream) {
|
|
55
|
+
count++
|
|
56
|
+
totalMTU += conn.rawStream.mtu
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return totalMTU / count
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
getRetransmitsAcrossAllStreams () {
|
|
64
|
+
let countFromCurrentConns = 0
|
|
65
|
+
for (const conn of this.swarm.connections) {
|
|
66
|
+
countFromCurrentConns += conn.rawStream?.retransmits || 0
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return countFromCurrentConns + this._retransmitsOfClosedSwarmStreams
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getFastRecoveriesAcrossAllStreams () {
|
|
73
|
+
let countFromCurrentConns = 0
|
|
74
|
+
for (const conn of this.swarm.connections) {
|
|
75
|
+
countFromCurrentConns += conn.rawStream?.fastRecoveries || 0
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return countFromCurrentConns + this._fastRecoveriesOfClosedSwarmStreams
|
|
29
79
|
}
|
|
30
80
|
|
|
31
|
-
|
|
32
|
-
|
|
81
|
+
getRTOCountAcrossAllStreams () {
|
|
82
|
+
let countFromCurrentConns = 0
|
|
83
|
+
for (const conn of this.swarm.connections) {
|
|
84
|
+
countFromCurrentConns += conn.rawStream?.rtoCount || 0
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return countFromCurrentConns + this._rtoCountOfClosedSwarmStreams
|
|
33
88
|
}
|
|
34
89
|
|
|
35
90
|
getBytesTransmittedAcrossAllStreams () {
|
|
@@ -68,62 +123,13 @@ class HyperswarmStats {
|
|
|
68
123
|
return packetsFromCurrentConns + this._packetsReceivedOverClosedSwarmStreams
|
|
69
124
|
}
|
|
70
125
|
|
|
71
|
-
get dhtClientSocketBytesTransmitted () {
|
|
72
|
-
return this.swarm.dht.io.clientSocket?.bytesTransmitted || 0
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
get dhtClientSocketPacketsTransmitted () {
|
|
76
|
-
return this.swarm.dht.io.clientSocket?.packetsTransmitted || 0
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
get dhtClientSocketBytesReceived () {
|
|
80
|
-
return this.swarm.dht.io.clientSocket?.bytesReceived || 0
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
get dhtClientSocketPacketsReceived () {
|
|
84
|
-
return this.swarm.dht.io.clientSocket?.packetsReceived || 0
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
get dhtServerSocketBytesTransmitted () {
|
|
88
|
-
return this.swarm.dht.io.serverSocket?.bytesTransmitted || 0
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
get dhtServerSocketPacketsTransmitted () {
|
|
92
|
-
return this.swarm.dht.io.serverSocket?.packetsTransmitted || 0
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
get dhtServerSocketBytesReceived () {
|
|
96
|
-
return this.swarm.dht.io.serverSocket?.bytesReceived || 0
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
get dhtServerSocketPacketsReceived () {
|
|
100
|
-
return this.swarm.dht.io.serverSocket?.packetsReceived || 0
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
get udxBytesTransmitted () {
|
|
104
|
-
return this.swarm.dht.udx.bytesTransmitted
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
get udxPacketsTransmitted () {
|
|
108
|
-
return this.swarm.dht.udx.packetsTransmitted
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
get udxBytesReceived () {
|
|
112
|
-
return this.swarm.dht.udx.bytesReceived
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
get udxPacketsReceived () {
|
|
116
|
-
return this.swarm.dht.udx.packetsReceived
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// TODO
|
|
120
|
-
// get nrDhtEntries () {}
|
|
121
|
-
|
|
122
126
|
get nrPeers () {
|
|
123
127
|
return this.swarm.peers.size
|
|
124
128
|
}
|
|
125
129
|
|
|
126
130
|
registerPrometheusMetrics (promClient) {
|
|
131
|
+
this.dhtStats.registerPrometheusMetrics(promClient)
|
|
132
|
+
|
|
127
133
|
const self = this
|
|
128
134
|
new promClient.Gauge({ // eslint-disable-line no-new
|
|
129
135
|
name: 'hyperswarm_nr_peers',
|
|
@@ -171,156 +177,69 @@ class HyperswarmStats {
|
|
|
171
177
|
})
|
|
172
178
|
|
|
173
179
|
new promClient.Gauge({ // eslint-disable-line no-new
|
|
174
|
-
name: '
|
|
175
|
-
help: 'Total
|
|
176
|
-
collect () {
|
|
177
|
-
this.set(self.punches.consistent)
|
|
178
|
-
}
|
|
179
|
-
})
|
|
180
|
-
new promClient.Gauge({ // eslint-disable-line no-new
|
|
181
|
-
name: 'dht_random_punches',
|
|
182
|
-
help: 'Total number of random holepunches performed by the hyperdht instance',
|
|
183
|
-
collect () {
|
|
184
|
-
this.set(self.punches.random)
|
|
185
|
-
}
|
|
186
|
-
})
|
|
187
|
-
new promClient.Gauge({ // eslint-disable-line no-new
|
|
188
|
-
name: 'dht_open_punches',
|
|
189
|
-
help: 'Total number of open holepunches performed by the hyperdht instance',
|
|
190
|
-
collect () {
|
|
191
|
-
this.set(self.punches.open)
|
|
192
|
-
}
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
new promClient.Gauge({ // eslint-disable-line no-new
|
|
196
|
-
name: 'dht_active_queries',
|
|
197
|
-
help: 'Number of currently active queries in the dht-rpc instance',
|
|
198
|
-
collect () {
|
|
199
|
-
this.set(self.dhtQueries.active)
|
|
200
|
-
}
|
|
201
|
-
})
|
|
202
|
-
|
|
203
|
-
new promClient.Gauge({ // eslint-disable-line no-new
|
|
204
|
-
name: 'dht_total_queries',
|
|
205
|
-
help: 'Total number of queries in the dht-rpc instance',
|
|
206
|
-
collect () {
|
|
207
|
-
this.set(self.dhtQueries.total)
|
|
208
|
-
}
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
new promClient.Gauge({ // eslint-disable-line no-new
|
|
212
|
-
name: 'hyperswarm_total_bytes_transmitted',
|
|
213
|
-
help: 'Total bytes transmitted by the hyperswarm and the DHT',
|
|
180
|
+
name: 'hyperswarm_total_bytes_transmitted_over_swarm_streams',
|
|
181
|
+
help: 'Total bytes transmitted over the streams exposed explicitly by hyperswarm connections',
|
|
214
182
|
collect () {
|
|
215
|
-
this.set(self.
|
|
183
|
+
this.set(self.getBytesTransmittedAcrossAllStreams())
|
|
216
184
|
}
|
|
217
185
|
})
|
|
218
186
|
new promClient.Gauge({ // eslint-disable-line no-new
|
|
219
|
-
name: '
|
|
220
|
-
help: 'Total
|
|
187
|
+
name: 'hyperswarm_total_bytes_received_over_swarm_streams',
|
|
188
|
+
help: 'Total bytes received over the streams exposed explicitly by hyperswarm connections',
|
|
221
189
|
collect () {
|
|
222
|
-
this.set(self.
|
|
190
|
+
this.set(self.getBytesReceivedAcrossAllStreams())
|
|
223
191
|
}
|
|
224
192
|
})
|
|
225
193
|
new promClient.Gauge({ // eslint-disable-line no-new
|
|
226
|
-
name: '
|
|
227
|
-
help: 'Total
|
|
194
|
+
name: 'hyperswarm_total_packets_transmitted_over_swarm_streams',
|
|
195
|
+
help: 'Total packets transmitted over the streams exposed explicitly by hyperswarm connections',
|
|
228
196
|
collect () {
|
|
229
|
-
this.set(self.
|
|
197
|
+
this.set(self.getPacketsTransmittedAcrossAllStreams())
|
|
230
198
|
}
|
|
231
199
|
})
|
|
232
200
|
new promClient.Gauge({ // eslint-disable-line no-new
|
|
233
|
-
name: '
|
|
234
|
-
help: 'Total packets received
|
|
201
|
+
name: 'hyperswarm_total_packets_received_over_swarm_streams',
|
|
202
|
+
help: 'Total packets received over the streams exposed explicitly by hyperswarm connections',
|
|
235
203
|
collect () {
|
|
236
|
-
this.set(self.
|
|
204
|
+
this.set(self.getPacketsReceivedAcrossAllStreams())
|
|
237
205
|
}
|
|
238
206
|
})
|
|
239
207
|
|
|
240
208
|
new promClient.Gauge({ // eslint-disable-line no-new
|
|
241
|
-
name: '
|
|
242
|
-
help: '
|
|
243
|
-
collect () {
|
|
244
|
-
this.set(self.dhtClientSocketBytesTransmitted)
|
|
245
|
-
}
|
|
246
|
-
})
|
|
247
|
-
new promClient.Gauge({ // eslint-disable-line no-new
|
|
248
|
-
name: 'dht_client_socket_packets_transmitted',
|
|
249
|
-
help: 'Total packets transmitted by the client socket of the DHT',
|
|
250
|
-
collect () {
|
|
251
|
-
this.set(self.dhtClientSocketPacketsTransmitted)
|
|
252
|
-
}
|
|
253
|
-
})
|
|
254
|
-
new promClient.Gauge({ // eslint-disable-line no-new
|
|
255
|
-
name: 'dht_client_socket_bytes_received',
|
|
256
|
-
help: 'Total bytes received by the client socket of the DHT',
|
|
209
|
+
name: 'hyperswarm_avg_congestion_window',
|
|
210
|
+
help: 'Average size of the congestion window (over all hyperswarm connections)',
|
|
257
211
|
collect () {
|
|
258
|
-
this.set(self.
|
|
259
|
-
}
|
|
260
|
-
})
|
|
261
|
-
new promClient.Gauge({ // eslint-disable-line no-new
|
|
262
|
-
name: 'dht_client_socket_packets_received',
|
|
263
|
-
help: 'Total packets received by the client socket of the DHT',
|
|
264
|
-
collect () {
|
|
265
|
-
this.set(self.dhtClientSocketPacketsReceived)
|
|
212
|
+
this.set(self.getAvgCongestionWindow())
|
|
266
213
|
}
|
|
267
214
|
})
|
|
268
215
|
|
|
269
216
|
new promClient.Gauge({ // eslint-disable-line no-new
|
|
270
|
-
name: '
|
|
271
|
-
help: '
|
|
272
|
-
collect () {
|
|
273
|
-
this.set(self.dhtServerSocketBytesTransmitted)
|
|
274
|
-
}
|
|
275
|
-
})
|
|
276
|
-
new promClient.Gauge({ // eslint-disable-line no-new
|
|
277
|
-
name: 'dht_server_socket_packets_transmitted',
|
|
278
|
-
help: 'Total packets transmitted by the server socket of the DHT',
|
|
279
|
-
collect () {
|
|
280
|
-
this.set(self.dhtServerSocketPacketsTransmitted)
|
|
281
|
-
}
|
|
282
|
-
})
|
|
283
|
-
new promClient.Gauge({ // eslint-disable-line no-new
|
|
284
|
-
name: 'dht_server_socket_bytes_received',
|
|
285
|
-
help: 'Total bytes received by the server socket of the DHT',
|
|
286
|
-
collect () {
|
|
287
|
-
this.set(self.dhtServerSocketBytesReceived)
|
|
288
|
-
}
|
|
289
|
-
})
|
|
290
|
-
new promClient.Gauge({ // eslint-disable-line no-new
|
|
291
|
-
name: 'dht_server_socket_packets_received',
|
|
292
|
-
help: 'Total packets received by the server socket of the DHT',
|
|
217
|
+
name: 'hyperswarm_avg_mtu',
|
|
218
|
+
help: 'Average size of the Maximum Transmission Unit (over all hyperswarm connections)',
|
|
293
219
|
collect () {
|
|
294
|
-
this.set(self.
|
|
220
|
+
this.set(self.getAvgMTU())
|
|
295
221
|
}
|
|
296
222
|
})
|
|
297
223
|
|
|
298
224
|
new promClient.Gauge({ // eslint-disable-line no-new
|
|
299
|
-
name: '
|
|
300
|
-
help: 'Total
|
|
225
|
+
name: 'hyperswarm_total_retransmits_over_swarm_streams',
|
|
226
|
+
help: 'Total UDX retransmits (after a lost packet), summed across the streams exposed explicitly by hyperswarm connections',
|
|
301
227
|
collect () {
|
|
302
|
-
this.set(self.
|
|
228
|
+
this.set(self.getRetransmitsAcrossAllStreams())
|
|
303
229
|
}
|
|
304
230
|
})
|
|
305
231
|
new promClient.Gauge({ // eslint-disable-line no-new
|
|
306
|
-
name: '
|
|
307
|
-
help: 'Total
|
|
232
|
+
name: 'hyperswarm_total_fast_recoveries_over_swarm_streams',
|
|
233
|
+
help: 'Total UDX fast recoveries summed across the streams exposed explicitly by hyperswarm connections',
|
|
308
234
|
collect () {
|
|
309
|
-
this.set(self.
|
|
235
|
+
this.set(self.getFastRecoveriesAcrossAllStreams())
|
|
310
236
|
}
|
|
311
237
|
})
|
|
312
238
|
new promClient.Gauge({ // eslint-disable-line no-new
|
|
313
|
-
name: '
|
|
314
|
-
help: 'Total
|
|
239
|
+
name: 'hyperswarm_total_rto_count_over_swarm_streams',
|
|
240
|
+
help: 'Total UDX retransmission time-outs, summed across the streams exposed explicitly by hyperswarm connections',
|
|
315
241
|
collect () {
|
|
316
|
-
this.set(self.
|
|
317
|
-
}
|
|
318
|
-
})
|
|
319
|
-
new promClient.Gauge({ // eslint-disable-line no-new
|
|
320
|
-
name: 'hyperswarm_total_packets_received_over_swarm_streams',
|
|
321
|
-
help: 'Total packets received over the streams exposed explicitly by hyperswarm connections',
|
|
322
|
-
collect () {
|
|
323
|
-
this.set(self.getPacketsReceivedAcrossAllStreams())
|
|
242
|
+
this.set(self.getRTOCountAcrossAllStreams())
|
|
324
243
|
}
|
|
325
244
|
})
|
|
326
245
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hyperswarm-stats",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Hyperswarm stats with prometheus support",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -30,5 +30,9 @@
|
|
|
30
30
|
"hyperswarm": "^4.8.2",
|
|
31
31
|
"prom-client": "^15.1.3",
|
|
32
32
|
"standard": "^17.1.0"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"hyperdht-stats": "1.0.0",
|
|
36
|
+
"udx-native": "^1.12.0"
|
|
33
37
|
}
|
|
34
38
|
}
|