[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor] 04/13: metrics: Add number of opened circuits to MetricsPort



This is an automated email from the git hooks/post-receive script.

dgoulet pushed a commit to branch main
in repository tor.

commit 177f3a40ebc3e570133133c15ae79d9eaab16052
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
AuthorDate: Thu Oct 27 10:39:55 2022 -0400

    metrics: Add number of opened circuits to MetricsPort
    
    Related to #40194
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
 src/feature/relay/relay_metrics.c | 24 ++++++++++++++++++++++++
 src/feature/relay/relay_metrics.h |  2 ++
 2 files changed, 26 insertions(+)

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. */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits