]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
relay: Add TCP port exhaustion metrics
authorDavid Goulet <dgoulet@torproject.org>
Thu, 6 May 2021 15:17:26 +0000 (11:17 -0400)
committerDavid Goulet <dgoulet@torproject.org>
Wed, 12 May 2021 15:58:25 +0000 (11:58 -0400)
Signed-off-by: David Goulet <dgoulet@torproject.org>
src/core/mainloop/connection.c
src/feature/relay/relay_metrics.c
src/feature/relay/relay_metrics.h
src/feature/stats/rephist.c
src/feature/stats/rephist.h

index 9c6da1295f383c698a258ed5703aa688d8b738f0..4832f254918ba2df4d2dcde1c3551534b1fbff84 100644 (file)
@@ -1261,7 +1261,7 @@ socket_failed_from_resource_exhaustion(void)
    */
   if (get_max_sockets() > 65535) {
     /* TCP port exhaustion */
-    rep_hist_note_overload(OVERLOAD_GENERAL);
+    rep_hist_note_tcp_exhaustion();
   } else {
     /* File descriptor exhaustion */
     rep_hist_note_overload(OVERLOAD_FD_EXHAUSTED);
index 466e4da55e714c76f851c00f3cd4fe7200cf476f..2c24728d9a18aa9028b095f2a9a6e0e5e23af1a8 100644 (file)
@@ -30,6 +30,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_tcp_exhaustion_values(void);
 
 /** The base metrics that is a static array of metrics added to the metrics
  * store.
@@ -79,6 +80,13 @@ static const relay_metrics_entry_t base_metrics[] =
     .help = "Total number of DNS errors encountered by this relay",
     .fill_fn = fill_dns_error_values,
   },
+  {
+    .key = RELAY_METRICS_NUM_TCP_EXHAUSTION,
+    .type = METRICS_TYPE_COUNTER,
+    .name = METRICS_NAME(relay_load_tcp_exhaustion_total),
+    .help = "Total number of times we ran out of TCP ports",
+    .fill_fn = fill_tcp_exhaustion_values,
+  },
 };
 static const size_t num_base_metrics = ARRAY_LENGTH(base_metrics);
 
@@ -103,6 +111,19 @@ handshake_type_to_str(const uint16_t type)
   }
 }
 
+/** Fill function for the RELAY_METRICS_NUM_DNS metrics. */
+static void
+fill_tcp_exhaustion_values(void)
+{
+  metrics_store_entry_t *sentry;
+  const relay_metrics_entry_t *rentry =
+    &base_metrics[RELAY_METRICS_NUM_TCP_EXHAUSTION];
+
+  sentry = metrics_store_add(the_store, rentry->type, rentry->name,
+                             rentry->help);
+  metrics_store_entry_update(sentry, rep_hist_get_n_tcp_exhaustion());
+}
+
 /** Helper array containing mapping for the name of the different DNS records
  * and their corresponding libevent values. */
 static struct dns_type {
index 67f58f60294cc68dad95771be603c3b9acf3cd06..00dfeaa624271e3836316f987cee67a1232305ea 100644 (file)
@@ -27,6 +27,8 @@ typedef enum {
   RELAY_METRICS_NUM_DNS        = 4,
   /** Number of DNS query errors. */
   RELAY_METRICS_NUM_DNS_ERRORS = 5,
+  /** Number of TCP exhaustion reached. */
+  RELAY_METRICS_NUM_TCP_EXHAUSTION = 6,
 } relay_metrics_key_t;
 
 /** The metadata of a relay metric. */
index 7481b2f0a851cb295d385d377e86ba86b24a7d7f..01fa644b9e605acd680eaf886657b7f7d8f72f39 100644 (file)
@@ -214,6 +214,9 @@ static overload_stats_t overload_stats;
 static uint64_t stats_n_read_limit_reached = 0;
 static uint64_t stats_n_write_limit_reached = 0;
 
+/** Total number of times we've reached TCP port exhaustion. */
+static uint64_t stats_n_tcp_exhaustion = 0;
+
 /***** DNS statistics *****/
 
 /** Represents the statistics of DNS queries seen if it is an Exit. */
@@ -512,6 +515,22 @@ rep_hist_note_overload(overload_type_t overload)
   }
 }
 
+/** Note down that we've reached a TCP port exhaustion. This triggers an
+ * overload general event. */
+void
+rep_hist_note_tcp_exhaustion(void)
+{
+  stats_n_tcp_exhaustion++;
+  rep_hist_note_overload(OVERLOAD_GENERAL);
+}
+
+/** Return the total number of TCP exhaustion times we've reached. */
+uint64_t
+rep_hist_get_n_tcp_exhaustion(void)
+{
+  return stats_n_tcp_exhaustion;
+}
+
 /** Return the or_history_t for the OR with identity digest <b>id</b>,
  * creating it if necessary. */
 static or_history_t *
index 9d2e457b4b758779ff93149e1e68eeeddfe2aad1..ca305dfd8d847302533307cd9589693076bf13fd 100644 (file)
@@ -167,6 +167,9 @@ void rep_hist_note_overload(overload_type_t overload);
 char *rep_hist_get_overload_general_line(void);
 char *rep_hist_get_overload_stats_lines(void);
 
+void rep_hist_note_tcp_exhaustion(void);
+uint64_t rep_hist_get_n_tcp_exhaustion(void);
+
 uint64_t rep_hist_get_n_read_limit_reached(void);
 uint64_t rep_hist_get_n_write_limit_reached(void);