add metrics for sent messages by topic and peer (#220)

This commit is contained in:
Dmitriy Ryajov 2020-06-15 17:39:03 -06:00 committed by GitHub
parent 3c4c10d871
commit 9d9f793b4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 6 deletions

View File

@ -22,8 +22,8 @@ import rpc/[messages, message, protobuf],
logScope: logScope:
topics = "pubsubpeer" topics = "pubsubpeer"
declareCounter(libp2p_pubsub_sent_messages, "number of messages sent", labels = ["id"]) declareCounter(libp2p_pubsub_sent_messages, "number of messages sent", labels = ["id", "topic"])
declareCounter(libp2p_pubsub_received_messages, "number of messages received", labels = ["id"]) declareCounter(libp2p_pubsub_received_messages, "number of messages received", labels = ["id", "topic"])
declareCounter(libp2p_pubsub_skipped_messages, "number of skipped messages", labels = ["id"]) declareCounter(libp2p_pubsub_skipped_messages, "number of skipped messages", labels = ["id"])
type type
@ -87,8 +87,10 @@ proc handle*(p: PubSubPeer, conn: Connection) {.async.} =
# trigger hooks # trigger hooks
p.recvObservers(msg) p.recvObservers(msg)
# metrics for m in msg.messages:
libp2p_pubsub_received_messages.inc(labelValues = [p.id]) for t in m.topicIDs:
# metrics
libp2p_pubsub_received_messages.inc(labelValues = [p.id, t])
await p.handler(p, @[msg]) await p.handler(p, @[msg])
p.recvdRpcCache.put(digest) p.recvdRpcCache.put(digest)
@ -128,8 +130,12 @@ proc send*(p: PubSubPeer, msgs: seq[RPCMsg]) {.async.} =
await p.sendConn.writeLp(encoded.buffer) await p.sendConn.writeLp(encoded.buffer)
p.sentRpcCache.put(digest) p.sentRpcCache.put(digest)
# metrics for m in msgs:
libp2p_pubsub_sent_messages.inc(labelValues = [p.id]) for mm in m.messages:
for t in mm.topicIDs:
# metrics
libp2p_pubsub_sent_messages.inc(labelValues = [p.id, t])
except CatchableError as exc: except CatchableError as exc:
trace "unable to send to remote", exc = exc.msg trace "unable to send to remote", exc = exc.msg
p.sendConn = nil p.sendConn = nil