Dedicated hardware poller + read-only consumers #4

Open
adamksmith wants to merge 13 commits from feat/dedicated-poller into main
Showing only changes of commit 514502e045 - Show all commits

View File

@@ -45,6 +45,10 @@ def _parse_ipmi(text: str) -> list[dict]:
if len(parts) < 5:
continue
name, _sid, status, entity, reading = parts[:5]
# Skip relative/derived sensors (e.g. "P1 Therm Margin") — they read in
# "degrees C" but are a distance-to-throttle, not an absolute temp.
if "margin" in name.lower():
continue
m = re.search(r"(-?\d+(?:\.\d+)?)\s*degrees?\s*C", reading, re.IGNORECASE)
if not m: # "no reading", "disabled", "ns", etc.
continue
@@ -74,22 +78,28 @@ def read_coretemp() -> list[dict]:
continue
except OSError:
continue
packages: list[dict] = []
cores: list[int] = []
for label_f in sorted(hw.glob("temp*_label")):
try:
label = label_f.read_text().strip()
except OSError:
continue
if not label.lower().startswith("package id"):
continue
input_f = label_f.with_name(label_f.name.replace("_label", "_input"))
try:
milli = int(input_f.read_text().strip())
temp = round(int(input_f.read_text().strip()) / 1000)
except (OSError, ValueError):
continue
low = label.lower()
if low.startswith("package id"):
pkg = label.split("id")[-1].strip()
cpus.append({
"name": f"CPU {pkg}",
"temperature_c": round(milli / 1000),
"kind": "cpu",
})
packages.append({"name": f"CPU {pkg}", "temperature_c": temp, "kind": "cpu"})
elif low.startswith("core"):
cores.append(temp)
# Prefer the per-package sensor; older CPUs (no package sensor) fall back
# to the hottest core as the CPU temp.
if packages:
cpus.extend(packages)
elif cores:
cpus.append({"name": "CPU", "temperature_c": max(cores), "kind": "cpu"})
return cpus