diff options
author | David Goulet <dgoulet@torproject.org> | 2021-05-05 14:09:07 -0400 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2021-05-12 11:58:25 -0400 |
commit | 897344fddc1ea5ba6dc0db814a703932b05560f4 (patch) | |
tree | 5906976057f27d2be9d496493c20e63ebd20ad12 /src/feature/stats | |
parent | 9040a5475ddaee4a244ae9e03f4597a75f86d9be (diff) | |
download | tor-897344fddc1ea5ba6dc0db814a703932b05560f4.tar.gz tor-897344fddc1ea5ba6dc0db814a703932b05560f4.zip |
relay: Add the global connection limit metrics
This emits two events (read and write) of the total number that the
global connection limit was reached.
Related to #40367
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/feature/stats')
-rw-r--r-- | src/feature/stats/rephist.c | 21 | ||||
-rw-r--r-- | src/feature/stats/rephist.h | 3 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/feature/stats/rephist.c b/src/feature/stats/rephist.c index 98907055ef..920a96a39a 100644 --- a/src/feature/stats/rephist.c +++ b/src/feature/stats/rephist.c @@ -207,6 +207,11 @@ typedef struct { /** Current state of overload stats */ static overload_stats_t overload_stats; +/** Counters to count the number of times we've reached an overload for the + * global connection read/write limit. Reported on the MetricsPort. */ +static uint64_t stats_n_read_limit_reached = 0; +static uint64_t stats_n_write_limit_reached = 0; + /** Return true if this overload happened within the last `n_hours`. */ static bool overload_happened_recently(time_t overload_time, int n_hours) @@ -221,6 +226,20 @@ overload_happened_recently(time_t overload_time, int n_hours) /* The current version of the overload stats version */ #define OVERLOAD_STATS_VERSION 1 +/** Return the stats_n_read_limit_reached counter. */ +uint64_t +rep_hist_get_n_read_limit_reached(void) +{ + return stats_n_read_limit_reached; +} + +/** Return the stats_n_write_limit_reached counter. */ +uint64_t +rep_hist_get_n_write_limit_reached(void) +{ + return stats_n_write_limit_reached; +} + /** Returns an allocated string for server descriptor for publising information * on whether we are overloaded or not. */ char * @@ -299,6 +318,7 @@ rep_hist_note_overload(overload_type_t overload) SET_TO_START_OF_HOUR(overload_stats.overload_general_time); break; case OVERLOAD_READ: { + stats_n_read_limit_reached++; SET_TO_START_OF_HOUR(overload_stats.overload_ratelimits_time); if (approx_time() >= last_read_counted + 60) { /* Count once a minute */ overload_stats.overload_read_count++; @@ -307,6 +327,7 @@ rep_hist_note_overload(overload_type_t overload) break; } case OVERLOAD_WRITE: { + stats_n_write_limit_reached++; SET_TO_START_OF_HOUR(overload_stats.overload_ratelimits_time); if (approx_time() >= last_write_counted + 60) { /* Count once a minute */ overload_stats.overload_write_count++; diff --git a/src/feature/stats/rephist.h b/src/feature/stats/rephist.h index 0bb9dd4678..b54fc77883 100644 --- a/src/feature/stats/rephist.h +++ b/src/feature/stats/rephist.h @@ -162,6 +162,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); +uint64_t rep_hist_get_n_read_limit_reached(void); +uint64_t rep_hist_get_n_write_limit_reached(void); + #ifdef TOR_UNIT_TESTS struct hs_v2_stats_t; const struct hs_v2_stats_t *rep_hist_get_hs_v2_stats(void); |