count published messages (#224)

This commit is contained in:
Dmitriy Ryajov 2020-06-16 22:14:02 -06:00 committed by GitHub
parent 224c2613e3
commit fe828d87d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 0 deletions

View File

@ -92,6 +92,7 @@ method rpcHandler*(f: FloodSub,
for p in toSendPeers:
if p in f.peers and f.peers[p].id != peer.id:
sent.add(f.peers[p].send(@[RPCMsg(messages: m.messages)]))
# wait for all the futures now
sent = await allFinished(sent)
checkFutures(sent)
@ -133,10 +134,13 @@ method publish*(f: FloodSub,
for p in f.floodsub[topic]:
trace "publishing message", name = topic, peer = p, data = data.shortLog
sent.add(f.peers[p].send(@[RPCMsg(messages: @[msg])]))
# wait for all the futures now
sent = await allFinished(sent)
checkFutures(sent)
libp2p_pubsub_messages_published.inc(labelValues = [topic])
method unsubscribe*(f: FloodSub,
topics: seq[TopicPair]) {.async.} =
await procCall PubSub(f).unsubscribe(topics)

View File

@ -480,6 +480,8 @@ method publish*(g: GossipSub,
sent.add(g.peers[p].send(@[RPCMsg(messages: @[msg])]))
checkFutures(await allFinished(sent))
libp2p_pubsub_messages_published.inc(labelValues = [topic])
method start*(g: GossipSub) {.async.} =
## start pubsub
## start long running/repeating procedures

View File

@ -26,6 +26,7 @@ declareGauge(libp2p_pubsub_peers, "pubsub peer instances")
declareGauge(libp2p_pubsub_topics, "pubsub subscribed topics")
declareCounter(libp2p_pubsub_validation_success, "pubsub successfully validated messages")
declareCounter(libp2p_pubsub_validation_failure, "pubsub failed validated messages")
declarePublicCounter(libp2p_pubsub_messages_published, "published messages", labels = ["topic"])
declareGauge(libp2p_pubsub_peers_per_topic, "pubsub peers per topic", labels = ["topic"])
type

View File

@ -12,6 +12,7 @@ import chronos, chronicles, metrics
import connection,
transports/transport,
multistream,
multiaddress,
protocols/protocol,
protocols/secure/secure,
protocols/secure/plaintext, # for plain text