From 5bb7d6cf57f63e910918370136d691307f121099 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Mon, 1 Dec 2025 19:35:03 +0100 Subject: [PATCH] Fix CPU model extraction for newer Intel generations - Handle 12th/13th Gen Intel format (e.g., "12th Gen Intel(R) Core(TM) i7-12700K") - Extract full model including suffix (i7-12700K instead of truncated name) - Simplify pattern matching logic - Reduce fallback truncation to 15 chars --- Cargo.lock | 6 +++--- agent/Cargo.toml | 2 +- agent/src/collectors/cpu.rs | 34 ++++++++++++---------------------- dashboard/Cargo.toml | 2 +- shared/Cargo.toml | 2 +- 5 files changed, 18 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 911a96f..b527611 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" [[package]] name = "cm-dashboard" -version = "0.1.240" +version = "0.1.241" dependencies = [ "anyhow", "chrono", @@ -301,7 +301,7 @@ dependencies = [ [[package]] name = "cm-dashboard-agent" -version = "0.1.240" +version = "0.1.241" dependencies = [ "anyhow", "async-trait", @@ -325,7 +325,7 @@ dependencies = [ [[package]] name = "cm-dashboard-shared" -version = "0.1.240" +version = "0.1.241" dependencies = [ "chrono", "serde", diff --git a/agent/Cargo.toml b/agent/Cargo.toml index 29be315..5af1b2f 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-agent" -version = "0.1.241" +version = "0.1.242" edition = "2021" [dependencies] diff --git a/agent/src/collectors/cpu.rs b/agent/src/collectors/cpu.rs index 60e4172..a1d1ae6 100644 --- a/agent/src/collectors/cpu.rs +++ b/agent/src/collectors/cpu.rs @@ -152,27 +152,17 @@ impl CpuCollector { /// Extract CPU model number from full model name /// Examples: /// - "Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz" -> "i7-9700" + /// - "12th Gen Intel(R) Core(TM) i7-12700K" -> "i7-12700K" /// - "AMD Ryzen 9 5950X 16-Core Processor" -> "Ryzen 9 5950X" fn extract_cpu_model(full_name: &str) -> String { - // Look for common Intel patterns: i3, i5, i7, i9, Xeon - if let Some(pos) = full_name.find("i3-") { - if let Some(end) = full_name[pos..].find(' ') { - return full_name[pos..pos + end].to_string(); - } - } - if let Some(pos) = full_name.find("i5-") { - if let Some(end) = full_name[pos..].find(' ') { - return full_name[pos..pos + end].to_string(); - } - } - if let Some(pos) = full_name.find("i7-") { - if let Some(end) = full_name[pos..].find(' ') { - return full_name[pos..pos + end].to_string(); - } - } - if let Some(pos) = full_name.find("i9-") { - if let Some(end) = full_name[pos..].find(' ') { - return full_name[pos..pos + end].to_string(); + // Look for Intel Core patterns (both old and new gen): i3, i5, i7, i9 + // Match pattern like "i7-12700K" or "i7-9700" + for prefix in &["i3-", "i5-", "i7-", "i9-"] { + if let Some(pos) = full_name.find(prefix) { + // Find end of model number (until space or end of string) + let after_prefix = &full_name[pos..]; + let end = after_prefix.find(' ').unwrap_or(after_prefix.len()); + return after_prefix[..end].to_string(); } } @@ -186,9 +176,9 @@ impl CpuCollector { } } - // Fallback: return first 20 characters or full name if shorter - if full_name.len() > 20 { - full_name[..20].to_string() + // Fallback: return first 15 characters or full name if shorter + if full_name.len() > 15 { + full_name[..15].to_string() } else { full_name.to_string() } diff --git a/dashboard/Cargo.toml b/dashboard/Cargo.toml index 7a7e2c0..bdb62b9 100644 --- a/dashboard/Cargo.toml +++ b/dashboard/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard" -version = "0.1.241" +version = "0.1.242" edition = "2021" [dependencies] diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 5fb7bb8..d2aa76b 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-shared" -version = "0.1.241" +version = "0.1.242" edition = "2021" [dependencies]