Skip to content

Commit

Permalink
add counter for peers with colliding bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
shyba committed Dec 14, 2021
1 parent 31978c7 commit 41e1368
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lbry/dht/protocol/routing_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import typing
import itertools

from prometheus_client import Gauge
from prometheus_client import Gauge, Counter

from lbry.dht import constants
from lbry.dht.protocol.distance import Distance
Expand All @@ -22,6 +22,10 @@ class KBucket:
"peers_in_routing_table", "Number of peers on routing table", namespace="dht_node",
labelnames=("scope",)
)
peer_with_x_byte_colliding_metric = Counter(
"peer_x_byte_colliding", "Number of peers with at least X bytes colliding with this node id",
namespace="dht_node", labelnames=("amount",)
)

def __init__(self, peer_manager: 'PeerManager', range_min: int, range_max: int, node_id: bytes):
"""
Expand Down Expand Up @@ -66,6 +70,9 @@ def add_peer(self, peer: 'KademliaPeer') -> bool:
if len(self.peers) < constants.K:
self.peers.append(peer)
self.peer_in_routing_table_metric.labels("global").inc()
if self._node_id[0] == peer.node_id[0]:
amount = 2 if self._node_id[1] == peer.node_id[1] else 1
self.peer_with_x_byte_colliding_metric.labels(amount=amount).inc()
return True
else:
return False
Expand Down

0 comments on commit 41e1368

Please sign in to comment.