]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
metrics: Add flow control metrics.
authorMike Perry <mikeperry-git@torproject.org>
Thu, 3 Nov 2022 21:27:08 +0000 (21:27 +0000)
committerDavid Goulet <dgoulet@torproject.org>
Mon, 7 Nov 2022 14:55:06 +0000 (09:55 -0500)
Part of #40708.

src/core/or/congestion_control_flow.c
src/core/or/congestion_control_flow.h
src/feature/relay/relay_metrics.c

index ea2c0df42c88b09f644ff07c6b0155efab1a4479..cc120acd298971d2d4827109429e5b3bdbf614e5 100644 (file)
@@ -23,6 +23,7 @@
 #include "feature/nodelist/networkstatus.h"
 #include "trunnel/flow_control_cells.h"
 #include "feature/control/control_events.h"
+#include "lib/math/stats.h"
 
 #include "core/or/connection_st.h"
 #include "core/or/cell_st.h"
@@ -36,6 +37,14 @@ static uint32_t xon_change_pct;
 static uint32_t xon_ewma_cnt;
 static uint32_t xon_rate_bytes;
 
+/** Metricsport stats */
+uint64_t cc_stats_flow_num_xoff_sent;
+uint64_t cc_stats_flow_num_xon_sent;
+double cc_stats_flow_xoff_outbuf_ma = 0;
+static double cc_stats_flow_xoff_outbuf_ma_count = 0;
+double cc_stats_flow_xon_outbuf_ma = 0;
+static double cc_stats_flow_xon_outbuf_ma_count = 0;
+
 /* In normal operation, we can get a burst of up to 32 cells before returning
  * to libevent to flush the outbuf. This is a heuristic from hardcoded values
  * and strange logic in connection_bucket_get_share(). */
@@ -148,6 +157,7 @@ circuit_send_stream_xoff(edge_connection_t *stream)
   if (connection_edge_send_command(stream, RELAY_COMMAND_XOFF,
                                (char*)payload, (size_t)xoff_size) == 0) {
     stream->xoff_sent = true;
+    cc_stats_flow_num_xoff_sent++;
 
     /* If this is an entry conn, notify control port */
     if (TO_CONN(stream)->type == CONN_TYPE_AP) {
@@ -222,6 +232,8 @@ circuit_send_stream_xon(edge_connection_t *stream)
     /* Revert the xoff sent status, so we can send another one if need be */
     stream->xoff_sent = false;
 
+    cc_stats_flow_num_xon_sent++;
+
     /* If it's an entry conn, notify control port */
     if (TO_CONN(stream)->type == CONN_TYPE_AP) {
       control_event_stream_status(TO_ENTRY_CONN(TO_CONN(stream)),
@@ -473,6 +485,10 @@ flow_control_decide_xoff(edge_connection_t *stream)
                  total_buffered, buffer_limit_xoff);
       tor_trace(TR_SUBSYS(cc), TR_EV(flow_decide_xoff_sending), stream);
 
+      cc_stats_flow_xoff_outbuf_ma_count++;
+      STATS_UPDATE_AVG(cc_stats_flow_xoff_outbuf_ma,
+                       total_buffered, cc_stats_flow_xoff_outbuf_ma_count);
+
       circuit_send_stream_xoff(stream);
 
       /* Clear the drain rate. It is considered wrong if we
@@ -627,6 +643,11 @@ flow_control_decide_xon(edge_connection_t *stream, size_t n_written)
                  stream->ewma_drain_rate,
                  total_buffered);
       tor_trace(TR_SUBSYS(cc), TR_EV(flow_decide_xon_rate_change), stream);
+
+      cc_stats_flow_xon_outbuf_ma_count++;
+      STATS_UPDATE_AVG(cc_stats_flow_xon_outbuf_ma,
+                       total_buffered, cc_stats_flow_xon_outbuf_ma_count);
+
       circuit_send_stream_xon(stream);
     }
   } else if (total_buffered == 0) {
index 6c318027ea43697a934334ebc3469b258e35cce8..5c735cce235a7e59bfc4ae19563d9111630d83b5 100644 (file)
@@ -33,6 +33,12 @@ bool conn_uses_flow_control(connection_t *stream);
 
 uint64_t edge_get_max_rtt(const edge_connection_t *);
 
+/** Metricsport externs */
+extern uint64_t cc_stats_flow_num_xoff_sent;
+extern uint64_t cc_stats_flow_num_xon_sent;
+extern double cc_stats_flow_xoff_outbuf_ma;
+extern double cc_stats_flow_xon_outbuf_ma;
+
 /* Private section starts. */
 #ifdef TOR_CONGESTION_CONTROL_FLOW_PRIVATE
 
index af59eb3dcc7b2488c6a5a93b7e242bced1b8f486..076ac6861837236cf4ef9950b7e02bee31a744f2 100644 (file)
@@ -15,6 +15,7 @@
 #include "core/mainloop/mainloop.h"
 #include "core/or/congestion_control_common.h"
 #include "core/or/congestion_control_vegas.h"
+#include "core/or/congestion_control_flow.h"
 #include "core/or/circuitlist.h"
 #include "core/or/dos.h"
 #include "core/or/relay.h"
@@ -409,6 +410,42 @@ fill_cc_values(void)
   metrics_store_entry_update(sentry,
                              tor_llround(cc_stats_circ_close_ss_cwnd_ma));
 
+  sentry = metrics_store_add(the_store, rentry->type, rentry->name,
+                             rentry->help);
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("state", "xoff"));
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("action", "outbuf"));
+  metrics_store_entry_update(sentry,
+                             tor_llround(cc_stats_flow_xoff_outbuf_ma));
+
+  sentry = metrics_store_add(the_store, rentry->type, rentry->name,
+                             rentry->help);
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("state", "xoff"));
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("action", "num_sent"));
+  metrics_store_entry_update(sentry,
+                             cc_stats_flow_num_xoff_sent);
+
+  sentry = metrics_store_add(the_store, rentry->type, rentry->name,
+                             rentry->help);
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("state", "xon"));
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("action", "outbuf"));
+  metrics_store_entry_update(sentry,
+                             tor_llround(cc_stats_flow_xon_outbuf_ma));
+
+  sentry = metrics_store_add(the_store, rentry->type, rentry->name,
+                             rentry->help);
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("state", "xon"));
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("action", "num_sent"));
+  metrics_store_entry_update(sentry,
+                             cc_stats_flow_num_xon_sent);
+
   sentry = metrics_store_add(the_store, rentry->type, rentry->name,
                              rentry->help);
   metrics_store_entry_add_label(sentry,