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

[tor-commits] [tor] 02/13: metrics: Add traffic related stats 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 48ab17cc72864529ed11d579552dfc2f0cf93f9d
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
AuthorDate: Thu Oct 27 10:00:50 2022 -0400

    metrics: Add traffic related stats to MetricsPort
    
    At this commit, bytes read and written are exported.
    
    Related to #40194
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
 src/feature/relay/relay_metrics.c | 29 +++++++++++++++++++++++++++++
 src/feature/relay/relay_metrics.h |  2 ++
 2 files changed, 31 insertions(+)

diff --git a/src/feature/relay/relay_metrics.c b/src/feature/relay/relay_metrics.c
index e9f4b68350..d5237bbfed 100644
--- a/src/feature/relay/relay_metrics.c
+++ b/src/feature/relay/relay_metrics.c
@@ -12,6 +12,7 @@
 
 #include "core/or/or.h"
 #include "core/mainloop/connection.h"
+#include "core/mainloop/mainloop.h"
 #include "core/or/congestion_control_common.h"
 #include "core/or/dos.h"
 #include "core/or/relay.h"
@@ -39,6 +40,7 @@ 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);
+static void fill_traffic_values(void);
 
 /** The base metrics that is a static array of metrics added to the metrics
  * store.
@@ -123,6 +125,13 @@ static const relay_metrics_entry_t base_metrics[] =
     .help = "Denial of Service defenses related counters",
     .fill_fn = fill_dos_values,
   },
+  {
+    .key = RELAY_METRICS_NUM_TRAFFIC,
+    .type = METRICS_TYPE_COUNTER,
+    .name = METRICS_NAME(relay_traffic_bytes),
+    .help = "Traffic related counters",
+    .fill_fn = fill_traffic_values,
+  },
 };
 static const size_t num_base_metrics = ARRAY_LENGTH(base_metrics);
 
@@ -149,6 +158,26 @@ handshake_type_to_str(const uint16_t type)
   }
 }
 
+/** Fill function for the RELAY_METRICS_NUM_TRAFFIC metric. */
+static void
+fill_traffic_values(void)
+{
+  const relay_metrics_entry_t *rentry =
+    &base_metrics[RELAY_METRICS_NUM_TRAFFIC];
+  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("direction", "read"));
+  metrics_store_entry_update(sentry, get_bytes_read());
+
+  sentry = metrics_store_add(the_store, rentry->type, rentry->name,
+                             rentry->help);
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("direction", "written"));
+  metrics_store_entry_update(sentry, get_bytes_written());
+}
+
 /** Fill function for the RELAY_METRICS_NUM_DOS metric. */
 static void
 fill_dos_values(void)
diff --git a/src/feature/relay/relay_metrics.h b/src/feature/relay/relay_metrics.h
index 2aa227c9cb..d501176f2e 100644
--- a/src/feature/relay/relay_metrics.h
+++ b/src/feature/relay/relay_metrics.h
@@ -37,6 +37,8 @@ typedef enum {
   RELAY_METRICS_NUM_CC = 9,
   /** Denial of Service defenses subsystem. */
   RELAY_METRICS_NUM_DOS = 10,
+  /** Denial of Service defenses subsystem. */
+  RELAY_METRICS_NUM_TRAFFIC = 11,
 } 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