@@ -38,6 +38,9 @@ export class Poller {
3838 private latestBlock ?: string ;
3939 private pollingInterval : number ;
4040 private activePollsGauge : Gauge ;
41+ private activeNewHeadsPollsGauge : Gauge ;
42+
43+ private NEW_HEADS_EVENT = 'newHeads' ;
4144
4245 constructor ( eth : Eth , logger : Logger , register : Registry ) {
4346 this . eth = eth ;
@@ -52,6 +55,14 @@ export class Poller {
5255 help : 'Relay websocket active polls count' ,
5356 registers : [ register ] ,
5457 } ) ;
58+
59+ const activeNewHeadsPollsGaugeName = 'rpc_websocket_active_newheads_polls' ;
60+ register . removeSingleMetric ( activeNewHeadsPollsGaugeName ) ;
61+ this . activeNewHeadsPollsGauge = new Gauge ( {
62+ name : activeNewHeadsPollsGaugeName ,
63+ help : 'Relay websocket active newHeads polls count' ,
64+ registers : [ register ] ,
65+ } ) ;
5566 }
5667
5768 public poll ( ) {
@@ -72,7 +83,7 @@ export class Poller {
7283 ) ;
7384
7485 poll . lastPolled = this . latestBlock ;
75- } else if ( event === 'newHeads' && process . env . WS_NEW_HEADS_ENABLED === 'true' ) {
86+ } else if ( event === this . NEW_HEADS_EVENT && process . env . WS_NEW_HEADS_ENABLED === 'true' ) {
7687 data = await this . eth . getBlockByNumber ( 'latest' , true ) ;
7788 data . jsonrpc = '2.0' ;
7889 poll . lastPolled = this . latestBlock ;
@@ -120,7 +131,11 @@ export class Poller {
120131 tag,
121132 callback,
122133 } ) ;
123- this . activePollsGauge . inc ( ) ;
134+ if ( JSON . parse ( tag ) . event === this . NEW_HEADS_EVENT ) {
135+ this . activeNewHeadsPollsGauge . inc ( ) ;
136+ } else {
137+ this . activePollsGauge . inc ( ) ;
138+ }
124139 }
125140
126141 if ( ! this . isPolling ( ) ) {
@@ -135,7 +150,11 @@ export class Poller {
135150
136151 const pollsRemoved = pollsAtStart - this . polls . length ;
137152 if ( pollsRemoved > 0 ) {
138- this . activePollsGauge . dec ( pollsRemoved ) ;
153+ if ( JSON . parse ( tag ) . event === this . NEW_HEADS_EVENT ) {
154+ this . activeNewHeadsPollsGauge . dec ( pollsRemoved ) ;
155+ } else {
156+ this . activePollsGauge . dec ( pollsRemoved ) ;
157+ }
139158 }
140159
141160 if ( ! this . polls . length ) {
0 commit comments