]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
relay: Add total number of streams seen on MetricsPort
authorDavid Goulet <dgoulet@torproject.org>
Thu, 13 Oct 2022 14:41:21 +0000 (10:41 -0400)
committerDavid Goulet <dgoulet@torproject.org>
Wed, 26 Oct 2022 19:16:48 +0000 (15:16 -0400)
Related to #40194

Signed-off-by: David Goulet <dgoulet@torproject.org>
src/core/or/relay.c
src/core/or/relay.h
src/feature/relay/relay_metrics.c
src/feature/relay/relay_metrics.h

index 01a377b6f5e1d80d4ac3d1f89fa8317bec42a95b..d77c47100ab6e98cd152e55067867ab837b49bc6 100644 (file)
@@ -502,7 +502,7 @@ relay_header_unpack(relay_header_t *dest, const uint8_t *src)
 }
 
 /** Convert the relay <b>command</b> into a human-readable string. */
-static const char *
+const char *
 relay_command_to_string(uint8_t command)
 {
   static char buf[64];
index 71e07562cd7e7313616e1ff7c12c545a84f4cdc1..24466bccd0acec1fd51f7c5766081bf0998c5fdd 100644 (file)
@@ -16,6 +16,8 @@ extern uint64_t stats_n_relay_cells_relayed;
 extern uint64_t stats_n_relay_cells_delivered;
 extern uint64_t stats_n_circ_max_cell_reached;
 
+const char *relay_command_to_string(uint8_t command);
+
 void relay_consensus_has_changed(const networkstatus_t *ns);
 uint32_t relay_get_param_max_circuit_cell_queue_size(
                                      const networkstatus_t *ns);
index 8d0fef86b38a5d407377425aa52b8aa082bc672e..e48e211ba7f825a74a0fafe10465a37cbfb46947 100644 (file)
@@ -32,6 +32,7 @@ static void fill_global_bw_limit_values(void);
 static void fill_socket_values(void);
 static void fill_onionskins_values(void);
 static void fill_oom_values(void);
+static void fill_streams_values(void);
 static void fill_tcp_exhaustion_values(void);
 
 /** The base metrics that is a static array of metrics added to the metrics
@@ -96,6 +97,13 @@ static const relay_metrics_entry_t base_metrics[] =
     .help = "Connections metrics of this relay",
     .fill_fn = fill_connections_values,
   },
+  {
+    .key = RELAY_METRICS_NUM_STREAMS,
+    .type = METRICS_TYPE_COUNTER,
+    .name = METRICS_NAME(relay_streams_total),
+    .help = "Total number of streams",
+    .fill_fn = fill_streams_values,
+  },
 };
 static const size_t num_base_metrics = ARRAY_LENGTH(base_metrics);
 
@@ -122,6 +130,34 @@ handshake_type_to_str(const uint16_t type)
   }
 }
 
+/** Helper: Fill in single stream metrics output. */
+static void
+fill_single_stream_value(metrics_store_entry_t *sentry, uint8_t cmd)
+{
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("type", relay_command_to_string(cmd)));
+  metrics_store_entry_update(sentry, rep_hist_get_stream_seen(cmd));
+}
+
+/** Fill function for the RELAY_METRICS_NUM_STREAMS metric. */
+static void
+fill_streams_values(void)
+{
+  const relay_metrics_entry_t *rentry =
+    &base_metrics[RELAY_METRICS_NUM_STREAMS];
+  metrics_store_entry_t *sentry =
+    metrics_store_add(the_store, rentry->type, rentry->name, rentry->help);
+  fill_single_stream_value(sentry, RELAY_COMMAND_BEGIN);
+
+  sentry = metrics_store_add(the_store, rentry->type, rentry->name,
+                             rentry->help);
+  fill_single_stream_value(sentry, RELAY_COMMAND_BEGIN_DIR);
+
+  sentry = metrics_store_add(the_store, rentry->type, rentry->name,
+                             rentry->help);
+  fill_single_stream_value(sentry, RELAY_COMMAND_RESOLVE);
+}
+
 /** Helper: Fill in single connection metrics output. */
 static void
 fill_single_connection_value(metrics_store_entry_t *sentry,
index 02b92cd043689abee7a65e78c1120bac3976e485..17f9c9f195c0043523dee686495670cb85a78ae6 100644 (file)
@@ -31,6 +31,8 @@ typedef enum {
   RELAY_METRICS_NUM_TCP_EXHAUSTION = 6,
   /** Number of connections. */
   RELAY_METRICS_NUM_CONNECTIONS = 7,
+  /** Number of streams. */
+  RELAY_METRICS_NUM_STREAMS = 8,
 } relay_metrics_key_t;
 
 /** The metadata of a relay metric. */