iroh_relay/server/
metrics.rs

1use std::sync::Arc;
2
3use iroh_metrics::{Counter, MetricsGroup, MetricsGroupSet};
4
5/// Metrics tracked for the relay server
6#[derive(Debug, Default, MetricsGroup)]
7#[metrics(name = "relayserver")]
8#[non_exhaustive]
9pub struct Metrics {
10    /*
11     * Metrics about packets
12     */
13    /// Bytes sent to a client in [`RelayToClientDatagram`] or [`RelayToClientDatagramBatch`] frames.
14    ///
15    /// [`RelayToClientDatagram`]: crate::protos::common::FrameType::RelayToClientDatagram
16    /// [`RelayToClientDatagramBatch`]: crate::protos::common::FrameType::RelayToClientDatagramBatch
17    #[metrics(help = "Number of bytes sent.")]
18    pub bytes_sent: Counter,
19    /// Bytes received from a client in [`ClientToRelayDatagram`] or [`ClientToRelayDatagramBatch`] frames.
20    ///
21    /// [`ClientToRelayDatagram`]: crate::protos::common::FrameType::ClientToRelayDatagram
22    /// [`ClientToRelayDatagramBatch`]: crate::protos::common::FrameType::ClientToRelayDatagramBatch
23    #[metrics(help = "Number of bytes received.")]
24    pub bytes_recv: Counter,
25
26    /// [`RelayToClientDatagram`] or [`RelayToClientDatagramBatch`] frames sent to a client.
27    ///
28    /// [`RelayToClientDatagram`]: crate::protos::common::FrameType::RelayToClientDatagram
29    /// [`RelayToClientDatagramBatch`]: crate::protos::common::FrameType::RelayToClientDatagramBatch
30    #[metrics(help = "Number of 'send' packets relayed.")]
31    pub send_packets_sent: Counter,
32    /// [`ClientToRelayDatagram`] or [`ClientToRelayDatagramBatch`] frames received from a client.
33    ///
34    /// [`ClientToRelayDatagram`]: crate::protos::common::FrameType::ClientToRelayDatagram
35    /// [`ClientToRelayDatagramBatch`]: crate::protos::common::FrameType::ClientToRelayDatagramBatch
36    #[metrics(help = "Number of 'send' packets received.")]
37    pub send_packets_recv: Counter,
38    /// [`RelayToClientDatagram`] or [`RelayToClientDatagramBatch`] frames dropped instead of being
39    /// delivered to a client, because the recipient is not connected or writing to its stream failed.
40    ///
41    /// Note that frames dropped because the recipient's send queue is full or closed are not counted
42    /// here.
43    ///
44    /// [`RelayToClientDatagram`]: crate::protos::common::FrameType::RelayToClientDatagram
45    /// [`RelayToClientDatagramBatch`]: crate::protos::common::FrameType::RelayToClientDatagramBatch
46    #[metrics(help = "Number of 'send' packets dropped.")]
47    pub send_packets_dropped: Counter,
48
49    /// Intended to count sent frames other than datagrams, but currently unused (never incremented).
50    #[metrics(help = "Number of packets sent that were not 'send' packets")]
51    pub other_packets_sent: Counter,
52    /// Intended to count received frames other than datagrams, but currently unused (never incremented).
53    #[metrics(help = "Number of packets received that were not 'send' packets")]
54    pub other_packets_recv: Counter,
55    /// Intended to count dropped frames other than datagrams, but currently unused (never incremented).
56    #[metrics(help = "Number of times, non-send packet was dropped.")]
57    pub other_packets_dropped: Counter,
58
59    /// Number of [`FrameType::Ping`](crate::protos::common::FrameType::Ping) frames received from a client.
60    #[metrics(help = "Number of times the server has received a Ping from a client.")]
61    pub got_ping: Counter,
62    /// Number of [`FrameType::Pong`](crate::protos::common::FrameType::Pong) frames sent to a client.
63    #[metrics(help = "Number of times the server has sent a Pong to a client.")]
64    pub sent_pong: Counter,
65    /// Intended to count received frames with an unrecognized [`FrameType`](crate::protos::common::FrameType),
66    /// but currently unused (never incremented).
67    #[metrics(help = "Number of unknown frames sent to this server.")]
68    pub unknown_frames: Counter,
69
70    /// Number of bytes received from client connection which have been rate-limited.
71    pub bytes_rx_ratelimited_total: Counter,
72    /// Number of client connections which have had any frames rate-limited.
73    pub conns_rx_ratelimited_total: Counter,
74
75    /*
76     * Metrics about peers
77     */
78    /// Number of times this server has accepted a connection.
79    pub accepts: Counter,
80    /// Number of times a client connection was disconnected.
81    ///
82    /// Incremented once per connection, paired with [`Self::accepts`].
83    #[metrics(help = "Number of clients that have then disconnected.")]
84    pub disconnects: Counter,
85
86    /// Number of unique client keys per day
87    pub unique_client_keys: Counter,
88
89    /// Number of times a client was moved into the inactive state.
90    ///
91    /// A client becomes inactive when a new client connects with the same endpoint id. An inactive
92    /// client can still send messages, but won't receive anything. If the currently-active client
93    /// disconnects, and if there are inactive clients, the most-recent inactive client becomes
94    /// active again.
95    ///
96    /// The number of inactive clients at any time is `clients_inactive_added` - `clients_inactive_removed`.
97    pub clients_inactive_added: Counter,
98
99    /// Number of times a client was removed from the inactive state.
100    ///
101    /// This is increased whenever a client disconnects while being inactive, or if a client is upgraded to be
102    /// active again (happens only when the currently-active client for that endpoint id disconnects).
103    ///
104    /// See [`Self::clients_inactive_added`] for details on when a client becomes inactive.
105    pub clients_inactive_removed: Counter,
106
107    // TODO: only important stat that we cannot track right now
108    // pub average_queue_duration:
109    //
110    /// Number of incoming QAD connections.
111    ///
112    /// After completion, each is counted in either `qad_incoming_error` or `qad_connections`.
113    ///
114    /// Thus the number of inflight incomings is `qad_incoming` - `qad_incoming_error` - `qad_connections`.
115    pub qad_incoming: Counter,
116
117    /// Number of QAD QUIC connections that aborted before completing the handshake.
118    pub qad_incoming_error: Counter,
119
120    /// Number of accepted QAD QUIC connections.
121    ///
122    /// The number of active connections is `qad_connections` - `qad_connections_closed`.
123    pub qad_connections: Counter,
124
125    /// Number of QAD QUIC connections that disconnected after being accepted.
126    pub qad_connections_closed: Counter,
127
128    /// Number of QAD QUIC connections that disconnected after being accepted, with an error.
129    ///
130    /// The number is *included* in `qad_connections_closed` (not in addition to).
131    pub qad_connections_errored: Counter,
132
133    /// Number of accepted HTTP(S) connections.
134    ///
135    /// The number of active connections at any time is `http_connections` - `http_connections_closed`
136    pub http_connections: Counter,
137
138    /// Number of terminated HTTP(S) connections.
139    pub http_connections_closed: Counter,
140
141    /// Number of HTTP(S) connections that terminated with an error.
142    ///
143    /// The number is *included* in `http_connections_closed` (not in addition to).
144    pub http_connections_errored: Counter,
145}
146
147/// All metrics tracked in the relay server.
148#[derive(Debug, Default, Clone, MetricsGroupSet)]
149#[metrics(name = "relay")]
150#[non_exhaustive]
151pub struct RelayMetrics {
152    /// Metrics tracked for the relay server.
153    pub server: Arc<Metrics>,
154}