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
7 changes: 7 additions & 0 deletions src/core/services/statistics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,26 @@ pub async fn get_metrics(tracker: Arc<Tracker>) -> TrackerMetrics {
TrackerMetrics {
torrents_metrics,
protocol_metrics: Metrics {
// TCP
tcp4_connections_handled: stats.tcp4_connections_handled,
tcp4_announces_handled: stats.tcp4_announces_handled,
tcp4_scrapes_handled: stats.tcp4_scrapes_handled,
tcp6_connections_handled: stats.tcp6_connections_handled,
tcp6_announces_handled: stats.tcp6_announces_handled,
tcp6_scrapes_handled: stats.tcp6_scrapes_handled,
// UDP
udp_requests_aborted: stats.udp_requests_aborted,
udp4_requests: stats.udp4_requests,
udp4_connections_handled: stats.udp4_connections_handled,
udp4_announces_handled: stats.udp4_announces_handled,
udp4_scrapes_handled: stats.udp4_scrapes_handled,
udp4_responses: stats.udp4_responses,
udp4_errors_handled: stats.udp4_errors_handled,
udp6_requests: stats.udp6_requests,
udp6_connections_handled: stats.udp6_connections_handled,
udp6_announces_handled: stats.udp6_announces_handled,
udp6_scrapes_handled: stats.udp6_scrapes_handled,
udp6_responses: stats.udp6_responses,
udp6_errors_handled: stats.udp6_errors_handled,
},
}
Expand Down
66 changes: 66 additions & 0 deletions src/core/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,18 @@ pub enum Event {
Tcp4Scrape,
Tcp6Announce,
Tcp6Scrape,
Udp4RequestAborted,
Udp4Request,
Udp4Connect,
Udp4Announce,
Udp4Scrape,
Udp4Response,
Udp4Error,
Udp6Request,
Udp6Connect,
Udp6Announce,
Udp6Scrape,
Udp6Response,
Udp6Error,
}

Expand All @@ -72,26 +77,40 @@ pub struct Metrics {
pub tcp4_announces_handled: u64,
/// Total number of TCP (HTTP tracker) `scrape` requests from IPv4 peers.
pub tcp4_scrapes_handled: u64,

/// Total number of TCP (HTTP tracker) connections from IPv6 peers.
pub tcp6_connections_handled: u64,
/// Total number of TCP (HTTP tracker) `announce` requests from IPv6 peers.
pub tcp6_announces_handled: u64,
/// Total number of TCP (HTTP tracker) `scrape` requests from IPv6 peers.
pub tcp6_scrapes_handled: u64,

/// Total number of UDP (UDP tracker) requests aborted.
pub udp_requests_aborted: u64,

/// Total number of UDP (UDP tracker) requests from IPv4 peers.
pub udp4_requests: u64,
/// Total number of UDP (UDP tracker) connections from IPv4 peers.
pub udp4_connections_handled: u64,
/// Total number of UDP (UDP tracker) `announce` requests from IPv4 peers.
pub udp4_announces_handled: u64,
/// Total number of UDP (UDP tracker) `scrape` requests from IPv4 peers.
pub udp4_scrapes_handled: u64,
/// Total number of UDP (UDP tracker) responses from IPv4 peers.
pub udp4_responses: u64,
/// Total number of UDP (UDP tracker) `error` requests from IPv4 peers.
pub udp4_errors_handled: u64,

/// Total number of UDP (UDP tracker) requests from IPv6 peers.
pub udp6_requests: u64,
/// Total number of UDP (UDP tracker) `connection` requests from IPv6 peers.
pub udp6_connections_handled: u64,
/// Total number of UDP (UDP tracker) `announce` requests from IPv6 peers.
pub udp6_announces_handled: u64,
/// Total number of UDP (UDP tracker) `scrape` requests from IPv6 peers.
pub udp6_scrapes_handled: u64,
/// Total number of UDP (UDP tracker) responses from IPv6 peers.
pub udp6_responses: u64,
/// Total number of UDP (UDP tracker) `error` requests from IPv6 peers.
pub udp6_errors_handled: u64,
}
Expand Down Expand Up @@ -164,7 +183,15 @@ async fn event_handler(event: Event, stats_repository: &Repo) {
stats_repository.increase_tcp6_connections().await;
}

// UDP
Event::Udp4RequestAborted => {
stats_repository.increase_udp_requests_aborted().await;
}

// UDP4
Event::Udp4Request => {
stats_repository.increase_udp4_requests().await;
}
Event::Udp4Connect => {
stats_repository.increase_udp4_connections().await;
}
Expand All @@ -174,11 +201,17 @@ async fn event_handler(event: Event, stats_repository: &Repo) {
Event::Udp4Scrape => {
stats_repository.increase_udp4_scrapes().await;
}
Event::Udp4Response => {
stats_repository.increase_udp4_responses().await;
}
Event::Udp4Error => {
stats_repository.increase_udp4_errors().await;
}

// UDP6
Event::Udp6Request => {
stats_repository.increase_udp6_requests().await;
}
Event::Udp6Connect => {
stats_repository.increase_udp6_connections().await;
}
Expand All @@ -188,6 +221,9 @@ async fn event_handler(event: Event, stats_repository: &Repo) {
Event::Udp6Scrape => {
stats_repository.increase_udp6_scrapes().await;
}
Event::Udp6Response => {
stats_repository.increase_udp6_responses().await;
}
Event::Udp6Error => {
stats_repository.increase_udp6_errors().await;
}
Expand Down Expand Up @@ -276,6 +312,18 @@ impl Repo {
drop(stats_lock);
}

pub async fn increase_udp_requests_aborted(&self) {
let mut stats_lock = self.stats.write().await;
stats_lock.udp_requests_aborted += 1;
drop(stats_lock);
}

pub async fn increase_udp4_requests(&self) {
let mut stats_lock = self.stats.write().await;
stats_lock.udp4_requests += 1;
drop(stats_lock);
}

pub async fn increase_udp4_connections(&self) {
let mut stats_lock = self.stats.write().await;
stats_lock.udp4_connections_handled += 1;
Expand All @@ -294,12 +342,24 @@ impl Repo {
drop(stats_lock);
}

pub async fn increase_udp4_responses(&self) {
let mut stats_lock = self.stats.write().await;
stats_lock.udp4_responses += 1;
drop(stats_lock);
}

pub async fn increase_udp4_errors(&self) {
let mut stats_lock = self.stats.write().await;
stats_lock.udp4_errors_handled += 1;
drop(stats_lock);
}

pub async fn increase_udp6_requests(&self) {
let mut stats_lock = self.stats.write().await;
stats_lock.udp6_requests += 1;
drop(stats_lock);
}

pub async fn increase_udp6_connections(&self) {
let mut stats_lock = self.stats.write().await;
stats_lock.udp6_connections_handled += 1;
Expand All @@ -318,6 +378,12 @@ impl Repo {
drop(stats_lock);
}

pub async fn increase_udp6_responses(&self) {
let mut stats_lock = self.stats.write().await;
stats_lock.udp6_responses += 1;
drop(stats_lock);
}

pub async fn increase_udp6_errors(&self) {
let mut stats_lock = self.stats.write().await;
stats_lock.udp6_errors_handled += 1;
Expand Down
67 changes: 51 additions & 16 deletions src/servers/apis/v1/context/stats/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,40 @@ pub struct Stats {
pub tcp4_announces_handled: u64,
/// Total number of TCP (HTTP tracker) `scrape` requests from IPv4 peers.
pub tcp4_scrapes_handled: u64,

/// Total number of TCP (HTTP tracker) connections from IPv6 peers.
pub tcp6_connections_handled: u64,
/// Total number of TCP (HTTP tracker) `announce` requests from IPv6 peers.
pub tcp6_announces_handled: u64,
/// Total number of TCP (HTTP tracker) `scrape` requests from IPv6 peers.
pub tcp6_scrapes_handled: u64,

/// Total number of UDP (UDP tracker) requests aborted.
pub udp_requests_aborted: u64,

/// Total number of UDP (UDP tracker) requests from IPv4 peers.
pub udp4_requests: u64,
/// Total number of UDP (UDP tracker) connections from IPv4 peers.
pub udp4_connections_handled: u64,
/// Total number of UDP (UDP tracker) `announce` requests from IPv4 peers.
pub udp4_announces_handled: u64,
/// Total number of UDP (UDP tracker) `scrape` requests from IPv4 peers.
pub udp4_scrapes_handled: u64,
/// Total number of UDP (UDP tracker) responses from IPv4 peers.
pub udp4_responses: u64,
/// Total number of UDP (UDP tracker) `scrape` requests from IPv4 peers.
pub udp4_errors_handled: u64,

/// Total number of UDP (UDP tracker) requests from IPv6 peers.
pub udp6_requests: u64,
/// Total number of UDP (UDP tracker) `connection` requests from IPv6 peers.
pub udp6_connections_handled: u64,
/// Total number of UDP (UDP tracker) `announce` requests from IPv6 peers.
pub udp6_announces_handled: u64,
/// Total number of UDP (UDP tracker) `scrape` requests from IPv6 peers.
pub udp6_scrapes_handled: u64,
/// Total number of UDP (UDP tracker) responses from IPv6 peers.
pub udp6_responses: u64,
/// Total number of UDP (UDP tracker) `scrape` requests from IPv6 peers.
pub udp6_errors_handled: u64,
}
Expand All @@ -57,19 +71,26 @@ impl From<TrackerMetrics> for Stats {
seeders: metrics.torrents_metrics.complete,
completed: metrics.torrents_metrics.downloaded,
leechers: metrics.torrents_metrics.incomplete,
// TCP
tcp4_connections_handled: metrics.protocol_metrics.tcp4_connections_handled,
tcp4_announces_handled: metrics.protocol_metrics.tcp4_announces_handled,
tcp4_scrapes_handled: metrics.protocol_metrics.tcp4_scrapes_handled,
tcp6_connections_handled: metrics.protocol_metrics.tcp6_connections_handled,
tcp6_announces_handled: metrics.protocol_metrics.tcp6_announces_handled,
tcp6_scrapes_handled: metrics.protocol_metrics.tcp6_scrapes_handled,
// UDP
udp_requests_aborted: metrics.protocol_metrics.udp_requests_aborted,
udp4_requests: metrics.protocol_metrics.udp4_requests,
udp4_connections_handled: metrics.protocol_metrics.udp4_connections_handled,
udp4_announces_handled: metrics.protocol_metrics.udp4_announces_handled,
udp4_scrapes_handled: metrics.protocol_metrics.udp4_scrapes_handled,
udp4_responses: metrics.protocol_metrics.udp4_responses,
udp4_errors_handled: metrics.protocol_metrics.udp4_errors_handled,
udp6_requests: metrics.protocol_metrics.udp6_requests,
udp6_connections_handled: metrics.protocol_metrics.udp6_connections_handled,
udp6_announces_handled: metrics.protocol_metrics.udp6_announces_handled,
udp6_scrapes_handled: metrics.protocol_metrics.udp6_scrapes_handled,
udp6_responses: metrics.protocol_metrics.udp6_responses,
udp6_errors_handled: metrics.protocol_metrics.udp6_errors_handled,
}
}
Expand All @@ -94,41 +115,55 @@ mod tests {
torrents: 4
},
protocol_metrics: Metrics {
// TCP
tcp4_connections_handled: 5,
tcp4_announces_handled: 6,
tcp4_scrapes_handled: 7,
tcp6_connections_handled: 8,
tcp6_announces_handled: 9,
tcp6_scrapes_handled: 10,
udp4_connections_handled: 11,
udp4_announces_handled: 12,
udp4_scrapes_handled: 13,
udp4_errors_handled: 14,
udp6_connections_handled: 15,
udp6_announces_handled: 16,
udp6_scrapes_handled: 17,
udp6_errors_handled: 18
// UDP
udp_requests_aborted: 11,
udp4_requests: 12,
udp4_connections_handled: 13,
udp4_announces_handled: 14,
udp4_scrapes_handled: 15,
udp4_responses: 16,
udp4_errors_handled: 17,
udp6_requests: 18,
udp6_connections_handled: 19,
udp6_announces_handled: 20,
udp6_scrapes_handled: 21,
udp6_responses: 22,
udp6_errors_handled: 23
}
}),
Stats {
torrents: 4,
seeders: 1,
completed: 2,
leechers: 3,
// TCP
tcp4_connections_handled: 5,
tcp4_announces_handled: 6,
tcp4_scrapes_handled: 7,
tcp6_connections_handled: 8,
tcp6_announces_handled: 9,
tcp6_scrapes_handled: 10,
udp4_connections_handled: 11,
udp4_announces_handled: 12,
udp4_scrapes_handled: 13,
udp4_errors_handled: 14,
udp6_connections_handled: 15,
udp6_announces_handled: 16,
udp6_scrapes_handled: 17,
udp6_errors_handled: 18
// UDP
udp_requests_aborted: 11,
udp4_requests: 12,
udp4_connections_handled: 13,
udp4_announces_handled: 14,
udp4_scrapes_handled: 15,
udp4_responses: 16,
udp4_errors_handled: 17,
udp6_requests: 18,
udp6_connections_handled: 19,
udp6_announces_handled: 20,
udp6_scrapes_handled: 21,
udp6_responses: 22,
udp6_errors_handled: 23
}
);
}
Expand Down
9 changes: 9 additions & 0 deletions src/servers/apis/v1/context/stats/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ pub fn metrics_response(tracker_metrics: &TrackerMetrics) -> Response {
tracker_metrics.protocol_metrics.tcp6_scrapes_handled
));

