diff --git a/Cargo.lock b/Cargo.lock index 7c8fc89..7dfe4e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" [[package]] name = "cm-dashboard" -version = "0.1.221" +version = "0.1.222" dependencies = [ "anyhow", "chrono", @@ -301,7 +301,7 @@ dependencies = [ [[package]] name = "cm-dashboard-agent" -version = "0.1.221" +version = "0.1.222" dependencies = [ "anyhow", "async-trait", @@ -309,6 +309,7 @@ dependencies = [ "chrono-tz", "clap", "cm-dashboard-shared", + "futures", "gethostname", "lettre", "reqwest", @@ -324,7 +325,7 @@ dependencies = [ [[package]] name = "cm-dashboard-shared" -version = "0.1.221" +version = "0.1.222" dependencies = [ "chrono", "serde", @@ -552,6 +553,21 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.31" @@ -559,6 +575,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -567,12 +584,34 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + [[package]] name = "futures-io" version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "futures-sink" version = "0.3.31" @@ -591,8 +630,11 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ + "futures-channel", "futures-core", "futures-io", + "futures-macro", + "futures-sink", "futures-task", "memchr", "pin-project-lite", diff --git a/agent/Cargo.toml b/agent/Cargo.toml index 00abef5..dbf84f8 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-agent" -version = "0.1.222" +version = "0.1.223" edition = "2021" [dependencies] @@ -20,4 +20,5 @@ gethostname = { workspace = true } chrono-tz = "0.8" toml = { workspace = true } async-trait = "0.1" -reqwest = { version = "0.11", features = ["json", "blocking"] } \ No newline at end of file +reqwest = { version = "0.11", features = ["json", "blocking"] } +futures = "0.3" \ No newline at end of file diff --git a/agent/src/collectors/disk.rs b/agent/src/collectors/disk.rs index fe190f2..bbd917f 100644 --- a/agent/src/collectors/disk.rs +++ b/agent/src/collectors/disk.rs @@ -387,9 +387,9 @@ impl DiskCollector { device.to_string() } - /// Get SMART data for drives + /// Get SMART data for drives in parallel async fn get_smart_data_for_drives(&self, physical_drives: &[PhysicalDrive], mergerfs_pools: &[MergerfsPool]) -> HashMap { - let mut smart_data = HashMap::new(); + use futures::future::join_all; // Collect all drive names let mut all_drives = std::collections::HashSet::new(); @@ -405,9 +405,24 @@ impl DiskCollector { } } - // Get SMART data for each drive - for drive_name in all_drives { - if let Ok(data) = self.get_smart_data(&drive_name).await { + // Collect SMART data for all drives in parallel + let futures: Vec<_> = all_drives + .iter() + .map(|drive_name| { + let drive = drive_name.clone(); + async move { + let result = self.get_smart_data(&drive).await; + (drive, result) + } + }) + .collect(); + + let results = join_all(futures).await; + + // Build HashMap from results + let mut smart_data = HashMap::new(); + for (drive_name, result) in results { + if let Ok(data) = result { smart_data.insert(drive_name, data); } } diff --git a/dashboard/Cargo.toml b/dashboard/Cargo.toml index ce5b310..9f924aa 100644 --- a/dashboard/Cargo.toml +++ b/dashboard/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard" -version = "0.1.222" +version = "0.1.223" edition = "2021" [dependencies] diff --git a/shared/Cargo.toml b/shared/Cargo.toml index de4d72e..18338d6 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-shared" -version = "0.1.222" +version = "0.1.223" edition = "2021" [dependencies]