You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If defined, `options` should be an object with the following keys and respective values:
59
+
60
+
-`stats`: an object with the following keys and respective values:
61
+
-`maxOldPeersRetention`: maximum old peers retention. For when peers disconnect and keeping the stats around in case they reconnect. Defaults to `100`.
62
+
-`computeThrottleMaxQueueSize`: maximum queue size to perform stats computation throttling. Defaults to `1000`.
63
+
-`computeThrottleTimeout`: Throttle timeout, in miliseconds. Defaults to `2000`,
64
+
-`movingAverageIntervals`: Array containin the intervals, in miliseconds, for which moving averages are calculated. Defaults to:
65
+
66
+
```js
67
+
[
68
+
60*1000, // 1 minute
69
+
5*60*1000, // 5 minutes
70
+
15*60*1000// 15 minutes
71
+
]
72
+
```
73
+
74
+
57
75
## API
58
76
59
77
- peerInfo is a [PeerInfo](https://github.com/libp2p/js-peer-info) object that has the peer information.
@@ -147,6 +165,111 @@ Enable circuit relaying.
147
165
- active - is it an active or passive relay (default false)
148
166
- `callback`
149
167
168
+
### Stats API
169
+
170
+
##### `switch.stats.emit('update')`
171
+
172
+
Every time any stat value changes, this object emits an `update` event.
173
+
174
+
#### Global stats
175
+
176
+
##### `switch.stats.global.snapshot`
177
+
178
+
Should return a stats snapshot, which is an object containing the following keys and respective values:
179
+
180
+
- dataSent: amount of bytes sent, [Big](https://github.com/MikeMcl/big.js#readme) number
181
+
- dataReceived: amount of bytes received, [Big](https://github.com/MikeMcl/big.js#readme) number
182
+
183
+
##### `switch.stats.global.movingAverages`
184
+
185
+
Returns an object containing the following keys:
186
+
187
+
- dataSent
188
+
- dataReceived
189
+
190
+
Each one of them contains an object that has a key for each interval (`60000`, `300000` and `900000` miliseconds).
191
+
192
+
Each one of these values is [an exponential moving-average instance](https://github.com/pgte/moving-average#readme).
193
+
194
+
#### Per-transport stats
195
+
196
+
##### `switch.stats.transports()`
197
+
198
+
Returns an array containing the tags (string) for each observed transport.
Each one of them contains an object that has a key for each interval (`60000`, `300000` and `900000` miliseconds).
265
+
266
+
Each one of these values is [an exponential moving-average instance](https://github.com/pgte/moving-average#readme).
267
+
268
+
#### Stats update interval
269
+
270
+
Stats are not updated in real-time. Instead, measurements are buffered and stats are updated at an interval. The maximum interval can be defined through the `Switch`constructor option `stats.computeThrottleTimeout`, defined in miliseconds.
@@ -212,9 +335,10 @@ Identify is a protocol that switchs mounts on top of itself, to identify the con
212
335
- a) peer A dials a conn to peer B
213
336
- b) that conn gets upgraded to a stream multiplexer that both peers agree
214
337
- c) peer B executes de identify protocol
215
-
- d) peer B now can open streams to peer A, knowing which is the identity of peer A
338
+
- d) peer B now can open streams to peer A, knowing which is the
339
+
identity of peer A
216
340
217
-
In addition to this, we also share the 'observed addresses' by the other peer, which is extremely useful information for different kinds of network topologies.
341
+
In addition to this, we also share the "observed addresses" by the other peer, which is extremely useful information for different kinds of network topologies.
0 commit comments