iroh/socket/
metrics.rs

1use iroh_metrics::{Counter, MetricsGroup};
2use serde::{Deserialize, Serialize};
3
4/// Metrics collected by the iroh socket.
5#[derive(Debug, Serialize, Deserialize, MetricsGroup)]
6#[non_exhaustive]
7#[metrics(name = "socket", default)]
8pub struct Metrics {
9    /// Intended to count updates to the local direct address set, but currently unused
10    /// (never incremented).
11    pub update_direct_addrs: Counter,
12
13    /// Number of bytes sent over IPv4.
14    pub send_ipv4: Counter,
15    /// Number of bytes sent over IPv6.
16    pub send_ipv6: Counter,
17    /// Number of bytes sent over the relay transport.
18    pub send_relay: Counter,
19
20    /// Number of data bytes received over the relay transport.
21    pub recv_data_relay: Counter,
22    /// Number of data bytes received over any custom transport.
23    pub recv_data_custom: Counter,
24    /// Number of data bytes received over IPv4.
25    pub recv_data_ipv4: Counter,
26    /// Number of data bytes received over IPv6.
27    pub recv_data_ipv6: Counter,
28    /// Number of QUIC datagrams received.
29    pub recv_datagrams: Counter,
30    /// Number of receive events that used GRO (coalesced datagram batches).
31    ///
32    /// This counts batches, not the individual datagrams within them. See
33    /// [`Self::recv_datagrams`] for the datagram count.
34    pub recv_gro_datagrams: Counter,
35
36    /// Number of times the home relay changed to a different relay.
37    ///
38    /// This includes the initial assignment from no home relay to a home relay.
39    pub relay_home_change: Counter,
40
41    /// Number of connections to a relay server that were established.
42    ///
43    /// Failed dial attempts are not counted. A relay that is reconnected to is counted
44    /// once per connection, so this grows on every reconnect.
45    pub relay_conns_success: Counter,
46    /// Number of failed attempts to connect to a relay server.
47    ///
48    /// Each attempt is counted, so an unreachable relay increments this on every retry.
49    pub relay_conns_failed: Counter,
50    /// Number of connections to a relay server that ended.
51    ///
52    /// Paired with [`Self::relay_conns_success`], so the number of current connections is
53    /// `relay_conns_success` - `relay_conns_closed`.
54    pub relay_conns_closed: Counter,
55    /// Number of relay connections on which the relay reported rate limiting.
56    ///
57    /// This is incremented at most once per connection, so it counts the affected
58    /// connections and not how often the relay reported the problem. Relate it to
59    /// [`Self::relay_conns_success`] to see how many connections were affected.
60    pub relay_conns_ratelimited: Counter,
61
62    /*
63     * Holepunching metrics
64     */
65    /// The number of times holepunching is initiated on a connection.
66    ///
67    /// This can be incremented multiple times for a single connection. Note that only the
68    /// client-side of a connection will increment this counter.
69    pub holepunch_attempts: Counter,
70    /// The number of network paths to peers that are direct.
71    ///
72    /// This can be incremented multiple times for a single connection.
73    pub paths_direct: Counter,
74    /// The number of network paths to peers that are relayed.
75    ///
76    /// This would typically only be incremented once for a single connection.
77    pub paths_relay: Counter,
78    /// The number of network paths to peers that are user defined.
79    ///
80    /// This would typically only be incremented once for a single connection.
81    pub paths_custom: Counter,
82    /// The number of connections that have been direct connections.
83    ///
84    /// This is only incremented once for each opened connection. See `num_conns_opened` for
85    /// the number of opened connections.
86    pub num_conns_direct: Counter,
87
88    /*
89     * Connection Metrics
90     *
91     * These all only count connections that completed the TLS handshake successfully. This means
92     * that short lived 0RTT connections are potentially not included in these counts.
93     */
94    /// Number of connections opened (only handshaked connections are counted).
95    pub num_conns_opened: Counter,
96    /// Number of connections closed (only handshaked connections are counted).
97    pub num_conns_closed: Counter,
98
99    /// Number of IP transport paths opened.
100    pub transport_ip_paths_added: Counter,
101    /// Number of IP transport paths closed.
102    pub transport_ip_paths_removed: Counter,
103    /// Number of relay transport paths opened.
104    pub transport_relay_paths_added: Counter,
105    /// Number of relay transport paths closed.
106    pub transport_relay_paths_removed: Counter,
107    /// Number of custom transport paths opened.
108    pub transport_custom_paths_added: Counter,
109    /// Number of custom transport paths closed.
110    pub transport_custom_paths_removed: Counter,
111
112    /// Number of iterations of the main socket actor loop.
113    pub actor_tick_main: Counter,
114    /// Number of actor messages processed by the socket actor loop.
115    pub actor_tick_msg: Counter,
116    /// Number of periodic re-STUN timer ticks handled by the socket actor loop.
117    pub actor_tick_re_stun: Counter,
118    /// Number of port-mapping change events handled by the socket actor loop.
119    pub actor_tick_portmap_changed: Counter,
120    /// Intended to count direct address heartbeat ticks, but currently unused (never incremented).
121    pub actor_tick_direct_addr_heartbeat: Counter,
122    /// Number of local network interface (link) change events handled by the socket actor loop.
123    pub actor_link_change: Counter,
124    /// Number of times an input watcher or receiver closed in the socket actor loop.
125    pub actor_tick_other: Counter,
126}