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