From ae3e8fadf56ddeda6fdb97061baa776499afe8ab Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Mon, 24 Jan 2022 10:54:19 -0300 Subject: [PATCH 1/2] count announcements and how many peers we were able to announce to --- lbry/dht/blob_announcer.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lbry/dht/blob_announcer.py b/lbry/dht/blob_announcer.py index 5d977aff4..df667bc6d 100644 --- a/lbry/dht/blob_announcer.py +++ b/lbry/dht/blob_announcer.py @@ -1,6 +1,9 @@ import asyncio import typing import logging + +from prometheus_client import Counter + if typing.TYPE_CHECKING: from lbry.dht.node import Node from lbry.extras.daemon.storage import SQLiteStorage @@ -9,6 +12,11 @@ log = logging.getLogger(__name__) class BlobAnnouncer: + announcements_sent_metric = Counter( + "announcements_sent", "Number of announcements sent and their respective status.", namespace="dht_node", + labelnames=("peers", "error"), + ) + def __init__(self, loop: asyncio.AbstractEventLoop, node: 'Node', storage: 'SQLiteStorage'): self.loop = loop self.node = node @@ -18,12 +26,15 @@ class BlobAnnouncer: async def _submit_announcement(self, blob_hash): try: + peers = len(await self.node.announce_blob(blob_hash)) + self.announcements_sent_metric.labels(peers=peers, error=False).inc() if peers > 4: return blob_hash else: log.debug("failed to announce %s, could only find %d peers, retrying soon.", blob_hash[:8], peers) except Exception as err: + self.announcements_sent_metric.labels(peers=0, error=True).inc() if isinstance(err, asyncio.CancelledError): # TODO: remove when updated to 3.8 raise err log.warning("error announcing %s: %s", blob_hash[:8], str(err)) From c9d637b4da32fa919c4f19c06aff8ab5537bede5 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Mon, 24 Jan 2022 11:20:48 -0300 Subject: [PATCH 2/2] add gauge for queue size --- lbry/dht/blob_announcer.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lbry/dht/blob_announcer.py b/lbry/dht/blob_announcer.py index df667bc6d..24cf18bbe 100644 --- a/lbry/dht/blob_announcer.py +++ b/lbry/dht/blob_announcer.py @@ -2,7 +2,7 @@ import asyncio import typing import logging -from prometheus_client import Counter +from prometheus_client import Counter, Gauge if typing.TYPE_CHECKING: from lbry.dht.node import Node @@ -16,6 +16,10 @@ class BlobAnnouncer: "announcements_sent", "Number of announcements sent and their respective status.", namespace="dht_node", labelnames=("peers", "error"), ) + announcement_queue_size_metric = Gauge( + "announcement_queue_size", "Number of hashes waiting to be announced.", namespace="dht_node", + labelnames=("scope",) + ) def __init__(self, loop: asyncio.AbstractEventLoop, node: 'Node', storage: 'SQLiteStorage'): self.loop = loop @@ -48,6 +52,7 @@ class BlobAnnouncer: log.warning("No peers in DHT, announce round skipped") continue self.announce_queue.extend(await self.storage.get_blobs_to_announce()) + self.announcement_queue_size_metric.labels(scope="global").set(len(self.announce_queue)) log.debug("announcer task wake up, %d blobs to announce", len(self.announce_queue)) while len(self.announce_queue) > 0: log.info("%i blobs to announce", len(self.announce_queue))