feat(monitor): CPU 卡显示型号(psutil 只给核数,型号走注册表 ProcessorNameString / Linux /proc/cpuinfo),加在卡底与 GPU 同名同位置

This commit is contained in:
cbb
2026-10-18 16:15:44 +08:00
parent c143b56232
commit 21ad209747
2 changed files with 20 additions and 3 deletions
+1 -1
View File
@@ -558,7 +558,7 @@ function renderStatus(s) {
<div class="c"><div><b>${tot}%</b><span>CPU</span></div></div></div>
<div class="gpurows">${gr('占用', `${tot}% · ${CP.n} 核`, tot, col)}
<div class="cores">${bars}</div></div></div>
<div class="gname">每核占用(深色=忙)</div>`;
<div class="gname">${CP.model || 'CPU'} · 每核占用(深色=忙)</div>`;
})() : '';
$('gpu').innerHTML = (gpuBlk + (gpuBlk && cpuBlk ? hr : '') + cpuBlk) || empty('未检测到 nvidia-smi / psutil');
+19 -2
View File
@@ -17,7 +17,7 @@
N-11 Windows 子进程用 CREATE_NO_WINDOW 自带隐藏控制台:关掉控制台黑窗口训练照跑,重开控制台可接着看、可停止;
N-9 生成阶段的行数按文件增量统计(只读新增字节),其他阶段不扫 shard;
N-12 停止后的状态改写走 ml.pstate(单一写者、原子替换);N-14 阶段名/估时/权重由 ml.pstate.STAGES 下发。"""
import argparse, glob, json, os, re, shutil, signal, subprocess, sys, threading, time, webbrowser
import argparse, glob, json, os, platform, re, shutil, signal, subprocess, sys, threading, time, webbrowser
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from ml import pstate
from http.server import ThreadingHTTPServer, BaseHTTPRequestHandler
@@ -71,6 +71,22 @@ def read_log(name, offset):
_CPU = {'v': {}}
def cpu_name():
"""CPU 型号:psutil 只有核数,型号得自己读——Windows 在注册表,Linux 在 /proc/cpuinfo。"""
try:
if os.name == 'nt':
import winreg
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r'HARDWARE\DESCRIPTION\System\CentralProcessor\0') as k:
return re.sub(r'\s+', ' ', winreg.QueryValueEx(k, 'ProcessorNameString')[0]).strip()
with open('/proc/cpuinfo') as f:
for ln in f:
if ln.startswith('model name'):
return ln.split(':', 1)[1].strip()
except Exception:
pass
return platform.processor().strip()
class CpuSampler(threading.Thread):
"""后台每秒阻塞采样一次 CPU。cpu_percent 是"距上次调用"的差值:放在请求里算,窗口取决于两次
HTTP 请求的间隔(网页 1 秒轮询 + 手动 curl 会把它压成几毫秒,读数恒为 0)——所以单独一个线程按固定
@@ -80,10 +96,11 @@ class CpuSampler(threading.Thread):
def run(self):
try:
import psutil
name = cpu_name() # 型号只读一次,别每秒翻注册表
psutil.cpu_percent(interval=None, percpu=True) # 打桩:第一次恒为 0,丢掉
while True:
per = psutil.cpu_percent(interval=1.0, percpu=True)
_CPU['v'] = {'total': round(sum(per) / max(1, len(per)), 1), 'per': [round(x) for x in per], 'n': len(per)}
_CPU['v'] = {'total': round(sum(per) / max(1, len(per)), 1), 'per': [round(x) for x in per], 'n': len(per), 'model': name}
except Exception:
_CPU['v'] = {}