Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ unexpected_cfgs = { level = "warn", check-cfg = ["cfg(iroh_docsrs)", "cfg(iroh_l
unused-async = "warn"

[patch.crates-io]
iroh-metrics = { git = "https://github.com/n0-computer/iroh-metrics", branch = "Frando/refactor" }
iroh-metrics = { git = "https://github.com/n0-computer/iroh-metrics", branch = "Frando/refactor2" }
53 changes: 19 additions & 34 deletions iroh-dns-server/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,56 +1,41 @@
//! Metrics support for the server

use iroh_metrics::{struct_iterable::Iterable, Counter, MetricsGroup};
use iroh_metrics::{Counter, MetricsGroup};

/// Metrics for iroh-dns-server
#[derive(Debug, Clone, Iterable)]
#[allow(missing_docs)]
#[derive(Debug, Clone, MetricsGroup)]
#[metrics(name = "dns_server")]
pub struct Metrics {
/// Number of pkarr relay puts that updated the state
pub pkarr_publish_update: Counter,
/// Number of pkarr relay puts that did not update the state
pub pkarr_publish_noop: Counter,
/// DNS requests (total)
pub dns_requests: Counter,
/// DNS requests via UDP
pub dns_requests_udp: Counter,
/// DNS requests via HTTPS (DoH)
pub dns_requests_https: Counter,
/// DNS lookup responses with at least one answer
pub dns_lookup_success: Counter,
/// DNS lookup responses with no answers
pub dns_lookup_notfound: Counter,
/// DNS lookup responses which failed
pub dns_lookup_error: Counter,
/// Number of HTTP requests
pub http_requests: Counter,
/// Number of HTTP requests with a 2xx status code
pub http_requests_success: Counter,
/// Number of HTTP requests with a non-2xx status code
pub http_requests_error: Counter,
/// Total duration of all HTTP requests
pub http_requests_duration_ms: Counter,
/// Signed packets inserted into the store
pub store_packets_inserted: Counter,
/// Signed packets removed from the store
pub store_packets_removed: Counter,
/// Number of updates to existing packets
pub store_packets_updated: Counter,
/// Number of expired packets
pub store_packets_expired: Counter,
}

impl Default for Metrics {
fn default() -> Self {
Self {
pkarr_publish_update: Counter::new("Number of pkarr relay puts that updated the state"),
pkarr_publish_noop: Counter::new(
"Number of pkarr relay puts that did not update the state",
),
dns_requests: Counter::new("DNS requests (total)"),
dns_requests_udp: Counter::new("DNS requests via UDP"),
dns_requests_https: Counter::new("DNS requests via HTTPS (DoH)"),
dns_lookup_success: Counter::new("DNS lookup responses with at least one answer"),
dns_lookup_notfound: Counter::new("DNS lookup responses with no answers"),
dns_lookup_error: Counter::new("DNS lookup responses which failed"),
http_requests: Counter::new("Number of HTTP requests"),
http_requests_success: Counter::new("Number of HTTP requests with a 2xx status code"),
http_requests_error: Counter::new("Number of HTTP requests with a non-2xx status code"),
http_requests_duration_ms: Counter::new("Total duration of all HTTP requests"),
store_packets_inserted: Counter::new("Signed packets inserted into the store"),
store_packets_removed: Counter::new("Signed packets removed from the store"),
store_packets_updated: Counter::new("Number of updates to existing packets"),
store_packets_expired: Counter::new("Number of expired packets"),
}
}
}

impl MetricsGroup for Metrics {
fn name(&self) -> &'static str {
"dns_server"
}
}
123 changes: 28 additions & 95 deletions iroh-relay/src/server/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,59 @@
use std::sync::Arc;

use iroh_metrics::{struct_iterable::Iterable, Counter, MetricsGroup, MetricsGroupSet};
use iroh_metrics::{Counter, MetricsGroup, MetricsGroupSet};

/// Metrics tracked for the relay server
#[derive(Debug, Clone, Iterable)]
#[derive(Debug, Clone, MetricsGroup)]
#[metrics(name = "relayserver")]
pub struct Metrics {
/*
* Metrics about packets
*/
/// Bytes sent from a `FrameType::SendPacket`
#[metrics(help = "Number of bytes sent.")]
pub bytes_sent: Counter,
/// Bytes received from a `FrameType::SendPacket`
#[metrics(help = "Number of bytes received.")]
pub bytes_recv: Counter,

/// `FrameType::SendPacket` sent, that are not disco messages
#[metrics(help = "Number of 'send' packets relayed.")]
pub send_packets_sent: Counter,
/// `FrameType::SendPacket` received, that are not disco messages
#[metrics(help = "Number of 'send' packets received.")]
pub send_packets_recv: Counter,
/// `FrameType::SendPacket` dropped, that are not disco messages
#[metrics(help = "Number of 'send' packets dropped.")]
pub send_packets_dropped: Counter,

/// `FrameType::SendPacket` sent that are disco messages
#[metrics(help = "Number of disco packets sent.")]
pub disco_packets_sent: Counter,
/// `FrameType::SendPacket` received that are disco messages
#[metrics(help = "Number of disco packets received.")]
pub disco_packets_recv: Counter,
/// `FrameType::SendPacket` dropped that are disco messages
#[metrics(help = "Number of disco packets dropped.")]
pub disco_packets_dropped: Counter,

/// Packets of other `FrameType`s sent
#[metrics(help = "Number of packets sent that were not disco packets or 'send' packets")]
pub other_packets_sent: Counter,
/// Packets of other `FrameType`s received
#[metrics(help = "Number of packets received that were not disco packets or 'send' packets")]
pub other_packets_recv: Counter,
/// Packets of other `FrameType`s dropped
#[metrics(help = "Number of times a non-disco, non-send packet was dropped.")]
pub other_packets_dropped: Counter,

/// Number of `FrameType::Ping`s received
#[metrics(help = "Number of times the server has received a Ping from a client.")]
pub got_ping: Counter,
/// Number of `FrameType::Pong`s sent
#[metrics(help = "Number of times the server has sent a Pong to a client.")]
pub sent_pong: Counter,
/// Number of `FrameType::Unknown` received
#[metrics(help = "Number of unknown frames sent to this server.")]
pub unknown_frames: Counter,

/// Number of frames received from client connection which have been rate-limited.
Expand All @@ -49,15 +64,16 @@ pub struct Metrics {
/*
* Metrics about peers
*/
/// Number of connections we have accepted
/// Number of times this server has accepted a connection.
pub accepts: Counter,
/// Number of connections we have removed because of an error
#[metrics(help = "Number of clients that have then disconnected.")]
pub disconnects: Counter,

/// Number of unique client keys per day
pub unique_client_keys: Counter,

/// Number of accepted websocket connections
/// Number of accepted websocket connections.
pub websocket_accepts: Counter,
/// Number of accepted 'iroh derp http' connection upgrades
pub relay_accepts: Counter,
Expand All @@ -68,105 +84,22 @@ pub struct Metrics {
// pub average_queue_duration:
}

impl Default for Metrics {
fn default() -> Self {
Self {
/*
* Metrics about packets
*/
send_packets_sent: Counter::new("Number of 'send' packets relayed."),
bytes_sent: Counter::new("Number of bytes sent."),
send_packets_recv: Counter::new("Number of 'send' packets received."),
bytes_recv: Counter::new("Number of bytes received."),
send_packets_dropped: Counter::new("Number of 'send' packets dropped."),
disco_packets_sent: Counter::new("Number of disco packets sent."),
disco_packets_recv: Counter::new("Number of disco packets received."),
disco_packets_dropped: Counter::new("Number of disco packets dropped."),

other_packets_sent: Counter::new(
"Number of packets sent that were not disco packets or 'send' packets",
),
other_packets_recv: Counter::new(
"Number of packets received that were not disco packets or 'send' packets",
),
other_packets_dropped: Counter::new(
"Number of times a non-disco, non-'send; packet was dropped.",
),
got_ping: Counter::new("Number of times the server has received a Ping from a client."),
sent_pong: Counter::new("Number of times the server has sent a Pong to a client."),
unknown_frames: Counter::new("Number of unknown frames sent to this server."),
frames_rx_ratelimited_total: Counter::new(
"Number of frames received from client connection which have been rate-limited.",
),
conns_rx_ratelimited_total: Counter::new(
"Number of client connections which have had any frames rate-limited.",
),

/*
* Metrics about peers
*/
accepts: Counter::new("Number of times this server has accepted a connection."),
disconnects: Counter::new("Number of clients that have then disconnected."),

unique_client_keys: Counter::new("Number of unique client keys per day."),

websocket_accepts: Counter::new("Number of accepted websocket connections"),
relay_accepts: Counter::new("Number of accepted 'iroh derp http' connection upgrades"),
// TODO: enable when we can have multiple connections for one node id
// pub duplicate_client_keys: Counter::new("Number of duplicate client keys."),
// pub duplicate_client_conns: Counter::new("Number of duplicate client connections."),
// TODO: only important stat that we cannot track right now
// pub average_queue_duration:
}
}
}

impl MetricsGroup for Metrics {
fn name(&self) -> &'static str {
"relayserver"
}
}

/// StunMetrics tracked for the relay server
#[derive(Debug, Clone, Iterable)]
#[derive(Debug, Clone, MetricsGroup)]
#[metrics(name = "stun")]
pub struct StunMetrics {
/*
* Metrics about STUN requests
*/
/// Number of stun requests made
/// Number of STUN requests made to the server.
pub requests: Counter,
/// Number of successful requests over ipv4
/// Number of successful ipv4 STUN requests served.
pub ipv4_success: Counter,
/// Number of successful requests over ipv6
/// Number of successful ipv6 STUN requests served.
pub ipv6_success: Counter,

/// Number of bad requests, either non-stun packets or incorrect binding request
/// Number of bad requests made to the STUN endpoint.
pub bad_requests: Counter,
/// Number of failures
/// Number of STUN requests that end in failure.
pub failures: Counter,
}

impl Default for StunMetrics {
fn default() -> Self {
Self {
/*
* Metrics about STUN requests
*/
requests: Counter::new("Number of STUN requests made to the server."),
ipv4_success: Counter::new("Number of successful ipv4 STUN requests served."),
ipv6_success: Counter::new("Number of successful ipv6 STUN requests served."),
bad_requests: Counter::new("Number of bad requests made to the STUN endpoint."),
failures: Counter::new("Number of STUN requests that end in failure."),
}
}
}

impl MetricsGroup for StunMetrics {
fn name(&self) -> &'static str {
"stun"
}
}

#[derive(Debug, Default, Clone)]
pub struct RelayMetrics {
pub stun: Arc<StunMetrics>,
Expand All @@ -178,7 +111,7 @@ impl MetricsGroupSet for RelayMetrics {
"relay"
}

fn iter(&self) -> impl Iterator<Item = &dyn MetricsGroup> {
fn groups(&self) -> impl Iterator<Item = &dyn MetricsGroup> {
[
&*self.stun as &dyn MetricsGroup,
&*self.server as &dyn MetricsGroup,
Expand Down
2 changes: 1 addition & 1 deletion iroh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ hickory-resolver = "0.25.1"
igd-next = { version = "0.15.1", features = ["aio_tokio"] }
netdev = { version = "0.31.0" }
# portmapper = { version = "0.4.1", default-features = false }
portmapper = { git = "https://github.com/n0-computer/net-tools", branch = "Frando/metrics" }
portmapper = { git = "https://github.com/n0-computer/net-tools", branch = "Frando/metrics2" }
quinn = { package = "iroh-quinn", version = "0.13.0", default-features = false, features = ["runtime-tokio", "rustls-ring"] }
tokio = { version = "1", features = [
"io-util",
Expand Down
17 changes: 9 additions & 8 deletions iroh/bench/src/bin/bulk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use clap::Parser;
#[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))]
use iroh_bench::quinn;
use iroh_bench::{configure_tracing_subscriber, iroh, rt, s2n, Commands, Opt};
use iroh_metrics::{MetricValue, MetricsGroup};

fn main() {
let cmd = Commands::parse();
Expand Down Expand Up @@ -158,15 +159,15 @@ pub fn run_s2n(_opt: s2n::Opt) -> Result<()> {
unimplemented!()
}

fn collect_and_print(
category: &'static str,
metrics: &impl iroh_metrics::struct_iterable::Iterable,
) {
fn collect_and_print(category: &'static str, metrics: &dyn MetricsGroup) {
let mut map = BTreeMap::new();
for (name, counter) in metrics.iter() {
if let Some(counter) = counter.downcast_ref::<iroh_metrics::Counter>() {
map.insert(name.to_string(), counter.get());
}
for item in metrics.iter() {
let value: i64 = match item.value() {
MetricValue::Counter(v) => v as i64,
MetricValue::Gauge(v) => v,
_ => continue,
};
map.insert(item.name().to_string(), value);
}
println!("{category}: {map:#?}");
}
Loading
Loading