lines.push(format!(
"udp_requests_aborted {}",
tracker_metrics.protocol_metrics.udp_requests_aborted
));

lines.push(format!("udp4_requests {}", tracker_metrics.protocol_metrics.udp4_requests));
lines.push(format!(
"udp4_connections_handled {}",
tracker_metrics.protocol_metrics.udp4_connections_handled
Expand All @@ -59,11 +65,13 @@ pub fn metrics_response(tracker_metrics: &TrackerMetrics) -> Response {
"udp4_scrapes_handled {}",
tracker_metrics.protocol_metrics.udp4_scrapes_handled
));
lines.push(format!("udp4_responses {}", tracker_metrics.protocol_metrics.udp4_responses));
lines.push(format!(
"udp4_errors_handled {}",
tracker_metrics.protocol_metrics.udp4_errors_handled
));

lines.push(format!("udp6_requests {}", tracker_metrics.protocol_metrics.udp6_requests));
lines.push(format!(
"udp6_connections_handled {}",
tracker_metrics.protocol_metrics.udp6_connections_handled
Expand All @@ -76,6 +84,7 @@ pub fn metrics_response(tracker_metrics: &TrackerMetrics) -> Response {
"udp6_scrapes_handled {}",
tracker_metrics.protocol_metrics.udp6_scrapes_handled
));
lines.push(format!("udp6_responses {}", tracker_metrics.protocol_metrics.udp6_responses));
lines.push(format!(
"udp6_errors_handled {}",
tracker_metrics.protocol_metrics.udp6_errors_handled
Expand Down
Loading
Loading