sui_core/traffic_controller/
metrics.rs

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