libp2p 0.35.3 → 0.35.4
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/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/dialer/index.d.ts +4 -1
- package/dist/src/dialer/index.d.ts.map +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/metrics/index.d.ts +9 -10
- package/dist/src/metrics/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/connection-manager/index.js +14 -0
- package/src/dialer/index.js +17 -1
- package/src/index.js +5 -3
- package/src/metrics/index.js +18 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/index.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/index.js"],"names":[],"mappings":";AAsCA;;;GAGG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;GAIG;AACH;IACE;;;;;;OAMG;IACH,oBAHW,MAAM,YACN,wBAAwB,EAqClC;IAhCC,uBAAqB;IACrB,gBAA0C;IAE1C,cAAqF;IAOrF;;;;OAIG;IACH,aAFU,IAAI,MAAM,EAAE,MAAM,CAAC,CAED;IAE5B;;;;OAIG;IACH,aAFU,IAAI,MAAM,EAAE,UAAU,EAAE,CAAC,CAEP;IAE5B,kBAAqB;IACrB,YAAkB;IAsFpB;;;;;OAKG;IACH,sBAcC;IAvGC,gCAGE;IAGJ;;OAEG;IACH,mBAGC;IAED;;;OAGG;IACH,cAYC;IAqKD;;;;;OAKG;IACH,0BAEC;IA3KD;;;;OAIG;IACH,sBASC;IAED;;;;OAIG;IACH,wBAaC;IAED;;;;;;;OAOG;IACH,qBAJW,MAAM,SACN,MAAM,GACJ,IAAI,CAOhB;IAwBD;;;;;OAKG;IACH,sBAHW,UAAU,GACR,IAAI,CAwBhB;IAED;;;;;OAKG;IACH,yBAHW,UAAU,GACR,IAAI,CAmBhB;IAED;;;;;OAKG;IACH,YAHW,MAAM,GACJ,UAAU,GAAC,IAAI,CAQ3B;IAED;;;;;OAKG;IACH,eAHW,MAAM,GACJ,UAAU,EAAE,CAexB;IAYD;;;;;;OAMG;IACH,uBAOC;IAED;;;;;OAKG;IACH,4BAiBC;CACF;;;;;;;;cApTY,OAAO,KAAK,CAAC"}
|
|
@@ -20,6 +20,7 @@ export = Dialer;
|
|
|
20
20
|
* @property {number} [maxDialsPerPeer = MAX_PER_PEER_DIALS] - Number of max concurrent dials per peer.
|
|
21
21
|
* @property {number} [dialTimeout = DIAL_TIMEOUT] - How long a dial attempt is allowed to take.
|
|
22
22
|
* @property {Record<string, Resolver>} [resolvers = {}] - multiaddr resolvers to use when dialing
|
|
23
|
+
* @property {import('../metrics')} [metrics]
|
|
23
24
|
*
|
|
24
25
|
* @typedef DialTarget
|
|
25
26
|
* @property {string} id
|
|
@@ -36,7 +37,7 @@ declare class Dialer {
|
|
|
36
37
|
* @class
|
|
37
38
|
* @param {DialerProperties & DialerOptions} options
|
|
38
39
|
*/
|
|
39
|
-
constructor({ transportManager, peerStore, addressSorter, maxParallelDials, maxAddrsToDial, dialTimeout, maxDialsPerPeer, resolvers }: DialerProperties & DialerOptions);
|
|
40
|
+
constructor({ transportManager, peerStore, addressSorter, maxParallelDials, maxAddrsToDial, dialTimeout, maxDialsPerPeer, resolvers, metrics }: DialerProperties & DialerOptions);
|
|
40
41
|
transportManager: import("../transport-manager");
|
|
41
42
|
peerStore: import("../peer-store");
|
|
42
43
|
addressSorter: (addresses: Address[]) => Address[];
|
|
@@ -47,6 +48,7 @@ declare class Dialer {
|
|
|
47
48
|
tokens: number[];
|
|
48
49
|
_pendingDials: Map<any, any>;
|
|
49
50
|
_pendingDialTargets: Map<any, any>;
|
|
51
|
+
_metrics: import("../metrics") | undefined;
|
|
50
52
|
/**
|
|
51
53
|
* Clears any pending dials
|
|
52
54
|
*/
|
|
@@ -156,6 +158,7 @@ type DialerOptions = {
|
|
|
156
158
|
* - multiaddr resolvers to use when dialing
|
|
157
159
|
*/
|
|
158
160
|
resolvers?: Record<string, Resolver> | undefined;
|
|
161
|
+
metrics?: import("../metrics") | undefined;
|
|
159
162
|
};
|
|
160
163
|
type PeerStore = import('../peer-store');
|
|
161
164
|
type Address = import('../peer-store/address-book').Address;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dialer/index.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dialer/index.js"],"names":[],"mappings":";AA4BA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH;IACE;;;OAGG;IACH,gJAFW,gBAAgB,GAAG,aAAa,EA4B1C;IAfC,iDAAwC;IACxC,mCAA0B;IAC1B,2BArCsB,OAAO,EAAE,KAAK,OAAO,EAAE,CAqCX;IAClC,yBAAwC;IACxC,uBAAoC;IACpC,gBAA0B;IAC1B,wBAAsC;IACtC,iBAAuE;IACvE,6BAA8B;IAC9B,mCAAoC;IACpC,2CAAuB;IAOzB;;OAEG;IACH,gBAiBC;IAED;;;;;;;;;OASG;IACH,oBALW,MAAM,GAAC,SAAS,GAAC,MAAM;;oBAGrB,QAAQ,UAAU,CAAC,CAwB/B;IAED;;;;;;;OAOG;IACH,mCAHW,MAAM,GAAC,SAAS,GAAC,MAAM,GACrB,QAAQ,UAAU,CAAC,CAqB/B;IAED;;;;;;;;;OASG;IACH,0BAmCC;IAED;;;;;;;;OAQG;IACH,2BAqCC;IAED;;OAEG;IACH,eAFW,MAAM,YAOhB;IAED;;OAEG;IACH,oBAFW,MAAM,QAOhB;IAED;;;;;OAKG;IACH,aAHW,SAAS,GACP,QAAQ,SAAS,EAAE,CAAC,CAwBhC;IAED;;;;;OAKG;IACH,mBAHW,SAAS,GACP,QAAQ,SAAS,EAAE,CAAC,CAWhC;CACF;;;;cAxTY,OAAO,SAAS,CAAC;;;;QAuBhB,MAAM;WACN,SAAS,EAAE;;;eAhBX,SAAS;sBACT,gBAAgB;;;;;;iCAKJ,OAAO,EAAE,KAAK,OAAO,EAAE;;;;;;;;;;;;;;;;;;;;;;;iBAbpC,OAAO,eAAe,CAAC;eACvB,OAAO,4BAA4B,EAAE,OAAO;wBAC5C,OAAO,sBAAsB,CAAC;uBAQxB,SAAS,KAAK,QAAQ,MAAM,EAAE,CAAC;;iBAgBpC,WAAW;gBACX,iBAAiB;aACjB,QAAQ,UAAU,CAAC;mBACR,IAAI"}
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":";AAqCA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH;IACE;;;;;;OAMG;IACH,uBAHW,aAAa,GAAG,aAAa,GAC3B,QAAQ,MAAM,CAAC,CAa3B;IAED;;;;;OAKG;IACH,sBAFW,aAAa,GAAG,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":"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"}
|
|
@@ -4,9 +4,6 @@ export = Metrics;
|
|
|
4
4
|
* @typedef {import('libp2p-interfaces/src/transport/types').MultiaddrConnection} MultiaddrConnection
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
|
-
* @typedef MetricsProperties
|
|
8
|
-
* @property {import('../connection-manager')} connectionManager
|
|
9
|
-
*
|
|
10
7
|
* @typedef MetricsOptions
|
|
11
8
|
* @property {number} [computeThrottleMaxQueueSize = defaultOptions.computeThrottleMaxQueueSize]
|
|
12
9
|
* @property {number} [computeThrottleTimeout = defaultOptions.computeThrottleTimeout]
|
|
@@ -25,9 +22,9 @@ declare class Metrics {
|
|
|
25
22
|
static mergeStats(target: Stats, other: Stats): Stats;
|
|
26
23
|
/**
|
|
27
24
|
* @class
|
|
28
|
-
* @param {
|
|
25
|
+
* @param {MetricsOptions} options
|
|
29
26
|
*/
|
|
30
|
-
constructor(options:
|
|
27
|
+
constructor(options: MetricsOptions);
|
|
31
28
|
_options: any;
|
|
32
29
|
_globalStats: Stats;
|
|
33
30
|
_peerStats: Map<any, any>;
|
|
@@ -48,7 +45,7 @@ declare class Metrics {
|
|
|
48
45
|
* @returns {void}
|
|
49
46
|
*/
|
|
50
47
|
private _onMessage;
|
|
51
|
-
|
|
48
|
+
_componentMetrics: Map<any, any>;
|
|
52
49
|
/**
|
|
53
50
|
* Must be called for stats to saved. Any data pushed for tracking
|
|
54
51
|
* will be ignored.
|
|
@@ -71,6 +68,11 @@ declare class Metrics {
|
|
|
71
68
|
* @returns {string[]}
|
|
72
69
|
*/
|
|
73
70
|
get peers(): string[];
|
|
71
|
+
/**
|
|
72
|
+
* @returns {Map}
|
|
73
|
+
*/
|
|
74
|
+
getComponentMetrics(): Map<any, any>;
|
|
75
|
+
updateComponentMetric(component: any, metric: any, value: any): void;
|
|
74
76
|
/**
|
|
75
77
|
* Returns the `Stats` object for the given `PeerId` whether it
|
|
76
78
|
* is a live peer, or in the disconnected peer LRU cache.
|
|
@@ -130,14 +132,11 @@ declare class Metrics {
|
|
|
130
132
|
}): MultiaddrConnection;
|
|
131
133
|
}
|
|
132
134
|
declare namespace Metrics {
|
|
133
|
-
export { PeerId, MultiaddrConnection,
|
|
135
|
+
export { PeerId, MultiaddrConnection, MetricsOptions };
|
|
134
136
|
}
|
|
135
137
|
import Stats = require("./stats");
|
|
136
138
|
type PeerId = import('peer-id');
|
|
137
139
|
type MultiaddrConnection = import('libp2p-interfaces/src/transport/types').MultiaddrConnection;
|
|
138
|
-
type MetricsProperties = {
|
|
139
|
-
connectionManager: import('../connection-manager');
|
|
140
|
-
};
|
|
141
140
|
type MetricsOptions = {
|
|
142
141
|
computeThrottleMaxQueueSize?: number | undefined;
|
|
143
142
|
computeThrottleTimeout?: number | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/metrics/index.js"],"names":[],"mappings":";AAoBA;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/metrics/index.js"],"names":[],"mappings":";AAoBA;;;GAGG;AAEH;;;;;;GAMG;AAEH;IAqOE;;;;;;;OAOG;IACH,0BAJW,KAAK,SACL,KAAK,GACH,KAAK,CAWjB;IArPD;;;OAGG;IACH,qBAFW,cAAc,EAWxB;IARC,cAAqD;IACrD,oBAA6D;IAC7D,0BAA2B;IAC3B,8BAA+B;IAC/B,eAA+D;IAC/D,kBAAqB;IA8GvB;;;;;;;;;;;;OAYG;IACH,mBAwBC;IAjJC,iCAAkC;IAGpC;;;OAGG;IACH,cAEC;IAED;;;OAGG;IACH,aASC;IAED;;;;OAIG;IACH,oBAEC;IAED;;;;OAIG;IACH,sBAEC;IAED;;OAEG;IACH,qCAEC;IAED,qEAOC;IAED;;;;;;OAMG;IACH,gBAHW,MAAM,GACJ,KAAK,CAKjB;IAED;;;;OAIG;IACH,0BAEC;IAED;;;;;OAKG;IACH,sBAHW,MAAM,GACJ,KAAK,CAIjB;IAED;;;;;;OAMG;IACH,2BAFW,MAAM,QAUhB;IAyCD;;;;;;;;OAQG;IACH,+BAJW,MAAM,UACN,MAAM,GACJ,IAAI,CAoBhB;IAED;;;;;;;;;;;;OAYG;IACH;QALwC,MAAM,EAAnC,mBAAmB;QACF,UAAU;QACV,QAAQ;QACvB,mBAAmB,CA2B/B;CAoBF;;;;;cAnQY,OAAO,SAAS,CAAC;2BACjB,OAAO,uCAAuC,EAAE,mBAAmB"}
|
package/package.json
CHANGED
|
@@ -32,6 +32,10 @@ const defaultOptions = {
|
|
|
32
32
|
defaultPeerValue: 1
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
const METRICS_COMPONENT = 'connection-manager'
|
|
36
|
+
const METRICS_PEER_CONNECTIONS = 'peer-connections'
|
|
37
|
+
const METRICS_ALL_CONNECTIONS = 'all-connections'
|
|
38
|
+
|
|
35
39
|
/**
|
|
36
40
|
* @typedef {import('../')} Libp2p
|
|
37
41
|
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
|
|
@@ -160,6 +164,8 @@ class ConnectionManager extends EventEmitter {
|
|
|
160
164
|
|
|
161
165
|
await Promise.all(tasks)
|
|
162
166
|
this.connections.clear()
|
|
167
|
+
this._libp2p.metrics && this._libp2p.metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PEER_CONNECTIONS, 0)
|
|
168
|
+
this._libp2p.metrics && this._libp2p.metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_ALL_CONNECTIONS, 0)
|
|
163
169
|
}
|
|
164
170
|
|
|
165
171
|
/**
|
|
@@ -211,10 +217,13 @@ class ConnectionManager extends EventEmitter {
|
|
|
211
217
|
const storedConn = this.connections.get(peerIdStr)
|
|
212
218
|
|
|
213
219
|
this.emit('peer:connect', connection)
|
|
220
|
+
|
|
214
221
|
if (storedConn) {
|
|
215
222
|
storedConn.push(connection)
|
|
216
223
|
} else {
|
|
217
224
|
this.connections.set(peerIdStr, [connection])
|
|
225
|
+
this._libp2p.metrics && this._libp2p.metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PEER_CONNECTIONS, this.connections.size)
|
|
226
|
+
this._libp2p.metrics && this._libp2p.metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_ALL_CONNECTIONS, this.size)
|
|
218
227
|
}
|
|
219
228
|
|
|
220
229
|
this._libp2p.peerStore.keyBook.set(peerId, peerId.pubKey)
|
|
@@ -243,7 +252,12 @@ class ConnectionManager extends EventEmitter {
|
|
|
243
252
|
this.connections.delete(peerId)
|
|
244
253
|
this._peerValues.delete(connection.remotePeer.toB58String())
|
|
245
254
|
this.emit('peer:disconnect', connection)
|
|
255
|
+
|
|
256
|
+
this._libp2p.metrics && this._libp2p.metrics.onPeerDisconnected(connection.remotePeer)
|
|
246
257
|
}
|
|
258
|
+
|
|
259
|
+
this._libp2p.metrics && this._libp2p.metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PEER_CONNECTIONS, this.connections.size)
|
|
260
|
+
this._libp2p.metrics && this._libp2p.metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_ALL_CONNECTIONS, this.size)
|
|
247
261
|
}
|
|
248
262
|
|
|
249
263
|
/**
|
package/src/dialer/index.js
CHANGED
|
@@ -22,6 +22,10 @@ const {
|
|
|
22
22
|
MAX_ADDRS_TO_DIAL
|
|
23
23
|
} = require('../constants')
|
|
24
24
|
|
|
25
|
+
const METRICS_COMPONENT = 'dialler'
|
|
26
|
+
const METRICS_PENDING_DIALS = 'pending-dials'
|
|
27
|
+
const METRICS_PENDING_DIAL_TARGETS = 'pending-dials-targers'
|
|
28
|
+
|
|
25
29
|
/**
|
|
26
30
|
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
|
|
27
31
|
* @typedef {import('peer-id')} PeerId
|
|
@@ -44,6 +48,7 @@ const {
|
|
|
44
48
|
* @property {number} [maxDialsPerPeer = MAX_PER_PEER_DIALS] - Number of max concurrent dials per peer.
|
|
45
49
|
* @property {number} [dialTimeout = DIAL_TIMEOUT] - How long a dial attempt is allowed to take.
|
|
46
50
|
* @property {Record<string, Resolver>} [resolvers = {}] - multiaddr resolvers to use when dialing
|
|
51
|
+
* @property {import('../metrics')} [metrics]
|
|
47
52
|
*
|
|
48
53
|
* @typedef DialTarget
|
|
49
54
|
* @property {string} id
|
|
@@ -69,7 +74,8 @@ class Dialer {
|
|
|
69
74
|
maxAddrsToDial = MAX_ADDRS_TO_DIAL,
|
|
70
75
|
dialTimeout = DIAL_TIMEOUT,
|
|
71
76
|
maxDialsPerPeer = MAX_PER_PEER_DIALS,
|
|
72
|
-
resolvers = {}
|
|
77
|
+
resolvers = {},
|
|
78
|
+
metrics
|
|
73
79
|
}) {
|
|
74
80
|
this.transportManager = transportManager
|
|
75
81
|
this.peerStore = peerStore
|
|
@@ -81,6 +87,7 @@ class Dialer {
|
|
|
81
87
|
this.tokens = [...new Array(maxParallelDials)].map((_, index) => index)
|
|
82
88
|
this._pendingDials = new Map()
|
|
83
89
|
this._pendingDialTargets = new Map()
|
|
90
|
+
this._metrics = metrics
|
|
84
91
|
|
|
85
92
|
for (const [key, value] of Object.entries(resolvers)) {
|
|
86
93
|
Multiaddr.resolvers.set(key, value)
|
|
@@ -104,6 +111,9 @@ class Dialer {
|
|
|
104
111
|
pendingTarget.reject(new AbortError('Dialer was destroyed'))
|
|
105
112
|
}
|
|
106
113
|
this._pendingDialTargets.clear()
|
|
114
|
+
|
|
115
|
+
this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIALS, 0)
|
|
116
|
+
this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIAL_TARGETS, 0)
|
|
107
117
|
}
|
|
108
118
|
|
|
109
119
|
/**
|
|
@@ -153,6 +163,7 @@ class Dialer {
|
|
|
153
163
|
const id = `${(parseInt(String(Math.random() * 1e9), 10)).toString() + Date.now()}`
|
|
154
164
|
const cancellablePromise = new Promise((resolve, reject) => {
|
|
155
165
|
this._pendingDialTargets.set(id, { resolve, reject })
|
|
166
|
+
this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIAL_TARGETS, this._pendingDialTargets.size)
|
|
156
167
|
})
|
|
157
168
|
|
|
158
169
|
try {
|
|
@@ -164,6 +175,7 @@ class Dialer {
|
|
|
164
175
|
return dialTarget
|
|
165
176
|
} finally {
|
|
166
177
|
this._pendingDialTargets.delete(id)
|
|
178
|
+
this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIAL_TARGETS, this._pendingDialTargets.size)
|
|
167
179
|
}
|
|
168
180
|
}
|
|
169
181
|
|
|
@@ -252,9 +264,13 @@ class Dialer {
|
|
|
252
264
|
destroy: () => {
|
|
253
265
|
timeoutController.clear()
|
|
254
266
|
this._pendingDials.delete(dialTarget.id)
|
|
267
|
+
this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIALS, this._pendingDials.size)
|
|
255
268
|
}
|
|
256
269
|
}
|
|
257
270
|
this._pendingDials.set(dialTarget.id, pendingDial)
|
|
271
|
+
|
|
272
|
+
this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIALS, this._pendingDials.size)
|
|
273
|
+
|
|
258
274
|
return pendingDial
|
|
259
275
|
}
|
|
260
276
|
|
package/src/index.js
CHANGED
|
@@ -197,10 +197,11 @@ class Libp2p extends EventEmitter {
|
|
|
197
197
|
|
|
198
198
|
// Create Metrics
|
|
199
199
|
if (this._options.metrics.enabled) {
|
|
200
|
-
|
|
201
|
-
...this._options.metrics
|
|
202
|
-
connectionManager: this.connectionManager
|
|
200
|
+
const metrics = new Metrics({
|
|
201
|
+
...this._options.metrics
|
|
203
202
|
})
|
|
203
|
+
|
|
204
|
+
this.metrics = metrics
|
|
204
205
|
}
|
|
205
206
|
|
|
206
207
|
// Create keychain
|
|
@@ -262,6 +263,7 @@ class Libp2p extends EventEmitter {
|
|
|
262
263
|
this.dialer = new Dialer({
|
|
263
264
|
transportManager: this.transportManager,
|
|
264
265
|
peerStore: this.peerStore,
|
|
266
|
+
metrics: this.metrics,
|
|
265
267
|
...this._options.dialer
|
|
266
268
|
})
|
|
267
269
|
|
package/src/metrics/index.js
CHANGED
|
@@ -24,9 +24,6 @@ const directionToEvent = {
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* @typedef MetricsProperties
|
|
28
|
-
* @property {import('../connection-manager')} connectionManager
|
|
29
|
-
*
|
|
30
27
|
* @typedef MetricsOptions
|
|
31
28
|
* @property {number} [computeThrottleMaxQueueSize = defaultOptions.computeThrottleMaxQueueSize]
|
|
32
29
|
* @property {number} [computeThrottleTimeout = defaultOptions.computeThrottleTimeout]
|
|
@@ -37,7 +34,7 @@ const directionToEvent = {
|
|
|
37
34
|
class Metrics {
|
|
38
35
|
/**
|
|
39
36
|
* @class
|
|
40
|
-
* @param {
|
|
37
|
+
* @param {MetricsOptions} options
|
|
41
38
|
*/
|
|
42
39
|
constructor (options) {
|
|
43
40
|
this._options = mergeOptions(defaultOptions, options)
|
|
@@ -47,10 +44,7 @@ class Metrics {
|
|
|
47
44
|
this._oldPeers = oldPeerLRU(this._options.maxOldPeersRetention)
|
|
48
45
|
this._running = false
|
|
49
46
|
this._onMessage = this._onMessage.bind(this)
|
|
50
|
-
this.
|
|
51
|
-
this._connectionManager.on('peer:disconnect', (connection) => {
|
|
52
|
-
this.onPeerDisconnected(connection.remotePeer)
|
|
53
|
-
})
|
|
47
|
+
this._componentMetrics = new Map()
|
|
54
48
|
}
|
|
55
49
|
|
|
56
50
|
/**
|
|
@@ -94,6 +88,22 @@ class Metrics {
|
|
|
94
88
|
return Array.from(this._peerStats.keys())
|
|
95
89
|
}
|
|
96
90
|
|
|
91
|
+
/**
|
|
92
|
+
* @returns {Map}
|
|
93
|
+
*/
|
|
94
|
+
getComponentMetrics () {
|
|
95
|
+
return this._componentMetrics
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
updateComponentMetric (component, metric, value) {
|
|
99
|
+
if (!this._componentMetrics.has(component)) {
|
|
100
|
+
this._componentMetrics.set(component, new Map())
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const map = this._componentMetrics.get(component)
|
|
104
|
+
map.set(metric, value)
|
|
105
|
+
}
|
|
106
|
+
|
|
97
107
|
/**
|
|
98
108
|
* Returns the `Stats` object for the given `PeerId` whether it
|
|
99
109
|
* is a live peer, or in the disconnected peer LRU cache.
|