[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] relay: Add number of open and max sockets metrics
commit 9040a5475ddaee4a244ae9e03f4597a75f86d9be
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date: Wed May 5 13:57:19 2021 -0400
relay: Add number of open and max sockets metrics
With this commit, a relay will emit metrics that give the total number
of sockets and total number of opened sockets.
Related to #40367
Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
src/feature/relay/relay_metrics.c | 29 ++++++++++++++++++++++++++++-
src/feature/relay/relay_metrics.h | 2 ++
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/src/feature/relay/relay_metrics.c b/src/feature/relay/relay_metrics.c
index 6816c25f43..72030e079b 100644
--- a/src/feature/relay/relay_metrics.c
+++ b/src/feature/relay/relay_metrics.c
@@ -22,8 +22,9 @@
#include "feature/stats/rephist.h"
/** Declarations of each fill function for metrics defined in base_metrics. */
-static void fill_oom_values(void);
+static void fill_socket_values(void);
static void fill_onionskins_values(void);
+static void fill_oom_values(void);
/** The base metrics that is a static array of metrics added to the metrics
* store.
@@ -45,6 +46,13 @@ static const relay_metrics_entry_t base_metrics[] =
.help = "Total number of onionskins handled",
.fill_fn = fill_onionskins_values,
},
+ {
+ .key = RELAY_METRICS_NUM_SOCKETS,
+ .type = METRICS_TYPE_GAUGE,
+ .name = METRICS_NAME(relay_load_socket_total),
+ .help = "Total number of sockets",
+ .fill_fn = fill_socket_values,
+ },
};
static const size_t num_base_metrics = ARRAY_LENGTH(base_metrics);
@@ -69,6 +77,25 @@ handshake_type_to_str(const uint16_t type)
}
}
+/** Fill function for the RELAY_METRICS_NUM_SOCKETS metrics. */
+static void
+fill_socket_values(void)
+{
+ metrics_store_entry_t *sentry;
+ const relay_metrics_entry_t *rentry =
+ &base_metrics[RELAY_METRICS_NUM_SOCKETS];
+
+ 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, get_n_open_sockets());
+
+ sentry = metrics_store_add(the_store, rentry->type, rentry->name,
+ rentry->help);
+ metrics_store_entry_update(sentry, get_max_sockets());
+}
+
/** Fill function for the RELAY_METRICS_NUM_ONIONSKINS metrics. */
static void
fill_onionskins_values(void)
diff --git a/src/feature/relay/relay_metrics.h b/src/feature/relay/relay_metrics.h
index 6868bd26df..fd310ec7ae 100644
--- a/src/feature/relay/relay_metrics.h
+++ b/src/feature/relay/relay_metrics.h
@@ -19,6 +19,8 @@ typedef enum {
RELAY_METRICS_NUM_OOM_BYTES = 0,
/** Number of onionskines handled. */
RELAY_METRICS_NUM_ONIONSKINS = 1,
+ /** Number of sockets. */
+ RELAY_METRICS_NUM_SOCKETS = 2,
} relay_metrics_key_t;
/** The metadata of a relay metric. */
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits