feat: CPU页加温度/风扇显示,过滤0转速空接口 v1.3.4
This commit is contained in:
1 parent
497510c32b
commit
555d8839e7
2 files changed
+65
-3
No files matched your search
@@ -635,6 +635,66 @@ def api_sys_optimize():
|
||||
"freed": max(0, after_mem - before_mem),
|
||||
"available": after_mem})
|
||||
|
||||
@app.route("/api/sensors")
|
||||
def api_sensors():
|
||||
"""CPU温度/风扇转速: 优先读宿主 /host/sys hwmon,读不到返回空+提示"""
|
||||
temps, fans = [], []
|
||||
HWMON_LABEL = {"k10temp": "CPU", "zenpower": "CPU", "coretemp": "CPU",
|
||||
"amdgpu": "核显", "radeon": "核显", "nct6775": "主板",
|
||||
"nct6683": "主板", "nct6686": "主板", "nct6687": "主板",
|
||||
"drivetemp": "硬盘", "nvme": "硬盘", "iwlwifi": "无线",
|
||||
"mt7921_phy0": "无线", "r8169_0_2a00:00": "网卡", "r8169": "网卡"}
|
||||
try:
|
||||
for base in ("/host/sys/class/hwmon", "/sys/class/hwmon"):
|
||||
if not os.path.isdir(base):
|
||||
continue
|
||||
for h in sorted(os.listdir(base)):
|
||||
d = os.path.join(base, h)
|
||||
if not os.path.isdir(d):
|
||||
continue
|
||||
try:
|
||||
with open(os.path.join(d, "name")) as f:
|
||||
chip = f.read().strip()
|
||||
except Exception:
|
||||
chip = h
|
||||
label = HWMON_LABEL.get(chip, chip)
|
||||
for i in (1, 2, 3, 4, 5):
|
||||
tf = os.path.join(d, "temp%d_input" % i)
|
||||
if not os.path.isfile(tf):
|
||||
continue
|
||||
try:
|
||||
with open(tf) as f:
|
||||
v = float(f.read().strip()) / 1000.0
|
||||
if -40 < v < 130:
|
||||
lf = os.path.join(d, "temp%d_label" % i)
|
||||
nm = label
|
||||
try:
|
||||
if os.path.isfile(lf):
|
||||
with open(lf) as f:
|
||||
nm = "%s(%s)" % (label, f.read().strip())
|
||||
except Exception:
|
||||
pass
|
||||
temps.append({"name": nm, "value": round(v, 1)})
|
||||
except Exception:
|
||||
pass
|
||||
for i in (1, 2, 3, 4, 5, 6):
|
||||
ff = os.path.join(d, "fan%d_input" % i)
|
||||
if not os.path.isfile(ff):
|
||||
continue
|
||||
try:
|
||||
with open(ff) as f:
|
||||
v = int(float(f.read().strip()))
|
||||
if v > 0:
|
||||
fans.append({"name": "%s 风扇%d" % (label, i), "value": v})
|
||||
except Exception:
|
||||
pass
|
||||
if temps or fans:
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
note = "" if (temps or fans) else "宿主未暴露温度/转速传感器(容器读不到属正常,见 README 说明)"
|
||||
return jsonify({"temps": temps, "fans": fans, "note": note})
|
||||
|
||||
@app.route("/api/mem/drop", methods=["POST"])
|
||||
def api_mem_drop():
|
||||
import subprocess
|
||||
|
||||
Reference in new issue
Block a user