9#define RELAY_METRICS_ENTRY_PRIVATE
21#include "core/or/dos.h"
42#include <event2/dns.h>
66static void fill_est_intro_cells(
void);
67static void fill_est_rend_cells(
void);
68static void fill_intro1_cells(
void);
69static void fill_rend1_cells(
void);
79 .type = METRICS_TYPE_COUNTER,
80 .name = METRICS_NAME(relay_load_oom_bytes_total),
81 .help =
"Total number of bytes the OOM has freed by subsystem",
86 .type = METRICS_TYPE_COUNTER,
87 .name = METRICS_NAME(relay_load_onionskins_total),
88 .help =
"Total number of onionskins handled",
93 .type = METRICS_TYPE_GAUGE,
94 .name = METRICS_NAME(relay_load_socket_total),
95 .help =
"Total number of sockets",
100 .type = METRICS_TYPE_COUNTER,
101 .name = METRICS_NAME(relay_load_global_rate_limit_reached_total),
102 .help =
"Total number of global connection bucket limit reached",
107 .type = METRICS_TYPE_COUNTER,
108 .name = METRICS_NAME(relay_exit_dns_query_total),
109 .help =
"Total number of DNS queries done by this relay",
114 .type = METRICS_TYPE_COUNTER,
115 .name = METRICS_NAME(relay_exit_dns_error_total),
116 .help =
"Total number of DNS errors encountered by this relay",
121 .type = METRICS_TYPE_COUNTER,
122 .name = METRICS_NAME(relay_load_tcp_exhaustion_total),
123 .help =
"Total number of times we ran out of TCP ports",
128 .type = METRICS_TYPE_COUNTER,
129 .name = METRICS_NAME(relay_connections_total),
130 .help =
"Total number of created/rejected connections",
135 .type = METRICS_TYPE_GAUGE,
136 .name = METRICS_NAME(relay_connections),
137 .help =
"Total number of opened connections",
142 .type = METRICS_TYPE_COUNTER,
143 .name = METRICS_NAME(relay_streams_total),
144 .help =
"Total number of streams",
149 .type = METRICS_TYPE_COUNTER,
150 .name = METRICS_NAME(relay_congestion_control_total),
151 .help =
"Congestion control related counters",
156 .type = METRICS_TYPE_GAUGE,
157 .name = METRICS_NAME(relay_congestion_control),
158 .help =
"Congestion control related gauges",
163 .type = METRICS_TYPE_COUNTER,
164 .name = METRICS_NAME(relay_dos_total),
165 .help =
"Denial of Service defenses related counters",
170 .type = METRICS_TYPE_COUNTER,
171 .name = METRICS_NAME(relay_traffic_bytes),
172 .help =
"Traffic related counters",
177 .type = METRICS_TYPE_GAUGE,
178 .name = METRICS_NAME(relay_flag),
179 .help =
"Relay flags from consensus",
184 .type = METRICS_TYPE_GAUGE,
185 .name = METRICS_NAME(relay_circuits_total),
186 .help =
"Total number of circuits",
191 .type = METRICS_TYPE_GAUGE,
192 .name = METRICS_NAME(relay_signing_cert_expiry_timestamp),
193 .help =
"Timestamp at which the current online keys will expire",
198 .type = METRICS_TYPE_COUNTER,
199 .name = METRICS_NAME(relay_est_rend_total),
200 .help =
"Total number of EST_REND cells we received",
201 .fill_fn = fill_est_rend_cells,
205 .type = METRICS_TYPE_COUNTER,
206 .name = METRICS_NAME(relay_est_intro_total),
207 .help =
"Total number of EST_INTRO cells we received",
208 .fill_fn = fill_est_intro_cells,
212 .type = METRICS_TYPE_COUNTER,
213 .name = METRICS_NAME(relay_intro1_total),
214 .help =
"Total number of INTRO1 cells we received",
215 .fill_fn = fill_intro1_cells,
219 .type = METRICS_TYPE_COUNTER,
220 .name = METRICS_NAME(relay_rend1_total),
221 .help =
"Total number of REND1 cells we received",
222 .fill_fn = fill_rend1_cells,
226 .type = METRICS_TYPE_COUNTER,
227 .name = METRICS_NAME(relay_destroy_cell_total),
228 .help =
"Total number of DESTROY cell we received",
233 .type = METRICS_TYPE_COUNTER,
234 .name = METRICS_NAME(relay_circ_proto_violation_total),
235 .help =
"Total number of circuit protocol violation",
240 .type = METRICS_TYPE_COUNTER,
241 .name = METRICS_NAME(relay_drop_cell_total),
242 .help =
"Total number of DROP cell we received",
252static inline const char *
256 case ONION_HANDSHAKE_TYPE_TAP:
258 case ONION_HANDSHAKE_TYPE_FAST:
260 case ONION_HANDSHAKE_TYPE_NTOR:
262 case ONION_HANDSHAKE_TYPE_NTOR_V3:
266 tor_assert_unreached();
272static inline const char *
294 the_store, rentry->type, rentry->name, rentry->help, 0, NULL);
306 uint8_t is_fast = 0, is_exit = 0, is_authority = 0, is_stable = 0;
307 uint8_t is_running = 0, is_v2_dir = 0, is_guard = 0, is_sybil = 0;
308 uint8_t is_hs_dir = 0;
318 is_v2_dir = me->rs->is_v2_dir;
327 the_store, rentry->type, rentry->name, rentry->help, 0, NULL);
334 rentry->help, 0, NULL);
340 rentry->help, 0, NULL);
346 rentry->help, 0, NULL);
352 rentry->help, 0, NULL);
358 rentry->help, 0, NULL);
364 rentry->help, 0, NULL);
370 rentry->help, 0, NULL);
376 rentry->help, 0, NULL);
389 the_store, rentry->type, rentry->name, rentry->help, 0, NULL);
396 rentry->help, 0, NULL);
408 the_store, rentry->type, rentry->name, rentry->help, 0, NULL);
415 rentry->help, 0, NULL);
421 rentry->help, 0, NULL);
427 rentry->help, 0, NULL);
433 rentry->help, 0, NULL);
439 rentry->help, 0, NULL);
445 rentry->help, 0, NULL);
451 rentry->help, 0, NULL);
457 rentry->help, 0, NULL);
463 rentry->help, 0, NULL);
477 the_store, rentry->type, rentry->name, rentry->help, 0, NULL);
485 rentry->help, 0, NULL);
494 rentry->help, 0, NULL);
503 rentry->help, 0, NULL);
509 cc_stats_flow_num_xon_sent);
512 rentry->help, 0, NULL);
520 rentry->help, 0, NULL);
528 rentry->help, 0, NULL);
536 rentry->help, 0, NULL);
544 rentry->help, 0, NULL);
552 rentry->help, 0, NULL);
568 the_store, rentry->type, rentry->name, rentry->help, 0, NULL);
577 rentry->help, 0, NULL);
586 rentry->help, 0, NULL);
595 rentry->help, 0, NULL);
604 rentry->help, 0, NULL);
613 rentry->help, 0, NULL);
622 rentry->help, 0, NULL);
631 rentry->help, 0, NULL);
640 rentry->help, 0, NULL);
649 rentry->help, 0, NULL);
658 rentry->help, 0, NULL);
667 rentry->help, 0, NULL);
676 rentry->help, 0, NULL);
685 rentry->help, 0, NULL);
694 rentry->help, 0, NULL);
703 rentry->help, 0, NULL);
712 rentry->help, 0, NULL);
737 the_store, rentry->type, rentry->name, rentry->help, 0, NULL);
741 rentry->help, 0, NULL);
745 rentry->help, 0, NULL);
752 unsigned int conn_type,
753 const char* direction,
776 for (
unsigned int i = CONN_TYPE_MIN_; i < CONN_TYPE_MAX_ ; i++) {
782 the_store, rentry->type, rentry->name, rentry->help, 0, NULL);
786 rentry->help, 0, NULL);
792 rentry->help, 0, NULL);
796 rentry->help, 0, NULL);
801 rentry->help, 0, NULL);
805 rentry->help, 0, NULL);
820 for (
unsigned int i = CONN_TYPE_MIN_; i < CONN_TYPE_MAX_ ; i++) {
826 the_store, rentry->type, rentry->name, rentry->help, 0, NULL);
830 rentry->help, 0, NULL);
835 rentry->help, 0, NULL);
839 rentry->help, 0, NULL);
849 metrics_store_entry_t *sentry;
854 rentry->help, 0, NULL);
862static struct dns_type {
866 { .name =
"A", .type = DNS_IPv4_A },
867 { .name =
"PTR", .type = DNS_PTR },
868 { .name =
"AAAA", .type = DNS_IPv6_AAAA },
870static const size_t num_dns_types =
ARRAY_LENGTH(dns_types);
877 metrics_store_entry_t *sentry;
883 static struct dns_error {
887 { .name =
"success", .key = DNS_ERR_NONE },
888 { .name =
"format", .key = DNS_ERR_FORMAT },
889 { .name =
"serverfailed", .key = DNS_ERR_SERVERFAILED },
890 { .name =
"notexist", .key = DNS_ERR_NOTEXIST },
891 { .name =
"notimpl", .key = DNS_ERR_NOTIMPL },
892 { .name =
"refused", .key = DNS_ERR_REFUSED },
893 { .name =
"truncated", .key = DNS_ERR_TRUNCATED },
894 { .name =
"unknown", .key = DNS_ERR_UNKNOWN },
895 { .name =
"tor_timeout", .key = DNS_ERR_TIMEOUT },
896 { .name =
"shutdown", .key = DNS_ERR_SHUTDOWN },
897 { .name =
"cancel", .key = DNS_ERR_CANCEL },
898 { .name =
"nodata", .key = DNS_ERR_NODATA },
904 for (
size_t i = 0; i < num_dns_types; i++) {
910 for (
size_t j = 0; j < num_errors; j++) {
912 rentry->help, 0, NULL);
924 for (
size_t j = 0; j < num_errors; j++) {
926 rentry->help, 0, NULL);
938 metrics_store_entry_t *sentry;
944 for (
size_t i = 0; i < num_dns_types; i++) {
950 rentry->help, 0, NULL);
959 rentry->help, 0, NULL);
967 metrics_store_entry_t *sentry;
972 rentry->help, 0, NULL);
978 rentry->help, 0, NULL);
988 metrics_store_entry_t *sentry;
993 rentry->help, 0, NULL);
999 rentry->help, 0, NULL);
1007 metrics_store_entry_t *sentry;
1011 for (uint16_t t = 0; t <= MAX_ONION_HANDSHAKE_TYPE; t++) {
1017 rentry->help, 0, NULL);
1025 rentry->help, 0, NULL);
1039 metrics_store_entry_t *sentry;
1044 rentry->help, 0, NULL);
1050 rentry->help, 0, NULL);
1056 rentry->help, 0, NULL);
1062 rentry->help, 0, NULL);
1072 metrics_store_entry_t *sentry;
1078 signing_key = get_master_signing_key_cert();
1081 rentry->help, 0, NULL);
1087static uint64_t est_intro_actions[EST_INTRO_ACTION_COUNT] = {0};
1090relay_increment_est_intro_action(est_intro_action_t action)
1092 est_intro_actions[action]++;
1096fill_est_intro_cells(
void)
1098 metrics_store_entry_t *sentry;
1104 est_intro_action_t key;
1106 {.name =
"success", .key = EST_INTRO_SUCCESS},
1107 {.name =
"malformed", .key = EST_INTRO_MALFORMED},
1108 {.name =
"unsuitable_circuit", .key = EST_INTRO_UNSUITABLE_CIRCUIT},
1109 {.name =
"circuit_dead", .key = EST_INTRO_CIRCUIT_DEAD},
1111 static const size_t num_actions =
ARRAY_LENGTH(actions);
1113 for (
size_t i = 0; i < num_actions; ++i) {
1115 rentry->help, 0, NULL);
1119 (
long)est_intro_actions[actions[i].key]);
1123static uint64_t est_rend_actions[EST_REND_ACTION_COUNT] = {0};
1126relay_increment_est_rend_action(est_rend_action_t action)
1128 est_rend_actions[action]++;
1132fill_est_rend_cells(
void)
1134 metrics_store_entry_t *sentry;
1140 est_rend_action_t key;
1142 {.name =
"success", .key = EST_REND_SUCCESS},
1143 {.name =
"unsuitable_circuit", .key = EST_REND_UNSUITABLE_CIRCUIT},
1144 {.name =
"single_hop", .key = EST_REND_SINGLE_HOP},
1145 {.name =
"malformed", .key = EST_REND_MALFORMED},
1146 {.name =
"duplicate_cookie", .key = EST_REND_DUPLICATE_COOKIE},
1147 {.name =
"circuit_dead", .key = EST_REND_CIRCUIT_DEAD},
1149 static const size_t num_actions =
ARRAY_LENGTH(actions);
1151 for (
size_t i = 0; i < num_actions; ++i) {
1153 rentry->help, 0, NULL);
1160static uint64_t intro1_actions[INTRO1_ACTION_COUNT] = {0};
1163relay_increment_intro1_action(intro1_action_t action)
1165 intro1_actions[action]++;
1169fill_intro1_cells(
void)
1171 metrics_store_entry_t *sentry;
1177 intro1_action_t key;
1179 {.name =
"success", .key = INTRO1_SUCCESS},
1180 {.name =
"circuit_dead", .key = INTRO1_CIRCUIT_DEAD},
1181 {.name =
"malformed", .key = INTRO1_MALFORMED},
1182 {.name =
"unknown_service", .key = INTRO1_UNKNOWN_SERVICE},
1183 {.name =
"rate_limited", .key = INTRO1_RATE_LIMITED},
1184 {.name =
"circuit_reused", .key = INTRO1_CIRCUIT_REUSED},
1185 {.name =
"single_hop", .key = INTRO1_SINGLE_HOP},
1187 static const size_t num_actions =
ARRAY_LENGTH(actions);
1189 for (
size_t i = 0; i < num_actions; ++i) {
1191 rentry->help, 0, NULL);
1198static uint64_t rend1_actions[REND1_ACTION_COUNT] = {0};
1201relay_increment_rend1_action(rend1_action_t action)
1203 rend1_actions[action]++;
1207fill_rend1_cells(
void)
1209 metrics_store_entry_t *sentry;
1217 {.name =
"success", .key = REND1_SUCCESS},
1218 {.name =
"unsuitable_circuit", .key = REND1_UNSUITABLE_CIRCUIT},
1219 {.name =
"malformed", .key = REND1_MALFORMED},
1220 {.name =
"unknown_cookie", .key = REND1_UNKNOWN_COOKIE},
1221 {.name =
"circuit_dead", .key = REND1_CIRCUIT_DEAD},
1223 static const size_t num_actions =
ARRAY_LENGTH(actions);
1225 for (
size_t i = 0; i < num_actions; ++i) {
1227 rentry->help, 0, NULL);
1238 metrics_store_entry_t *sentry;
1243 rentry->help, 0, NULL);
1252 metrics_store_entry_t *sentry;
1257 rentry->help, 0, NULL);
1265 metrics_store_entry_t *sentry;
1270 rentry->help, 0, NULL);
1287 for (
size_t i = 0; i < num_base_metrics; i++) {
uint64_t circ_n_proto_violation
double cc_stats_circ_close_ss_cwnd_ma
double cc_stats_circ_close_cwnd_ma
smartlist_t * circuit_get_global_list(void)
Header file for circuitlist.c.
uint64_t stats_n_destroy_cells_processed
Header file for command.c.
const or_options_t * get_options(void)
Header file for config.c.
uint64_t congestion_control_get_num_clock_stalls(void)
uint64_t congestion_control_get_num_rtt_reset(void)
uint64_t cc_stats_circs_created
Public APIs for congestion control.
uint64_t cc_stats_flow_num_xoff_sent
APIs for stream flow control on congestion controlled circuits.
uint64_t cc_stats_vegas_above_ss_cwnd_max
uint64_t cc_stats_vegas_above_delta
double cc_stats_vegas_exit_ss_cwnd_ma
Private-ish APIs for the TOR_VEGAS congestion control algorithm.
const char * conn_type_to_string(int type)
Header file for connection.c.
int64_t tor_llround(double d)
uint64_t hs_dos_get_intro2_rejected_count(void)
Header file containing denial of service defenses for the HS subsystem for all versions.
uint64_t get_bytes_read(void)
uint64_t get_bytes_written(void)
Header file for mainloop.c.
Headers for util_malloc.c.
const char * metrics_format_label(const char *key, const char *value)
metrics_store_t * metrics_store_new(void)
metrics_store_entry_t * metrics_store_add(metrics_store_t *store, metrics_type_t type, const char *name, const char *help, size_t bucket_count, const int64_t *buckets)
void metrics_store_reset(metrics_store_t *store)
Header for lib/metrics/metrics_store.c.
void metrics_store_entry_update(metrics_store_entry_t *entry, const int64_t value)
void metrics_store_entry_add_label(metrics_store_entry_t *entry, const char *label)
Node information structure.
const node_t * node_get_by_id(const char *identity_digest)
Header file for nodelist.c.
Master header file for Tor-specific functionality.
uint64_t oom_stats_n_bytes_removed_dns
uint64_t stats_n_circ_max_cell_reached
const char * relay_command_to_string(uint8_t command)
static void fill_oom_values(void)
const smartlist_t * relay_metrics_get_stores(void)
static void fill_traffic_values(void)
static void fill_store(void)
static void fill_relay_drop_cell(void)
static void fill_streams_values(void)
static void fill_tcp_exhaustion_values(void)
static void fill_relay_circ_proto_violation(void)
static void fill_dns_query_values(void)
static void fill_onionskins_values(void)
static void fill_dos_values(void)
static void fill_dns_error_values(void)
static void fill_conn_gauge_values(void)
static void fill_conn_counter_values(void)
void relay_metrics_init(void)
static void fill_signing_cert_expiry(void)
static void fill_single_stream_value(metrics_store_entry_t *sentry, uint8_t cmd)
static void fill_single_connection_value(metrics_store_entry_t *sentry, unsigned int conn_type, const char *direction, const char *state, int socket_family, uint64_t value)
static void fill_circuits_values(void)
static void fill_global_bw_limit_values(void)
static void fill_cc_counters_values(void)
void relay_metrics_free(void)
static const char * af_to_string(const int af)
static void fill_relay_destroy_cell(void)
static void fill_relay_flags(void)
static const char * handshake_type_to_str(const uint16_t type)
static const relay_metrics_entry_t base_metrics[]
static void fill_cc_gauges_values(void)
static void fill_socket_values(void)
static metrics_store_t * the_store
Header for feature/relay/relay_metrics.c.
@ RELAY_METRICS_CC_GAUGES
@ RELAY_METRICS_NUM_GLOBAL_RW_LIMIT
@ RELAY_METRICS_NUM_EST_REND
@ RELAY_METRICS_NUM_STREAMS
@ RELAY_METRICS_NUM_CIRCUITS
@ RELAY_METRICS_NUM_TCP_EXHAUSTION
@ RELAY_METRICS_NUM_SOCKETS
@ RELAY_METRICS_NUM_INTRO1_CELLS
@ RELAY_METRICS_CONN_COUNTERS
@ RELAY_METRICS_CC_COUNTERS
@ RELAY_METRICS_CONN_GAUGES
@ RELAY_METRICS_CIRC_DESTROY_CELL
@ RELAY_METRICS_NUM_ONIONSKINS
@ RELAY_METRICS_RELAY_FLAGS
@ RELAY_METRICS_SIGNING_CERT_EXPIRY
@ RELAY_METRICS_NUM_EST_INTRO
@ RELAY_METRICS_NUM_DNS_ERRORS
@ RELAY_METRICS_NUM_OOM_BYTES
@ RELAY_METRICS_NUM_TRAFFIC
@ RELAY_METRICS_CIRC_DROP_CELL
@ RELAY_METRICS_NUM_REND1_CELLS
@ RELAY_METRICS_CIRC_PROTO_VIOLATION
uint64_t rep_hist_get_drop_cell_received_count(void)
uint64_t rep_hist_get_conn_created(bool from_listener, unsigned int type, int af)
uint64_t rep_hist_get_n_dns_request(int type)
uint64_t rep_hist_get_conn_rejected(unsigned int type, int af)
uint64_t rep_hist_get_circuit_n_handshake_assigned(uint16_t type)
uint64_t rep_hist_get_conn_opened(bool from_listener, unsigned int type, int af)
uint64_t rep_hist_get_n_dns_error(int type, uint8_t error)
uint64_t rep_hist_get_n_read_limit_reached(void)
uint64_t rep_hist_get_n_tcp_exhaustion(void)
uint64_t rep_hist_get_circuit_n_handshake_dropped(uint16_t type)
uint64_t rep_hist_get_exit_stream_seen(unsigned int cmd)
uint64_t rep_hist_get_n_write_limit_reached(void)
Header file for rephist.c.
const uint8_t * router_get_my_id_digest(void)
Header file for router.c.
Routerstatus (consensus entry) structure.
smartlist_t * smartlist_new(void)
void smartlist_add(smartlist_t *sl, void *element)
int get_max_sockets(void)
int get_n_open_sockets(void)
unsigned int is_possible_guard
unsigned int is_flagged_running
unsigned int is_authority
Macros to manage assertions, fatal and non-fatal.