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")]
8pub struct Metrics {
9    /*
10     * Metrics about packets
11     */
12    /// Bytes sent from a `FrameType::SendPacket`
13    #[metrics(help = "Number of bytes sent.")]
14    pub bytes_sent: Counter,
15    /// Bytes received from a `FrameType::SendPacket`
16    #[metrics(help = "Number of bytes received.")]
17    pub bytes_recv: Counter,
18
19    /// `FrameType::SendPacket` sent
20    #[metrics(help = "Number of 'send' packets relayed.")]
21    pub send_packets_sent: Counter,
22    /// `FrameType::SendPacket` received
23    #[metrics(help = "Number of 'send' packets received.")]
24    pub send_packets_recv: Counter,
25    /// `FrameType::SendPacket` dropped
26    #[metrics(help = "Number of 'send' packets dropped.")]
27    pub send_packets_dropped: Counter,
28
29    /// Packets of other `FrameType`s sent
30    #[metrics(help = "Number of packets sent that were not 'send' packets")]
31    pub other_packets_sent: Counter,
32    /// Packets of other `FrameType`s received
33    #[metrics(help = "Number of packets received that were not 'send' packets")]
34    pub other_packets_recv: Counter,
35    /// Packets of other `FrameType`s dropped
36    #[metrics(help = "Number of times, non-send packet was dropped.")]
37    pub other_packets_dropped: Counter,
38
39    /// Number of `FrameType::Ping`s received
40    #[metrics(help = "Number of times the server has received a Ping from a client.")]
41    pub got_ping: Counter,
42    /// Number of `FrameType::Pong`s sent
43    #[metrics(help = "Number of times the server has sent a Pong to a client.")]
44    pub sent_pong: Counter,
45    /// Number of `FrameType::Unknown` received
46    #[metrics(help = "Number of unknown frames sent to this server.")]
47    pub unknown_frames: Counter,
48
49    /// Number of bytes received from client connection which have been rate-limited.
50    pub bytes_rx_ratelimited_total: Counter,
51    /// Number of client connections which have had any frames rate-limited.
52    pub conns_rx_ratelimited_total: Counter,
53
54    /*
55     * Metrics about peers
56     */
57    /// Number of times this server has accepted a connection.
58    pub accepts: Counter,
59    /// Number of connections we have removed because of an error
60    #[metrics(help = "Number of clients that have then disconnected.")]
61    pub disconnects: Counter,
62
63    /// Number of unique client keys per day
64    pub unique_client_keys: Counter,
65    // TODO: enable when we can have multiple connections for one endpoint id
66    // pub duplicate_client_keys: Counter,
67    // pub duplicate_client_conns: Counter,
68    // TODO: only important stat that we cannot track right now
69    // pub average_queue_duration:
70}
71
72/// All metrics tracked in the relay server.
73#[derive(Debug, Default, Clone, MetricsGroupSet)]
74#[metrics(name = "relay")]
75pub struct RelayMetrics {
76    /// Metrics tracked for the relay server.
77    pub server: Arc<Metrics>,
78}