diff --git a/src/index.ts b/src/index.ts index 74c545f2..e27aae09 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2043,6 +2043,7 @@ export class GossipSub extends EventEmitter implements PubSub { + const startMs = Date.now() const transformedData = this.dataTransform ? this.dataTransform.outboundTransform(topic, data) : data if (this.publishConfig == null) { @@ -2099,7 +2100,14 @@ export class GossipSub extends EventEmitter implements PubSub({ + name: 'gossipsub_msg_publish_ms', + help: 'Total time in millisecond to publish a message', + buckets: [1, 2, 5, 10, 100, 500, 1000], + labelNames: ['topic'] + }), /** Total count of msg forwarded by topic */ msgForwardCount: register.gauge<{ topic: TopicLabel }>({ @@ -683,7 +690,13 @@ export function getMetrics( this.msgForwardPeers.inc({ topic }, tosendCount) }, - onPublishMsg(topicStr: TopicStr, tosendGroupCount: ToSendGroupCount, tosendCount: number, dataLen: number): void { + onPublishMsg( + topicStr: TopicStr, + tosendGroupCount: ToSendGroupCount, + tosendCount: number, + dataLen: number, + ms: number + ): void { const topic = this.toTopic(topicStr) this.msgPublishCount.inc({ topic }, 1) this.msgPublishBytes.inc({ topic }, tosendCount * dataLen) @@ -692,6 +705,7 @@ export function getMetrics( this.msgPublishPeersByGroup.inc({ peerGroup: 'floodsub' }, tosendGroupCount.floodsub) this.msgPublishPeersByGroup.inc({ peerGroup: 'mesh' }, tosendGroupCount.mesh) this.msgPublishPeersByGroup.inc({ peerGroup: 'fanout' }, tosendGroupCount.fanout) + this.msgPublishMs.observe({ topic }, ms) }, onMsgRecvPreValidation(topicStr: TopicStr): void {