From 95d03b842f6fdbfda19ed050131bc95ece13a171 Mon Sep 17 00:00:00 2001 From: Jesper Jensen Date: Mon, 14 Apr 2025 12:22:20 +0200 Subject: Add current hash metric It seems like it would be nice to know how many infohashes we actually know about. Let's add a guage that tells us that directly. --- src/metrics.c | 10 ++++++++++ src/metrics.h | 2 ++ src/peers.c | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/src/metrics.c b/src/metrics.c index 3a56837..7bac410 100644 --- a/src/metrics.c +++ b/src/metrics.c @@ -8,6 +8,7 @@ prom_counter_t *bytesSent = NULL; prom_counter_t *meta = NULL; prom_counter_t *peers = NULL; +prom_gauge_t *current_hashes = NULL; prom_counter_t *hashes = NULL; prom_counter_t *hash_expired = NULL; prom_counter_t *queries = NULL; @@ -110,6 +111,15 @@ void metric_init() { ) ); + current_hashes = prom_collector_registry_must_register_metric( + prom_gauge_new( + "dht_live_hashes_total", + "Number of hashes with active peers", + 0, + NULL + ) + ); + hashes = prom_collector_registry_must_register_metric( prom_counter_new( "dht_hashes_total", diff --git a/src/metrics.h b/src/metrics.h index 25afcce..3155ccb 100644 --- a/src/metrics.h +++ b/src/metrics.h @@ -10,6 +10,7 @@ extern prom_counter_t *bytesSent; extern prom_counter_t *meta; extern prom_counter_t *peers; +extern prom_gauge_t *current_hashes; extern prom_counter_t *hashes; extern prom_counter_t *hash_expired; extern prom_counter_t *queries; @@ -19,6 +20,7 @@ extern prom_gauge_t *activeNodes; extern prom_gauge_t *requestsInFlight; extern prom_counter_t *retries; + extern prom_counter_t *requestsProcessed; void metric_init(); diff --git a/src/peers.c b/src/peers.c index 781bc7e..6d23fff 100644 --- a/src/peers.c +++ b/src/peers.c @@ -105,6 +105,7 @@ int add_peer(struct infohash* infohash, struct addr* peer, time_t now) { peer_status.peers++; prom_counter_inc(peers, NULL); + prom_gauge_set(current_hashes, (double)peer_table_load, NULL); return 0; } @@ -155,6 +156,9 @@ void expire_hashes(time_t now) { // Remove the slot entry->set = false; + peer_table_load--; prom_counter_inc(hash_expired, NULL); } + + prom_gauge_set(current_hashes, (double)peer_table_load, NULL); } -- cgit v1.2.3