aboutsummaryrefslogtreecommitdiff
path: root/src/feature/relay/relay_metrics.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2022-10-27 10:39:55 -0400
committerDavid Goulet <dgoulet@torproject.org>2022-10-27 10:48:52 -0400
commit177f3a40ebc3e570133133c15ae79d9eaab16052 (patch)
treecd231cfac870d9d01aa043608735504dc47eb296 /src/feature/relay/relay_metrics.c
parent1a2d93f72ae29ef82899d5583d88efb29b872579 (diff)
downloadtor-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>
Diffstat (limited to 'src/feature/relay/relay_metrics.c')
-rw-r--r--src/feature/relay/relay_metrics.c24
1 files changed, 24 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)