diff options
| author | Jesper Jensen <jesper@jnsn.dev> | 2025-04-14 12:22:20 +0200 |
|---|---|---|
| committer | Jesper Jensen <jesper@jnsn.dev> | 2025-04-14 12:22:20 +0200 |
| commit | 95d03b842f6fdbfda19ed050131bc95ece13a171 (patch) | |
| tree | f3147d3ca5fe6c757960366e04768af398c99636 | |
| parent | 6cce106232e05e5ef20a69eb1dc9a0c617fb9fa4 (diff) | |
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.
| -rw-r--r-- | src/metrics.c | 10 | ||||
| -rw-r--r-- | src/metrics.h | 2 | ||||
| -rw-r--r-- | src/peers.c | 4 |
3 files changed, 16 insertions, 0 deletions
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); } |
