File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
packages/portalnetwork/src/client Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import { HistoryNetwork } from '../networks/history/history.js'
11
11
import {
12
12
BeaconLightClientNetwork ,
13
13
NetworkId ,
14
+ NetworkNames ,
14
15
StateNetwork ,
15
16
SyncStrategy ,
16
17
} from '../networks/index.js'
@@ -30,6 +31,7 @@ import type { ITalkReqMessage, ITalkRespMessage } from '@chainsafe/discv5/messag
30
31
import type { NodeId } from '@chainsafe/enr'
31
32
import type { Multiaddr } from '@multiformats/multiaddr'
32
33
import type { Debugger } from 'debug'
34
+ import type * as PromClient from 'prom-client'
33
35
34
36
export class PortalNetwork extends ( EventEmitter as { new ( ) : PortalNetworkEventEmitter } ) {
35
37
eventLog : boolean
@@ -288,6 +290,12 @@ export class PortalNetwork extends (EventEmitter as { new (): PortalNetworkEvent
288
290
}
289
291
network . startRefresh ( )
290
292
await network . prune ( )
293
+ if ( this . metrics ) {
294
+ network . on ( 'ContentAdded' , async ( ) => {
295
+ const metric = ( NetworkNames [ network . networkId ] + '_dbSize' ) as keyof PortalNetworkMetrics
296
+ ; ( < PromClient . Gauge > this . metrics ! [ metric ] ) . set ( await network . db . size ( ) )
297
+ } )
298
+ }
291
299
}
292
300
void this . bootstrap ( )
293
301
}
@@ -318,6 +326,7 @@ export class PortalNetwork extends (EventEmitter as { new (): PortalNetworkEvent
318
326
await this . db . close ( )
319
327
for ( const network of this . networks . values ( ) ) {
320
328
network . stopRefresh ( )
329
+ network . removeAllListeners ( )
321
330
}
322
331
}
323
332
You can’t perform that action at this time.
0 commit comments