summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorDiana <5275194+DianaNites@users.noreply.github.com>2022-11-01 21:43:58 -0700
committerGitHub <noreply@github.com>2022-11-02 00:43:58 -0400
commitb8c73d3a0bd4babbbe4f6ea640bea68abbd5f1b9 (patch)
treec297da1c0048d293f13ce31b3663285c9eeff56c /src/app
parent064d740c6dc625ff9a84e28441e1605a921086a9 (diff)
More human friendly temperature sensor naming (#807)
* More human friendly temperature sensor names This makes the names more human friendly, and possible to distinguish from each other * Keep hwmon sensor name for GPUs * Keep hwmon sensor name for non-GPUs too * fix device path
Diffstat (limited to 'src/app')
-rw-r--r--src/app/data_harvester/temperature/linux.rs52
1 files changed, 51 insertions, 1 deletions
diff --git a/src/app/data_harvester/temperature/linux.rs b/src/app/data_harvester/temperature/linux.rs
index a6b283b8..5fec1059 100644
--- a/src/app/data_harvester/temperature/linux.rs
+++ b/src/app/data_harvester/temperature/linux.rs
@@ -100,7 +100,57 @@ fn get_from_hwmon(
let temp_label = file_path.join(name.replace("input", "label"));
let temp_label = fs::read_to_string(temp_label).ok();
- let name = match (&hwmon_name, &temp_label) {
+ // Do some messing around to get a more sensible name for sensors
+ //
+ // - For GPUs, this will use the kernel device name, ex `card0`
+ // - For nvme drives, this will also use the kernel name, ex `nvme0`.
+ // This is found differently than for GPUs
+ // - For whatever acpitz is, on my machine this is now `thermal_zone0`.
+ // - For k10temp, this will still be k10temp, but it has to be handled special.
+ let human_hwmon_name = {
+ let device = file_path.join("device");
+ // This will exist for GPUs but not others, this is how
+ // we find their kernel name
+ let drm = device.join("drm");
+ if drm.exists() {
+ // This should never actually be empty
+ let mut gpu = None;
+ for card in drm.read_dir()? {
+ let card = card?;
+ let name = card.file_name().to_str().unwrap_or_default().to_owned();
+ if name.starts_with("card") {
+ if let Some(hwmon_name) = hwmon_name.as_ref() {
+ gpu = Some(format!("{} ({})", name, hwmon_name.trim()));
+ } else {
+ gpu = Some(name)
+ }
+ break;
+ }
+ }
+ gpu
+ } else {
+ // This little mess is to account for stuff like k10temp
+ // This is needed because the `device` symlink
+ // points to `nvme*` for nvme drives, but to PCI buses for anything else
+ // If the first character is alphabetic,
+ // its an actual name like k10temp or nvme0, not a PCI bus
+ let link = fs::read_link(device)?
+ .file_name()
+ .map(|f| f.to_str().unwrap_or_default().to_owned())
+ .unwrap();
+ if link.as_bytes()[0].is_ascii_alphabetic() {
+ if let Some(hwmon_name) = hwmon_name.as_ref() {
+ Some(format!("{} ({})", link, hwmon_name.trim()))
+ } else {
+ Some(link)
+ }
+ } else {
+ hwmon_name.clone()
+ }
+ }
+ };
+
+ let name = match (&human_hwmon_name, &temp_label) {
(Some(name), Some(label)) => format!("{}: {}", name.trim(), label.trim()),
(None, Some(label)) => label.to_string(),
(Some(name), None) => name.to_string(),