iroh_net/relay/server/
metrics.rs

1use iroh_metrics::{
2    core::{Counter, Metric},
3    struct_iterable::Iterable,
4};
5
6/// Metrics tracked for the relay server
7#[allow(missing_docs)]
8#[derive(Debug, Clone, Iterable)]
9pub struct Metrics {
10    /*
11     * Metrics about packets
12     */
13    /// Bytes sent from a `FrameType::SendPacket`
14    pub bytes_sent: Counter,
15    /// Bytes received from a `FrameType::SendPacket`
16    pub bytes_recv: Counter,
17
18    /// `FrameType::SendPacket` sent, that are not disco messages
19    pub send_packets_sent: Counter,
20    /// `FrameType::SendPacket` received, that are not disco messages
21    pub send_packets_recv: Counter,
22    /// `FrameType::SendPacket` dropped, that are not disco messages
23    pub send_packets_dropped: Counter,
24
25    /// `FrameType::SendPacket` sent that are disco messages
26    pub disco_packets_sent: Counter,
27    /// `FrameType::SendPacket` received that are disco messages
28    pub disco_packets_recv: Counter,
29    /// `FrameType::SendPacket` dropped that are disco messages
30    pub disco_packets_dropped: Counter,
31
32    /// Packets of other `FrameType`s sent
33    pub other_packets_sent: Counter,
34    /// Packets of other `FrameType`s received
35    pub other_packets_recv: Counter,
36    /// Packets of other `FrameType`s dropped
37    pub other_packets_dropped: Counter,
38
39    /// Number of `FrameType::Ping`s received
40    pub got_ping: Counter,
41    /// Number of `FrameType::Pong`s sent
42    pub sent_pong: Counter,
43    /// Number of `FrameType::Unknown` received
44    pub unknown_frames: Counter,
45
46    /*
47     * Metrics about peers
48     */
49    /// Number of connections we have accepted
50    pub accepts: Counter,
51    /// Number of connections we have removed because of an error
52    pub disconnects: Counter,
53
54    /// Number of unique client keys per day
55    pub unique_client_keys: Counter,
56
57    /// Number of accepted websocket connections
58    pub websocket_accepts: Counter,
59    /// Number of accepted 'iroh derp http' connection upgrades
60    pub derp_accepts: Counter,
61    // TODO: enable when we can have multiple connections for one node id
62    // pub duplicate_client_keys: Counter,
63    // pub duplicate_client_conns: Counter,
64    // TODO: only important stat that we cannot track right now
65    // pub average_queue_duration:
66}
67
68impl Default for Metrics {
69    fn default() -> Self {
70        Self {
71            /*
72             * Metrics about packets
73             */
74            send_packets_sent: Counter::new("Number of 'send' packets relayed."),
75            bytes_sent: Counter::new("Number of bytes sent."),
76            send_packets_recv: Counter::new("Number of 'send' packets received."),
77            bytes_recv: Counter::new("Number of bytes received."),
78            send_packets_dropped: Counter::new("Number of 'send' packets dropped."),
79            disco_packets_sent: Counter::new("Number of disco packets sent."),
80            disco_packets_recv: Counter::new("Number of disco packets received."),
81            disco_packets_dropped: Counter::new("Number of disco packets dropped."),
82
83            other_packets_sent: Counter::new(
84                "Number of packets sent that were not disco packets or 'send' packets",
85            ),
86            other_packets_recv: Counter::new(
87                "Number of packets received that were not disco packets or 'send' packets",
88            ),
89            other_packets_dropped: Counter::new(
90                "Number of times a non-disco, non-'send; packet was dropped.",
91            ),
92            got_ping: Counter::new("Number of times the server has received a Ping from a client."),
93            sent_pong: Counter::new("Number of times the server has sent a Pong to a client."),
94            unknown_frames: Counter::new("Number of unknown frames sent to this server."),
95
96            /*
97             * Metrics about peers
98             */
99            accepts: Counter::new("Number of times this server has accepted a connection."),
100            disconnects: Counter::new("Number of clients that have then disconnected."),
101
102            unique_client_keys: Counter::new("Number of unique client keys per day."),
103
104            websocket_accepts: Counter::new("Number of accepted websocket connections"),
105            derp_accepts: Counter::new("Number of accepted 'iroh derp http' connection upgrades"),
106            // TODO: enable when we can have multiple connections for one node id
107            // pub duplicate_client_keys: Counter::new("Number of duplicate client keys."),
108            // pub duplicate_client_conns: Counter::new("Number of duplicate client connections."),
109            // TODO: only important stat that we cannot track right now
110            // pub average_queue_duration:
111        }
112    }
113}
114
115impl Metric for Metrics {
116    fn name() -> &'static str {
117        "relayserver"
118    }
119}