fix: lookup temperature for parent disk, not partition
This commit is contained in:
parent
bd0d15a1ae
commit
bae2ecb79a
@ -343,7 +343,10 @@ pub async fn collect_disks(state: &AppState) -> Vec<DiskInfo> {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -351,8 +354,11 @@ pub async fn collect_disks(state: &AppState) -> Vec<DiskInfo> {
|
|||||||
// 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
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -386,12 +392,17 @@ 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,
|
||||||
total: d.total_space(),
|
total: d.total_space(),
|
||||||
@ -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