forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatistics.rs
More file actions
62 lines (52 loc) · 2.15 KB
/
statistics.rs
File metadata and controls
62 lines (52 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::sync::Arc;
use crate::tracker::statistics::Metrics;
use crate::tracker::{TorrentsMetrics, Tracker};
#[derive(Debug, PartialEq)]
pub struct TrackerMetrics {
pub torrents_metrics: TorrentsMetrics,
pub protocol_metrics: Metrics,
}
pub async fn get_metrics(tracker: Arc<Tracker>) -> TrackerMetrics {
let torrents_metrics = tracker.get_torrents_metrics().await;
let stats = tracker.get_stats().await;
TrackerMetrics {
torrents_metrics,
protocol_metrics: Metrics {
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,
udp4_connections_handled: stats.udp4_connections_handled,
udp4_announces_handled: stats.udp4_announces_handled,
udp4_scrapes_handled: stats.udp4_scrapes_handled,
udp6_connections_handled: stats.udp6_connections_handled,
udp6_announces_handled: stats.udp6_announces_handled,
udp6_scrapes_handled: stats.udp6_scrapes_handled,
},
}
}
#[cfg(test)]
mod tests {
use std::sync::Arc;
use crate::config::{ephemeral_configuration, Configuration};
use crate::tracker;
use crate::tracker::services::common::tracker_factory;
use crate::tracker::services::statistics::{get_metrics, TrackerMetrics};
pub fn tracker_configuration() -> Arc<Configuration> {
Arc::new(ephemeral_configuration())
}
#[tokio::test]
async fn the_statistics_service_should_return_the_tracker_metrics() {
let tracker = Arc::new(tracker_factory(&tracker_configuration()));
let tracker_metrics = get_metrics(tracker.clone()).await;
assert_eq!(
tracker_metrics,
TrackerMetrics {
torrents_metrics: tracker::TorrentsMetrics::default(),
protocol_metrics: tracker::statistics::Metrics::default(),
}
);
}
}