add passive estimation to prometheus

This commit is contained in:
Victor Shyba 2021-12-06 11:40:35 -03:00
parent 5ebcbc6370
commit 32b95fa04a

View file

@ -24,6 +24,10 @@ PEERS = Gauge(
"known_peers", "Number of peers on routing table", namespace="dht_node",
labelnames=("method",)
)
ESTIMATED_SIZE = Gauge(
"passively_estimated_network_size", "Estimated network size from routing table", namespace="dht_node",
labelnames=("method",)
)
class SimpleMetrics:
@ -126,6 +130,9 @@ async def main(host: str, port: int, db_file_path: str, bootstrap_node: Optional
while True:
await asyncio.sleep(10)
PEERS.labels('main').set(len(node.protocol.routing_table.get_peers()))
peers = node.protocol.routing_table.get_peers()
close_ids = [peer for peer in peers if peer.node_id[0] == node.protocol.node_id[0]]
ESTIMATED_SIZE.labels('main').set(len(close_ids) * 256)
BLOBS_STORED.labels('main').set(len(node.protocol.data_store.get_storing_contacts()))
log.info("Known peers: %d. Storing contact information for %d blobs from %d peers.",
len(node.protocol.routing_table.get_peers()), len(node.protocol.data_store),