mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 02:35:31 +00:00
ws: add torrent count metrics
This commit is contained in:
parent
32253a37df
commit
56fafda234
2 changed files with 24 additions and 0 deletions
|
|
@ -154,6 +154,8 @@ pub struct MetricsConfig {
|
||||||
pub run_prometheus_endpoint: bool,
|
pub run_prometheus_endpoint: bool,
|
||||||
/// Address to run prometheus endpoint on
|
/// Address to run prometheus endpoint on
|
||||||
pub prometheus_endpoint_address: SocketAddr,
|
pub prometheus_endpoint_address: SocketAddr,
|
||||||
|
/// Update metrics for torrent count this often, in seconds
|
||||||
|
pub torrent_count_update_interval: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "metrics")]
|
#[cfg(feature = "metrics")]
|
||||||
|
|
@ -162,6 +164,7 @@ impl Default for MetricsConfig {
|
||||||
Self {
|
Self {
|
||||||
run_prometheus_endpoint: false,
|
run_prometheus_endpoint: false,
|
||||||
prometheus_endpoint_address: SocketAddr::from(([0, 0, 0, 0], 9000)),
|
prometheus_endpoint_address: SocketAddr::from(([0, 0, 0, 0], 9000)),
|
||||||
|
torrent_count_update_interval: 10,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,27 @@ pub async fn run_swarm_worker(
|
||||||
})()
|
})()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Periodically update torrent count metrics
|
||||||
|
#[cfg(feature = "metrics")]
|
||||||
|
TimerActionRepeat::repeat(enclose!((config, torrents) move || {
|
||||||
|
enclose!((config, torrents) move || async move {
|
||||||
|
let torrents = torrents.borrow_mut();
|
||||||
|
|
||||||
|
::metrics::gauge!(
|
||||||
|
"aquatic_torrents",
|
||||||
|
torrents.ipv4.len() as f64,
|
||||||
|
"ip_version" => "4"
|
||||||
|
);
|
||||||
|
::metrics::gauge!(
|
||||||
|
"aquatic_torrents",
|
||||||
|
torrents.ipv6.len() as f64,
|
||||||
|
"ip_version" => "6"
|
||||||
|
);
|
||||||
|
|
||||||
|
Some(Duration::from_secs(config.metrics.torrent_count_update_interval))
|
||||||
|
})()
|
||||||
|
}));
|
||||||
|
|
||||||
let mut handles = Vec::new();
|
let mut handles = Vec::new();
|
||||||
|
|
||||||
for (_, receiver) in control_message_receivers.streams() {
|
for (_, receiver) in control_message_receivers.streams() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue