iota_core/traffic_controller/
metrics.rs1use prometheus::{
6 IntCounter, IntCounterVec, IntGauge, Registry, register_int_counter_vec_with_registry,
7 register_int_counter_with_registry, register_int_gauge_with_registry,
8};
9
10#[derive(Clone)]
11pub struct TrafficControllerMetrics {
12 pub tallies: IntCounter,
13 pub connection_ip_blocklist_len: IntGauge,
14 pub proxy_ip_blocklist_len: IntGauge,
15 pub requests_blocked_at_protocol: IntCounter,
16 pub blocks_delegated_to_firewall: IntCounter,
17 pub firewall_delegation_request_fail: IntCounter,
18 pub tally_channel_overflow: IntCounter,
19 pub num_dry_run_blocked_requests: IntCounter,
20 pub tally_handled: IntCounter,
21 pub error_tally_handled: IntCounter,
22 pub tally_error_types: IntCounterVec,
23 pub deadmans_switch_enabled: IntGauge,
24 pub highest_direct_spam_rate: IntGauge,
25 pub highest_proxied_spam_rate: IntGauge,
26 pub highest_direct_error_rate: IntGauge,
27 pub highest_proxied_error_rate: IntGauge,
28 pub spam_client_threshold: IntGauge,
29 pub error_client_threshold: IntGauge,
30 pub spam_proxied_client_threshold: IntGauge,
31 pub error_proxied_client_threshold: IntGauge,
32}
33
34impl TrafficControllerMetrics {
35 pub fn new(registry: &Registry) -> Self {
36 Self {
37 tallies: register_int_counter_with_registry!("tallies", "Number of tallies", registry)
38 .unwrap(),
39 connection_ip_blocklist_len: register_int_gauge_with_registry!(
40 "connection_ip_blocklist_len",
41 "Number of connection IP addresses (IP addresses as registered \
43 via direct socket connection to the reporting node) in the \
44 protocol layer blocklist",
45 registry
46 )
47 .unwrap(),
48 proxy_ip_blocklist_len: register_int_gauge_with_registry!(
49 "proxy_ip_blocklist_len",
50 "Number of proxy IP addresses (IP addresses as collected \
52 via some mechanism through proxy node such as fullnode) \
53 in the protocol layer blocklist",
54 registry
55 )
56 .unwrap(),
57 requests_blocked_at_protocol: register_int_counter_with_registry!(
58 "requests_blocked_at_protocol",
59 "Number of requests blocked by this node at the protocol level",
60 registry
61 )
62 .unwrap(),
63 blocks_delegated_to_firewall: register_int_counter_with_registry!(
64 "blocks_delegated_to_firewall",
65 "Number of delegation requests to firewall to add to blocklist",
66 registry
67 )
68 .unwrap(),
69 firewall_delegation_request_fail: register_int_counter_with_registry!(
70 "firewall_delegation_request_fail",
71 "Number of failed http requests to firewall for blocklist delegation",
72 registry
73 )
74 .unwrap(),
75 tally_channel_overflow: register_int_counter_with_registry!(
76 "tally_channel_overflow",
77 "Traffic controller tally channel overflow count",
78 registry
79 )
80 .unwrap(),
81 num_dry_run_blocked_requests: register_int_counter_with_registry!(
82 "traffic_control_num_dry_run_blocked_requests",
83 "Number of requests blocked in traffic controller dry run mode",
84 registry
85 )
86 .unwrap(),
87 tally_handled: register_int_counter_with_registry!(
88 "traffic_control_tally_handled",
89 "Number of tallies handled",
90 registry
91 )
92 .unwrap(),
93 error_tally_handled: register_int_counter_with_registry!(
94 "traffic_control_error_tally_handled",
95 "Number of error tallies handled",
96 registry
97 )
98 .unwrap(),
99 tally_error_types: register_int_counter_vec_with_registry!(
100 "traffic_control_tally_error_types",
101 "Number of tally errors, grouped by error type",
102 &["error_type"],
103 registry
104 )
105 .unwrap(),
106 deadmans_switch_enabled: register_int_gauge_with_registry!(
107 "deadmans_switch_enabled",
108 "If 1, the deadman's switch is enabled and all traffic control
109 should be getting bypassed",
110 registry
111 )
112 .unwrap(),
113 highest_direct_spam_rate: register_int_gauge_with_registry!(
114 "highest_direct_spam_rate",
115 "Highest direct spam rate seen recently",
116 registry
117 )
118 .unwrap(),
119 highest_proxied_spam_rate: register_int_gauge_with_registry!(
120 "highest_proxied_spam_rate",
121 "Highest proxied spam rate seen recently",
122 registry
123 )
124 .unwrap(),
125 highest_direct_error_rate: register_int_gauge_with_registry!(
126 "highest_direct_error_rate",
127 "Highest direct error rate seen recently",
128 registry
129 )
130 .unwrap(),
131 highest_proxied_error_rate: register_int_gauge_with_registry!(
132 "highest_proxied_error_rate",
133 "Highest proxied error rate seen recently",
134 registry
135 )
136 .unwrap(),
137 spam_client_threshold: register_int_gauge_with_registry!(
138 "spam_client_threshold",
139 "Spam client threshold",
140 registry
141 )
142 .unwrap(),
143 error_client_threshold: register_int_gauge_with_registry!(
144 "error_client_threshold",
145 "Error client threshold",
146 registry
147 )
148 .unwrap(),
149 spam_proxied_client_threshold: register_int_gauge_with_registry!(
150 "spam_proxied_client_threshold",
151 "Spam proxied client threshold",
152 registry
153 )
154 .unwrap(),
155 error_proxied_client_threshold: register_int_gauge_with_registry!(
156 "error_proxied_client_threshold",
157 "Error proxied client threshold",
158 registry
159 )
160 .unwrap(),
161 }
162 }
163
164 pub fn new_for_tests() -> Self {
165 Self::new(&Registry::new())
166 }
167}