fix: lookup temperature for parent disk, not partition
This commit is contained in:
parent
bd0d15a1ae
commit
bae2ecb79a
@ -338,21 +338,27 @@ pub async fn collect_disks(state: &AppState) -> Vec<DiskInfo> {
|
|||||||
let mut components = state.components.lock().await;
|
let mut components = state.components.lock().await;
|
||||||
components.refresh(false);
|
components.refresh(false);
|
||||||
let mut composite_temps = Vec::new();
|
let mut composite_temps = Vec::new();
|
||||||
|
|
||||||
for c in components.iter() {
|
for c in components.iter() {
|
||||||
let label = c.label().to_ascii_lowercase();
|
let label = c.label().to_ascii_lowercase();
|
||||||
|
|
||||||
// Collect all "Composite" temperatures (these are NVMe drives)
|
// Collect all "Composite" temperatures (these are NVMe drives)
|
||||||
if label == "composite" && let Some(temp) = c.temperature() {
|
if label == "composite"
|
||||||
|
&& let Some(temp) = c.temperature()
|
||||||
|
{
|
||||||
|
tracing::debug!("Found Composite temp: {}°C", temp);
|
||||||
composite_temps.push(temp);
|
composite_temps.push(temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store composite temps indexed by their order (nvme0n1, nvme1n1, nvme2n1, etc.)
|
// Store composite temps indexed by their order (nvme0n1, nvme1n1, nvme2n1, etc.)
|
||||||
let mut temps = std::collections::HashMap::new();
|
let mut temps = std::collections::HashMap::new();
|
||||||
for (idx, temp) in composite_temps.iter().enumerate() {
|
for (idx, temp) in composite_temps.iter().enumerate() {
|
||||||
temps.insert(format!("nvme{}n1", idx), *temp);
|
let key = format!("nvme{}n1", idx);
|
||||||
|
tracing::debug!("Mapping {} -> {}°C", key, temp);
|
||||||
|
temps.insert(key, *temp);
|
||||||
}
|
}
|
||||||
|
tracing::debug!("Final disk_temps map: {:?}", temps);
|
||||||
temps
|
temps
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -363,12 +369,12 @@ pub async fn collect_disks(state: &AppState) -> Vec<DiskInfo> {
|
|||||||
.iter()
|
.iter()
|
||||||
.filter_map(|d| {
|
.filter_map(|d| {
|
||||||
let name = d.name().to_string_lossy().into_owned();
|
let name = d.name().to_string_lossy().into_owned();
|
||||||
|
|
||||||
// Skip if we've already seen this partition/device
|
// Skip if we've already seen this partition/device
|
||||||
if !seen_partitions.insert(name.clone()) {
|
if !seen_partitions.insert(name.clone()) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine if this is a partition
|
// Determine if this is a partition
|
||||||
let is_partition = name.contains("p1")
|
let is_partition = name.contains("p1")
|
||||||
|| name.contains("p2")
|
|| name.contains("p2")
|
||||||
@ -386,11 +392,16 @@ pub async fn collect_disks(state: &AppState) -> Vec<DiskInfo> {
|
|||||||
// Try to find temperature for this disk
|
// Try to find temperature for this disk
|
||||||
let temperature = disk_temps.iter().find_map(|(key, &temp)| {
|
let temperature = disk_temps.iter().find_map(|(key, &temp)| {
|
||||||
if name.starts_with(key) {
|
if name.starts_with(key) {
|
||||||
|
tracing::debug!("Matched {} with key {} -> {}°C", name, key, temp);
|
||||||
Some(temp)
|
Some(temp)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if temperature.is_none() && !name.starts_with("loop") && !name.starts_with("ram") {
|
||||||
|
tracing::debug!("No temperature found for disk: {}", name);
|
||||||
|
}
|
||||||
|
|
||||||
Some(DiskInfo {
|
Some(DiskInfo {
|
||||||
name,
|
name,
|
||||||
@ -428,17 +439,26 @@ pub async fn collect_disks(state: &AppState) -> Vec<DiskInfo> {
|
|||||||
partition.name.trim_end_matches(char::is_numeric)
|
partition.name.trim_end_matches(char::is_numeric)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Look up temperature for the PARENT disk, not the partition
|
||||||
|
let parent_temp = disk_temps.iter().find_map(|(key, &temp)| {
|
||||||
|
if parent_name.starts_with(key) {
|
||||||
|
Some(temp)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Aggregate partition stats into parent
|
// Aggregate partition stats into parent
|
||||||
let entry = parent_disks.entry(parent_name.to_string()).or_insert((
|
let entry = parent_disks.entry(parent_name.to_string()).or_insert((
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
partition.temperature,
|
parent_temp,
|
||||||
));
|
));
|
||||||
entry.0 += partition.total;
|
entry.0 += partition.total;
|
||||||
entry.1 += partition.available;
|
entry.1 += partition.available;
|
||||||
// Keep temperature if any partition has it
|
// Keep temperature if any partition has it (or if we just found one)
|
||||||
if entry.2.is_none() {
|
if entry.2.is_none() {
|
||||||
entry.2 = partition.temperature;
|
entry.2 = parent_temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user