update client linux and psutil

This commit is contained in:
cppla
2026-07-09 18:01:57 +08:00
parent 2b799a524f
commit 3b0705edc1
2 changed files with 73 additions and 50 deletions
+37 -18
View File
@@ -150,9 +150,25 @@ def is_generic_cpu_model(value):
v = normalize_cpu_model(value).lower().replace('-', '').replace('_', '').replace(' ', '') v = normalize_cpu_model(value).lower().replace('-', '').replace('_', '').replace(' ', '')
return v in ('', 'unknown', 'x8664', 'amd64', 'i386', 'i686', 'aarch64', 'arm64') or v.startswith('armv') return v in ('', 'unknown', 'x8664', 'amd64', 'i386', 'i686', 'aarch64', 'arm64') or v.startswith('armv')
def get_cpu_model(): def get_lscpu_info():
result = {}
try:
output = subprocess.check_output(['lscpu'], stderr=subprocess.DEVNULL, timeout=2).decode(errors='ignore')
for line in output.splitlines():
if ':' not in line:
continue
key, value = line.split(':', 1)
key = key.strip().lower()
value = normalize_cpu_model(value)
if value and key not in result:
result[key] = value
except Exception:
pass
return result
def get_cpuinfo_values():
result = {}
try: try:
fallback = ""
with open('/proc/cpuinfo') as f: with open('/proc/cpuinfo') as f:
for line in f: for line in f:
if ':' not in line: if ':' not in line:
@@ -160,26 +176,29 @@ def get_cpu_model():
key, value = line.split(':', 1) key, value = line.split(':', 1)
key = key.strip().lower() key = key.strip().lower()
value = normalize_cpu_model(value) value = normalize_cpu_model(value)
if not value: if value and key not in result:
continue result[key] = value
if key == 'model name':
return value
if key in ('hardware', 'processor') and not value.isdigit() and not fallback:
fallback = value
if fallback:
return fallback
except Exception: except Exception:
pass pass
for cmd in ('sysctl -n machdep.cpu.brand_string', 'sysctl -n hw.model'): return result
try:
value = subprocess.check_output(cmd, shell=True, stderr=subprocess.DEVNULL, timeout=2).decode().strip() def get_cpu_model():
cpuinfo = get_cpuinfo_values()
lscpu = get_lscpu_info()
for value in (
cpuinfo.get('model name'),
lscpu.get('model name'),
cpuinfo.get('hardware'),
cpuinfo.get('processor'),
platform.processor(),
):
value = normalize_cpu_model(value) value = normalize_cpu_model(value)
if value: if value and not value.isdigit() and not is_generic_cpu_model(value):
return value return value
except Exception: vendor = normalize_cpu_model(lscpu.get('vendor id') or cpuinfo.get('vendor_id'))
pass if vendor:
value = normalize_cpu_model(platform.processor()) return vendor
return "" if is_generic_cpu_model(value) else value return normalize_cpu_model(lscpu.get('architecture') or platform.machine() or platform.processor())
def liuliang(): def liuliang():
NET_IN = 0 NET_IN = 0
+32 -28
View File
@@ -28,7 +28,6 @@ import sys
import json import json
import errno import errno
import psutil import psutil
import subprocess
import threading import threading
import platform import platform
from queue import Queue from queue import Queue
@@ -103,36 +102,41 @@ def is_generic_cpu_model(value):
v = normalize_cpu_model(value).lower().replace('-', '').replace('_', '').replace(' ', '') v = normalize_cpu_model(value).lower().replace('-', '').replace('_', '').replace(' ', '')
return v in ('', 'unknown', 'x8664', 'amd64', 'i386', 'i686', 'aarch64', 'arm64') or v.startswith('armv') return v in ('', 'unknown', 'x8664', 'amd64', 'i386', 'i686', 'aarch64', 'arm64') or v.startswith('armv')
def get_platform_cpu_vendor():
values = [
platform.processor(),
getattr(platform.uname(), 'processor', ''),
platform.machine(),
getattr(platform.uname(), 'machine', ''),
platform.platform(),
]
text = " ".join(normalize_cpu_model(v).lower() for v in values)
if 'genuineintel' in text:
return 'GenuineIntel'
if 'authenticamd' in text:
return 'AuthenticAMD'
if 'intel' in text:
return 'Intel'
if 'amd' in text:
return 'AMD'
if sys.platform.startswith('darwin') and platform.machine().lower() in ('arm64', 'aarch64'):
return 'Apple'
if any(token in text for token in ('aarch64', 'arm64', 'armv7', 'armv8', ' arm ')):
return 'ARM'
return ''
def get_platform_cpu_arch():
return normalize_cpu_model(platform.machine() or platform.processor() or platform.architecture()[0])
def get_cpu_model(): def get_cpu_model():
try: for value in (platform.processor(), getattr(platform.uname(), 'processor', '')):
fallback = ""
with open('/proc/cpuinfo') as f:
for line in f:
if ':' not in line:
continue
key, value = line.split(':', 1)
key = key.strip().lower()
value = normalize_cpu_model(value) value = normalize_cpu_model(value)
if not value: if value and not is_generic_cpu_model(value):
continue
if key == 'model name':
return value return value
if key in ('hardware', 'processor') and not value.isdigit() and not fallback: vendor = normalize_cpu_model(get_platform_cpu_vendor())
fallback = value if vendor:
if fallback: return vendor
return fallback return get_platform_cpu_arch()
except Exception:
pass
for cmd in ('sysctl -n machdep.cpu.brand_string', 'sysctl -n hw.model'):
try:
value = subprocess.check_output(cmd, shell=True, stderr=subprocess.DEVNULL, timeout=2).decode().strip()
value = normalize_cpu_model(value)
if value:
return value
except Exception:
pass
value = normalize_cpu_model(platform.processor())
return "" if is_generic_cpu_model(value) else value
def liuliang(): def liuliang():
NET_IN = 0 NET_IN = 0