@@ -23,9 +23,31 @@ import
2323from ../ waku_core/ codecs import WakuRelayCodec
2424export WakuRelayCodec
2525
26+ type ShardMetrics = object
27+ count: float64
28+ sizeSum: float64
29+ avgSize: float64
30+ maxSize: float64
31+
2632logScope:
2733 topics = " waku relay"
2834
35+ declareCounter waku_relay_network_bytes,
36+ " total traffic per topic, distinct gross/net and direction" ,
37+ labels = [" topic" , " type" , " direction" ]
38+
39+ declarePublicGauge (
40+ waku_relay_max_msg_bytes_per_shard,
41+ " Maximum length of messages seen per shard" ,
42+ labels = [" shard" ],
43+ )
44+
45+ declarePublicGauge (
46+ waku_relay_avg_msg_bytes_per_shard,
47+ " Average length of messages seen per shard" ,
48+ labels = [" shard" ],
49+ )
50+
2951# see: https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.1.md#overview-of-new-parameters
3052const TopicParameters = TopicParams (
3153 topicWeight: 1 ,
@@ -58,10 +80,6 @@ const TopicParameters = TopicParams(
5880 invalidMessageDeliveriesDecay: 0.5 ,
5981)
6082
61- declareCounter waku_relay_network_bytes,
62- " total traffic per topic, distinct gross/net and direction" ,
63- labels = [" topic" , " type" , " direction" ]
64-
6583# see: https://rfc.vac.dev/spec/29/#gossipsub-v10-parameters
6684const GossipsubParameters = GossipSubParams .init (
6785 pruneBackoff = chronos.minutes (1 ),
137155 topicsHealth* : Table [string , TopicHealth ]
138156 onTopicHealthChange* : TopicHealthChangeHandler
139157 topicHealthLoopHandle* : Future [void ]
158+ msgMetricsPerShard* : Table [string , ShardMetrics ]
140159
141160# predefinition for more detailed results from publishing new message
142161type PublishOutcome * {.pure .} = enum
@@ -176,6 +195,7 @@ proc logMessageInfo*(
176195 onRecv: bool ,
177196) =
178197 let msg_hash = computeMessageHash (topic, msg).to0xHex ()
198+ let payloadSize = float64 (msg.payload.len)
179199
180200 if onRecv:
181201 notice " received relay message" ,
@@ -185,7 +205,7 @@ proc logMessageInfo*(
185205 from_peer_id = remotePeerId,
186206 topic = topic,
187207 receivedTime = getNowInNanosecondTime (),
188- payloadSizeBytes = msg.payload.len
208+ payloadSizeBytes = payloadSize
189209 else :
190210 notice " sent relay message" ,
191211 my_peer_id = w.switch.peerInfo.peerId,
@@ -194,7 +214,19 @@ proc logMessageInfo*(
194214 to_peer_id = remotePeerId,
195215 topic = topic,
196216 sentTime = getNowInNanosecondTime (),
197- payloadSizeBytes = msg.payload.len
217+ payloadSizeBytes = payloadSize
218+
219+ var shardMetrics = w.msgMetricsPerShard.getOrDefault (topic, ShardMetrics ())
220+ shardMetrics.count += 1
221+ shardMetrics.sizeSum += payloadSize
222+ if payloadSize > shardMetrics.maxSize:
223+ shardMetrics.maxSize = payloadSize
224+ shardMetrics.avgSize = shardMetrics.sizeSum / shardMetrics.count
225+ w.msgMetricsPerShard[topic] = shardMetrics
226+
227+ waku_relay_max_msg_bytes_per_shard.set (shardMetrics.maxSize, labelValues = [topic])
228+
229+ waku_relay_avg_msg_bytes_per_shard.set (shardMetrics.avgSize, labelValues = [topic])
198230
199231proc initRelayObservers (w: WakuRelay ) =
200232 proc decodeRpcMessageInfo (
0 commit comments