Skip to content

Commit

Permalink
metrics: add metric for talkReq and talkResp sent
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottyPoi committed Nov 2, 2024
1 parent 5d714e9 commit 5a4f3a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/portalnetwork/src/networks/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,18 @@ export abstract class BaseNetwork extends EventEmitter {
networkId: NetworkId,
utpMessage?: boolean,
): Promise<Uint8Array> {
if (this.portal.metrics) {
const metric = (this.networkName + '_talkRequestsSent') as keyof PortalNetworkMetrics
this.portal.metrics[metric].inc()
}
return this.portal.sendPortalNetworkMessage(enr, payload, networkId, utpMessage)
}

sendResponse(src: INodeAddress, requestId: bigint, payload: Uint8Array): Promise<void> {
if (this.portal.metrics) {
const metric = (this.networkName + '_talkResponsesSent') as keyof PortalNetworkMetrics
this.portal.metrics[metric].inc()
}
return this.portal.sendPortalNetworkResponse(src, requestId, payload)
}
findEnr(nodeId: string): ENR | undefined {
Expand Down
14 changes: 12 additions & 2 deletions packages/portalnetwork/src/util/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,25 @@ const createMetrics = (metrics: MetricParams[], networks: NetworkId[]) => {

const ultralightMetrics = [
{
metric: MetricType.Gauge,
name: 'peers',
metric: MetricType.Gauge,
help: 'how many peers are in the routing table',
},
{
metric: MetricType.Gauge,
name: 'dbSize',
metric: MetricType.Gauge,
help: 'how many MBs are currently stored in the db',
},
{
name: 'talkRequestsSent',
metric: MetricType.Counter,
help: 'how many talk requests have been sent',
},
{
name: 'talkResponsesReceived',
metric: MetricType.Counter,
help: 'how many talk responses have been sent',
},
]

export const setupMetrics = (
Expand Down

0 comments on commit 5a4f3a5

Please sign in to comment.