Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7a3ed17952 | |||
| 7e1962a168 |
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard"
|
||||
version = "0.1.241"
|
||||
version = "0.1.243"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
@@ -301,7 +301,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard-agent"
|
||||
version = "0.1.241"
|
||||
version = "0.1.243"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
@@ -325,7 +325,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard-shared"
|
||||
version = "0.1.241"
|
||||
version = "0.1.243"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"serde",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard-agent"
|
||||
version = "0.1.242"
|
||||
version = "0.1.244"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -164,7 +164,7 @@ impl SystemdCollector {
|
||||
let metrics = Vec::new();
|
||||
|
||||
sub_services.push(SubServiceData {
|
||||
name: format!("ip: {}", external_ip),
|
||||
name: format!("route: {}", external_ip),
|
||||
service_status: Status::Info,
|
||||
metrics,
|
||||
service_type: "vpn_route".to_string(),
|
||||
@@ -172,6 +172,19 @@ impl SystemdCollector {
|
||||
}
|
||||
}
|
||||
|
||||
if service_name == "transmission-vpn" && status_info.active_state == "active" {
|
||||
if let Some((active_count, download_mbps, upload_mbps)) = self.get_transmission_stats() {
|
||||
let metrics = Vec::new();
|
||||
|
||||
sub_services.push(SubServiceData {
|
||||
name: format!("{} active, ↓ {:.1} MB/s, ↑ {:.1} MB/s", active_count, download_mbps, upload_mbps),
|
||||
service_status: Status::Info,
|
||||
metrics,
|
||||
service_type: "torrent_stats".to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Create complete service data
|
||||
let service_data = ServiceData {
|
||||
name: service_name.clone(),
|
||||
@@ -878,6 +891,74 @@ impl SystemdCollector {
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
/// Get aggregate transmission torrent statistics
|
||||
/// Returns: (active_count, download_mbps, upload_mbps)
|
||||
fn get_transmission_stats(&self) -> Option<(u32, f32, f32)> {
|
||||
let rpc_url = "http://localhost:9091/transmission/rpc";
|
||||
|
||||
// Create HTTP client with timeout
|
||||
let client = reqwest::blocking::Client::builder()
|
||||
.timeout(std::time::Duration::from_secs(5))
|
||||
.build()
|
||||
.ok()?;
|
||||
|
||||
// First request to get session ID (transmission requires this for CSRF protection)
|
||||
let session_id = match client.post(rpc_url).send() {
|
||||
Ok(resp) => {
|
||||
resp.headers()
|
||||
.get("X-Transmission-Session-Id")
|
||||
.and_then(|v| v.to_str().ok())
|
||||
.map(|s| s.to_string())
|
||||
}
|
||||
Err(_) => return None,
|
||||
}?;
|
||||
|
||||
// Request torrent list with session ID
|
||||
let request_body = serde_json::json!({
|
||||
"method": "torrent-get",
|
||||
"arguments": {
|
||||
"fields": ["status", "rateDownload", "rateUpload"]
|
||||
}
|
||||
});
|
||||
|
||||
let response = client
|
||||
.post(rpc_url)
|
||||
.header("X-Transmission-Session-Id", session_id)
|
||||
.json(&request_body)
|
||||
.send()
|
||||
.ok()?;
|
||||
|
||||
let json: serde_json::Value = response.json().ok()?;
|
||||
|
||||
// Parse torrent data and calculate aggregates
|
||||
let torrent_list = json["arguments"]["torrents"].as_array()?;
|
||||
|
||||
let mut active_count = 0u32;
|
||||
let mut total_download_bps = 0.0f64;
|
||||
let mut total_upload_bps = 0.0f64;
|
||||
|
||||
for torrent in torrent_list {
|
||||
let status_code = torrent["status"].as_i64().unwrap_or(0);
|
||||
let rate_download = torrent["rateDownload"].as_f64().unwrap_or(0.0);
|
||||
let rate_upload = torrent["rateUpload"].as_f64().unwrap_or(0.0);
|
||||
|
||||
// Status codes: 0=stopped, 4=downloading, 6=seeding
|
||||
// Count as active if downloading or seeding
|
||||
if status_code == 4 || status_code == 6 {
|
||||
active_count += 1;
|
||||
}
|
||||
|
||||
total_download_bps += rate_download;
|
||||
total_upload_bps += rate_upload;
|
||||
}
|
||||
|
||||
// Convert bytes/s to MB/s
|
||||
let download_mbps = (total_download_bps / 1024.0 / 1024.0) as f32;
|
||||
let upload_mbps = (total_upload_bps / 1024.0 / 1024.0) as f32;
|
||||
|
||||
Some((active_count, download_mbps, upload_mbps))
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard"
|
||||
version = "0.1.242"
|
||||
version = "0.1.244"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -110,14 +110,6 @@ impl TuiApp {
|
||||
host_widgets.system_widget.update_from_agent_data(agent_data);
|
||||
host_widgets.services_widget.update_from_agent_data(agent_data);
|
||||
|
||||
// Update ZMQ stats
|
||||
if let Some(zmq_stats) = metric_store.get_zmq_stats(&hostname) {
|
||||
host_widgets.system_widget.update_zmq_stats(
|
||||
zmq_stats.packets_received,
|
||||
zmq_stats.last_packet_age_secs
|
||||
);
|
||||
}
|
||||
|
||||
host_widgets.last_update = Some(Instant::now());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,6 @@ pub struct SystemWidget {
|
||||
nixos_build: Option<String>,
|
||||
agent_hash: Option<String>,
|
||||
|
||||
// ZMQ communication stats
|
||||
zmq_packets_received: Option<u64>,
|
||||
zmq_last_packet_age: Option<f64>,
|
||||
|
||||
// Network interfaces
|
||||
network_interfaces: Vec<cm_dashboard_shared::NetworkInterfaceData>,
|
||||
|
||||
@@ -92,8 +88,6 @@ impl SystemWidget {
|
||||
Self {
|
||||
nixos_build: None,
|
||||
agent_hash: None,
|
||||
zmq_packets_received: None,
|
||||
zmq_last_packet_age: None,
|
||||
network_interfaces: Vec::new(),
|
||||
cpu_load_1min: None,
|
||||
cpu_load_5min: None,
|
||||
@@ -159,12 +153,6 @@ impl SystemWidget {
|
||||
pub fn _get_agent_hash(&self) -> Option<&String> {
|
||||
self.agent_hash.as_ref()
|
||||
}
|
||||
|
||||
/// Update ZMQ communication statistics
|
||||
pub fn update_zmq_stats(&mut self, packets_received: u64, last_packet_age_secs: f64) {
|
||||
self.zmq_packets_received = Some(packets_received);
|
||||
self.zmq_last_packet_age = Some(last_packet_age_secs);
|
||||
}
|
||||
}
|
||||
|
||||
use super::Widget;
|
||||
@@ -811,18 +799,6 @@ impl SystemWidget {
|
||||
Span::styled(format!("Agent: {}", agent_version_text), Typography::secondary())
|
||||
]));
|
||||
|
||||
// ZMQ communication stats
|
||||
if let (Some(packets), Some(age)) = (self.zmq_packets_received, self.zmq_last_packet_age) {
|
||||
let age_text = if age < 1.0 {
|
||||
format!("{:.0}ms ago", age * 1000.0)
|
||||
} else {
|
||||
format!("{:.1}s ago", age)
|
||||
};
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled(format!("ZMQ: {} pkts, last {}", packets, age_text), Typography::secondary())
|
||||
]));
|
||||
}
|
||||
|
||||
// CPU section
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled("CPU:", Typography::widget_title())
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard-shared"
|
||||
version = "0.1.242"
|
||||
version = "0.1.244"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
Reference in New Issue
Block a user