iota_core/traffic_controller/
metrics.rs

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