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
28 lines (23 loc) · 964 Bytes
/
Copy pathstatistics.rs
File metadata and controls
28 lines (23 loc) · 964 Bytes
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
//! Statistics helpers — query aggregate metrics from the REST API.
use url::Url;
/// Global statistics with only metrics relevant to the test.
#[derive(serde::Deserialize)]
#[allow(dead_code)]
pub struct PartialGlobalStatistics {
pub tcp4_announces_handled: u64,
pub udp4_announces_handled: u64,
}
#[allow(dead_code)]
pub async fn get_tracker_statistics(api_url: &Url, token: &str) -> PartialGlobalStatistics {
use torrust_tracker_rest_api_client::connection_info::{ConnectionInfo, Origin};
use torrust_tracker_rest_api_client::v1::client::ApiHttpClient as TrackerApiClient;
let response = TrackerApiClient::new(ConnectionInfo::authenticated(Origin::new(api_url.as_str()).unwrap(), token))
.unwrap()
.get_tracker_statistics(None)
.await
.expect("failed to get tracker statistics");
response
.json::<PartialGlobalStatistics>()
.await
.expect("Failed to parse JSON response")
}