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}
29
30impl TrafficControllerMetrics {
31 pub fn new(registry: &Registry) -> Self {
32 Self {
33 tallies: register_int_counter_with_registry!("tallies", "Number of tallies", registry)
34 .unwrap(),
35 connection_ip_blocklist_len: register_int_gauge_with_registry!(
36 "connection_ip_blocklist_len",
37 "Number of connection IP addresses (IP addresses as registered \
39 via direct socket connection to the reporting node) in the \
40 protocol layer blocklist",
41 registry
42 )
43 .unwrap(),
44 proxy_ip_blocklist_len: register_int_gauge_with_registry!(
45 "proxy_ip_blocklist_len",
46 "Number of proxy IP addresses (IP addresses as collected \
48 via some mechanism through proxy node such as fullnode) \
49 in the protocol layer blocklist",
50 registry
51 )
52 .unwrap(),
53 requests_blocked_at_protocol: register_int_counter_with_registry!(
54 "requests_blocked_at_protocol",
55 "Number of requests blocked by this node at the protocol level",
56 registry
57 )
58 .unwrap(),
59 blocks_delegated_to_firewall: register_int_counter_with_registry!(
60 "blocks_delegated_to_firewall",
61 "Number of delegation requests to firewall to add to blocklist",
62 registry
63 )
64 .unwrap(),
65 firewall_delegation_request_fail: register_int_counter_with_registry!(
66 "firewall_delegation_request_fail",
67 "Number of failed http requests to firewall for blocklist delegation",
68 registry
69 )
70 .unwrap(),
71 tally_channel_overflow: register_int_counter_with_registry!(
72 "tally_channel_overflow",
73 "Traffic controller tally channel overflow count",
74 registry
75 )
76 .unwrap(),
77 num_dry_run_blocked_requests: register_int_counter_with_registry!(
78 "traffic_control_num_dry_run_blocked_requests",
79 "Number of requests blocked in traffic controller dry run mode",
80 registry
81 )
82 .unwrap(),
83 tally_handled: register_int_counter_with_registry!(
84 "traffic_control_tally_handled",
85 "Number of tallies handled",
86 registry
87 )
88 .unwrap(),
89 error_tally_handled: register_int_counter_with_registry!(
90 "traffic_control_error_tally_handled",
91 "Number of error tallies handled",
92 registry
93 )
94 .unwrap(),
95 tally_error_types: register_int_counter_vec_with_registry!(
96 "traffic_control_tally_error_types",
97 "Number of tally errors, grouped by error type",
98 &["error_type"],
99 registry
100 )
101 .unwrap(),
102 deadmans_switch_enabled: register_int_gauge_with_registry!(
103 "deadmans_switch_enabled",
104 "If 1, the deadman's switch is enabled and all traffic control
105 should be getting bypassed",
106 registry
107 )
108 .unwrap(),
109 highest_direct_spam_rate: register_int_gauge_with_registry!(
110 "highest_direct_spam_rate",
111 "Highest direct spam rate seen recently",
112 registry
113 )
114 .unwrap(),
115 highest_proxied_spam_rate: register_int_gauge_with_registry!(
116 "highest_proxied_spam_rate",
117 "Highest proxied spam rate seen recently",
118 registry
119 )
120 .unwrap(),
121 highest_direct_error_rate: register_int_gauge_with_registry!(
122 "highest_direct_error_rate",
123 "Highest direct error rate seen recently",
124 registry
125 )
126 .unwrap(),
127 highest_proxied_error_rate: register_int_gauge_with_registry!(
128 "highest_proxied_error_rate",
129 "Highest proxied error rate seen recently",
130 registry
131 )
132 .unwrap(),
133 }
134 }
135
136 pub fn new_for_tests() -> Self {
137 Self::new(&Registry::new())
138 }
139}