hyperswarm-stats 1.1.0 → 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.
Files changed (2) hide show
  1. package/index.js +61 -184
  2. 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,14 +34,6 @@ class HyperswarmStats {
24
34
  return this.swarm.stats.updates
25
35
  }
26
36
 
27
- get punches () {
28
- return this.swarm.dht.stats.punches
29
- }
30
-
31
- get dhtQueries () {
32
- return this.swarm.dht.stats.queries
33
- }
34
-
35
37
  getAvgCongestionWindow () {
36
38
  let totalCongestionWindow = 0
37
39
  let count = 0
@@ -58,6 +60,33 @@ class HyperswarmStats {
58
60
  return totalMTU / count
59
61
  }
60
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
79
+ }
80
+
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
88
+ }
89
+
61
90
  getBytesTransmittedAcrossAllStreams () {
62
91
  let bytesFromCurrentConns = 0
63
92
  for (const conn of this.swarm.connections) {
@@ -94,62 +123,13 @@ class HyperswarmStats {
94
123
  return packetsFromCurrentConns + this._packetsReceivedOverClosedSwarmStreams
95
124
  }
96
125
 
97
- get dhtClientSocketBytesTransmitted () {
98
- return this.swarm.dht.io.clientSocket?.bytesTransmitted || 0
99
- }
100
-
101
- get dhtClientSocketPacketsTransmitted () {
102
- return this.swarm.dht.io.clientSocket?.packetsTransmitted || 0
103
- }
104
-
105
- get dhtClientSocketBytesReceived () {
106
- return this.swarm.dht.io.clientSocket?.bytesReceived || 0
107
- }
108
-
109
- get dhtClientSocketPacketsReceived () {
110
- return this.swarm.dht.io.clientSocket?.packetsReceived || 0
111
- }
112
-
113
- get dhtServerSocketBytesTransmitted () {
114
- return this.swarm.dht.io.serverSocket?.bytesTransmitted || 0
115
- }
116
-
117
- get dhtServerSocketPacketsTransmitted () {
118
- return this.swarm.dht.io.serverSocket?.packetsTransmitted || 0
119
- }
120
-
121
- get dhtServerSocketBytesReceived () {
122
- return this.swarm.dht.io.serverSocket?.bytesReceived || 0
123
- }
124
-
125
- get dhtServerSocketPacketsReceived () {
126
- return this.swarm.dht.io.serverSocket?.packetsReceived || 0
127
- }
128
-
129
- get udxBytesTransmitted () {
130
- return this.swarm.dht.udx.bytesTransmitted
131
- }
132
-
133
- get udxPacketsTransmitted () {
134
- return this.swarm.dht.udx.packetsTransmitted
135
- }
136
-
137
- get udxBytesReceived () {
138
- return this.swarm.dht.udx.bytesReceived
139
- }
140
-
141
- get udxPacketsReceived () {
142
- return this.swarm.dht.udx.packetsReceived
143
- }
144
-
145
- // TODO
146
- // get nrDhtEntries () {}
147
-
148
126
  get nrPeers () {
149
127
  return this.swarm.peers.size
150
128
  }
151
129
 
152
130
  registerPrometheusMetrics (promClient) {
131
+ this.dhtStats.registerPrometheusMetrics(promClient)
132
+
153
133
  const self = this
154
134
  new promClient.Gauge({ // eslint-disable-line no-new
155
135
  name: 'hyperswarm_nr_peers',
@@ -196,131 +176,6 @@ class HyperswarmStats {
196
176
  }
197
177
  })
198
178
 
199
- new promClient.Gauge({ // eslint-disable-line no-new
200
- name: 'dht_consistent_punches',
201
- help: 'Total number of consistent holepunches performed by the hyperdht instance',
202
- collect () {
203
- this.set(self.punches.consistent)
204
- }
205
- })
206
- new promClient.Gauge({ // eslint-disable-line no-new
207
- name: 'dht_random_punches',
208
- help: 'Total number of random holepunches performed by the hyperdht instance',
209
- collect () {
210
- this.set(self.punches.random)
211
- }
212
- })
213
- new promClient.Gauge({ // eslint-disable-line no-new
214
- name: 'dht_open_punches',
215
- help: 'Total number of open holepunches performed by the hyperdht instance',
216
- collect () {
217
- this.set(self.punches.open)
218
- }
219
- })
220
-
221
- new promClient.Gauge({ // eslint-disable-line no-new
222
- name: 'dht_active_queries',
223
- help: 'Number of currently active queries in the dht-rpc instance',
224
- collect () {
225
- this.set(self.dhtQueries.active)
226
- }
227
- })
228
-
229
- new promClient.Gauge({ // eslint-disable-line no-new
230
- name: 'dht_total_queries',
231
- help: 'Total number of queries in the dht-rpc instance',
232
- collect () {
233
- this.set(self.dhtQueries.total)
234
- }
235
- })
236
-
237
- new promClient.Gauge({ // eslint-disable-line no-new
238
- name: 'hyperswarm_total_bytes_transmitted',
239
- help: 'Total bytes transmitted by the hyperswarm and the DHT',
240
- collect () {
241
- this.set(self.udxBytesTransmitted)
242
- }
243
- })
244
- new promClient.Gauge({ // eslint-disable-line no-new
245
- name: 'hyperswarm_total_packets_transmitted',
246
- help: 'Total packets transmitted by the hyperswarm and the DHT',
247
- collect () {
248
- this.set(self.udxPacketsTransmitted)
249
- }
250
- })
251
- new promClient.Gauge({ // eslint-disable-line no-new
252
- name: 'hyperswarm_total_bytes_received',
253
- help: 'Total bytes received by the hyperswarm and the DHT',
254
- collect () {
255
- this.set(self.udxBytesReceived)
256
- }
257
- })
258
- new promClient.Gauge({ // eslint-disable-line no-new
259
- name: 'hyperswarm_total_packets_received',
260
- help: 'Total packets received by the hyperswarm and the DHT',
261
- collect () {
262
- this.set(self.udxPacketsReceived)
263
- }
264
- })
265
-
266
- new promClient.Gauge({ // eslint-disable-line no-new
267
- name: 'dht_client_socket_bytes_transmitted',
268
- help: 'Total bytes transmitted by the client socket of the DHT',
269
- collect () {
270
- this.set(self.dhtClientSocketBytesTransmitted)
271
- }
272
- })
273
- new promClient.Gauge({ // eslint-disable-line no-new
274
- name: 'dht_client_socket_packets_transmitted',
275
- help: 'Total packets transmitted by the client socket of the DHT',
276
- collect () {
277
- this.set(self.dhtClientSocketPacketsTransmitted)
278
- }
279
- })
280
- new promClient.Gauge({ // eslint-disable-line no-new
281
- name: 'dht_client_socket_bytes_received',
282
- help: 'Total bytes received by the client socket of the DHT',
283
- collect () {
284
- this.set(self.dhtClientSocketBytesReceived)
285
- }
286
- })
287
- new promClient.Gauge({ // eslint-disable-line no-new
288
- name: 'dht_client_socket_packets_received',
289
- help: 'Total packets received by the client socket of the DHT',
290
- collect () {
291
- this.set(self.dhtClientSocketPacketsReceived)
292
- }
293
- })
294
-
295
- new promClient.Gauge({ // eslint-disable-line no-new
296
- name: 'dht_server_socket_bytes_transmitted',
297
- help: 'Total bytes transmitted by the server socket of the DHT',
298
- collect () {
299
- this.set(self.dhtServerSocketBytesTransmitted)
300
- }
301
- })
302
- new promClient.Gauge({ // eslint-disable-line no-new
303
- name: 'dht_server_socket_packets_transmitted',
304
- help: 'Total packets transmitted by the server socket of the DHT',
305
- collect () {
306
- this.set(self.dhtServerSocketPacketsTransmitted)
307
- }
308
- })
309
- new promClient.Gauge({ // eslint-disable-line no-new
310
- name: 'dht_server_socket_bytes_received',
311
- help: 'Total bytes received by the server socket of the DHT',
312
- collect () {
313
- this.set(self.dhtServerSocketBytesReceived)
314
- }
315
- })
316
- new promClient.Gauge({ // eslint-disable-line no-new
317
- name: 'dht_server_socket_packets_received',
318
- help: 'Total packets received by the server socket of the DHT',
319
- collect () {
320
- this.set(self.dhtServerSocketPacketsReceived)
321
- }
322
- })
323
-
324
179
  new promClient.Gauge({ // eslint-disable-line no-new
325
180
  name: 'hyperswarm_total_bytes_transmitted_over_swarm_streams',
326
181
  help: 'Total bytes transmitted over the streams exposed explicitly by hyperswarm connections',
@@ -365,6 +220,28 @@ class HyperswarmStats {
365
220
  this.set(self.getAvgMTU())
366
221
  }
367
222
  })
223
+
224
+ new promClient.Gauge({ // eslint-disable-line no-new
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',
227
+ collect () {
228
+ this.set(self.getRetransmitsAcrossAllStreams())
229
+ }
230
+ })
231
+ new promClient.Gauge({ // eslint-disable-line no-new
232
+ name: 'hyperswarm_total_fast_recoveries_over_swarm_streams',
233
+ help: 'Total UDX fast recoveries summed across the streams exposed explicitly by hyperswarm connections',
234
+ collect () {
235
+ this.set(self.getFastRecoveriesAcrossAllStreams())
236
+ }
237
+ })
238
+ new promClient.Gauge({ // eslint-disable-line no-new
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',
241
+ collect () {
242
+ this.set(self.getRTOCountAcrossAllStreams())
243
+ }
244
+ })
368
245
  }
369
246
  }
370
247
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperswarm-stats",
3
- "version": "1.1.0",
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
  }