From 2c4af77f5f7231b560c344ccaff3cc73f0d616e9 Mon Sep 17 00:00:00 2001 From: Jesper Jensen Date: Sun, 4 May 2025 00:39:13 +0200 Subject: Refactor lookup init and add routing table metric I think it would be nice to see the detailed routing table occupancy. I've added a metric that exposes the current occupancy of each bucket. That should provide me some insight into the current distribution of nodes and if we need to find a way to keep the closer buckets alive. --- src/routing.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/routing.c') diff --git a/src/routing.c b/src/routing.c index edffffc..7c10e16 100644 --- a/src/routing.c +++ b/src/routing.c @@ -8,7 +8,9 @@ #include #include #include +#include #include +#include // The DHT routing table has a keyspace of 0 -- 2^160 split into buckets of 8. // When a bucket becomes full, we split it in half. As we further expand the @@ -56,6 +58,24 @@ void routing_init(struct nodeid* myid) { routing_flush(); } +void routing_update_metrics() { + char buf[4]; // Largest value is 157 + \0 + + struct entry *entry = pTable->table; + for(uint8_t i = 0; i < RT_IDBITS-RT_BBITS; i++) { + sprintf(buf, "%d", i); + + uint8_t filled = 0; + for(uint8_t j = 0; j < RT_BSIZE; j++) { + filled += entry->set; + entry++; + } + + prom_gauge_set(routing_table_occupied, filled, (const char*[]){buf}); + } + dbg("Update metrics!!"); +} + void routing_flush() { memset(pTable->table, 0, sizeof(pTable->table)); } @@ -159,6 +179,7 @@ void routing_remove(struct nodeid* id) { entry->set = false; entry->expire = 0; + routing_update_metrics(); } bool routing_interested(struct nodeid* id) { @@ -295,3 +316,4 @@ void routing_status(int* filled, int* size, double* load_factor, size_t load_fac load_factor[i] /= per_bucket + is_overflow; } } + -- cgit v1.2.3