Skip to content

Commit dbca8c7

Browse files
author
ScottyPoi
committed
metrics: uTP streams opened
1 parent ca62130 commit dbca8c7

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

packages/portalnetwork/src/util/metrics.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,27 @@ const ultralightMetrics = [
7979
metric: MetricType.Counter,
8080
help: 'how many UTP packets have been received',
8181
},
82+
{
83+
name: 'utpStreamsTotal',
84+
metric: MetricType.Gauge,
85+
help: 'how many total UTP streams were opened',
86+
},
87+
{
88+
name: 'utpWriteStreams',
89+
metric: MetricType.Gauge,
90+
help: 'how many UTP write streams were opened',
91+
},
92+
{
93+
name: 'utpReadStreams',
94+
metric: MetricType.Gauge,
95+
help: 'how many UTP read streams were opened',
96+
},
8297
]
8398

8499
export const setupMetrics = (
85100
networks: NetworkId[] = [NetworkId.HistoryNetwork],
86101
): PortalNetworkMetrics => {
87-
const metrics = createMetrics(ultralightMetrics, [...networks, NetworkId.UTPNetwork])
102+
const metrics = createMetrics(ultralightMetrics, [...networks])
88103
return {
89104
...metrics,
90105
totalContentLookups: new Gauge<string>({

packages/portalnetwork/src/wire/utp/PortalNetworkUtp/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,23 @@ export class PortalNetworkUTP {
9090

9191
async handleNewRequest(params: INewRequest): Promise<ContentRequestType> {
9292
const { contentKeys, enr, connectionId, requestCode } = params
93+
if (this.client.metrics) {
94+
const utpMetric = (NetworkNames[params.networkId] +
95+
'_utpStreamsTotal') as keyof PortalNetworkMetrics
96+
this.client.metrics[utpMetric].inc()
97+
if (
98+
requestCode === RequestCode.FOUNDCONTENT_WRITE ||
99+
requestCode === RequestCode.OFFER_WRITE
100+
) {
101+
const utpWriteMetric = (NetworkNames[params.networkId] +
102+
'_utpWriteStreams') as keyof PortalNetworkMetrics
103+
this.client.metrics[utpWriteMetric].inc()
104+
} else {
105+
const utpReadMetric = (NetworkNames[params.networkId] +
106+
'_utpReadStreams') as keyof PortalNetworkMetrics
107+
this.client.metrics[utpReadMetric].inc()
108+
}
109+
}
93110
if (this.requestManagers[enr.nodeId] === undefined) {
94111
this.requestManagers[enr.nodeId] = new RequestManager(enr.nodeId, this.logger)
95112
}

0 commit comments

Comments
 (0)