diff options
author | David Goulet <dgoulet@torproject.org> | 2022-10-27 10:39:55 -0400 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2022-10-27 10:48:52 -0400 |
commit | 177f3a40ebc3e570133133c15ae79d9eaab16052 (patch) | |
tree | cd231cfac870d9d01aa043608735504dc47eb296 | |
parent | 1a2d93f72ae29ef82899d5583d88efb29b872579 (diff) | |
download | tor-177f3a40ebc3e570133133c15ae79d9eaab16052.tar.gz tor-177f3a40ebc3e570133133c15ae79d9eaab16052.zip |
metrics: Add number of opened circuits to MetricsPort
Related to #40194
Signed-off-by: David Goulet <dgoulet@torproject.org>
-rw-r--r-- | src/feature/relay/relay_metrics.c | 24 | ||||
-rw-r--r-- | src/feature/relay/relay_metrics.h | 2 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/feature/relay/relay_metrics.c b/src/feature/relay/relay_metrics.c index 348d776c3b..7fcbb72d75 100644 --- a/src/feature/relay/relay_metrics.c +++ b/src/feature/relay/relay_metrics.c @@ -14,6 +14,7 @@ #include "core/mainloop/connection.h" #include "core/mainloop/mainloop.h" #include "core/or/congestion_control_common.h" +#include "core/or/circuitlist.h" #include "core/or/dos.h" #include "core/or/relay.h" @@ -36,6 +37,7 @@ /** Declarations of each fill function for metrics defined in base_metrics. */ static void fill_cc_values(void); +static void fill_circuits_values(void); static void fill_connections_values(void); static void fill_dns_error_values(void); static void fill_dns_query_values(void); @@ -146,6 +148,13 @@ static const relay_metrics_entry_t base_metrics[] = .help = "Relay flags from consensus", .fill_fn = fill_relay_flags, }, + { + .key = RELAY_METRICS_NUM_CIRCUITS, + .type = METRICS_TYPE_GAUGE, + .name = METRICS_NAME(relay_circuits_total), + .help = "Total number of circuits", + .fill_fn = fill_circuits_values, + }, }; static const size_t num_base_metrics = ARRAY_LENGTH(base_metrics); @@ -172,6 +181,21 @@ handshake_type_to_str(const uint16_t type) } } +/** Fill function for the RELAY_METRICS_NUM_CIRCUITS metric. */ +static void +fill_circuits_values(void) +{ + const relay_metrics_entry_t *rentry = + &base_metrics[RELAY_METRICS_NUM_CIRCUITS]; + metrics_store_entry_t *sentry = + metrics_store_add(the_store, rentry->type, rentry->name, rentry->help); + + metrics_store_entry_add_label(sentry, + metrics_format_label("state", "opened")); + metrics_store_entry_update(sentry, + smartlist_len(circuit_get_global_list())); +} + /** Fill function for the RELAY_METRICS_RELAY_FLAGS metric. */ static void fill_relay_flags(void) diff --git a/src/feature/relay/relay_metrics.h b/src/feature/relay/relay_metrics.h index 7c41ecf38b..8ac24ebdb4 100644 --- a/src/feature/relay/relay_metrics.h +++ b/src/feature/relay/relay_metrics.h @@ -41,6 +41,8 @@ typedef enum { RELAY_METRICS_NUM_TRAFFIC = 11, /** Relay flags. */ RELAY_METRICS_RELAY_FLAGS = 12, + /** Numer of circuits. */ + RELAY_METRICS_NUM_CIRCUITS = 13, } relay_metrics_key_t; /** The metadata of a relay metric. */ |