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
+39 -20
View File
@@ -150,9 +150,25 @@ def is_generic_cpu_model(value):
v = normalize_cpu_model(value).lower().replace('-', '').replace('_', '').replace(' ', '')
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:
fallback = ""
with open('/proc/cpuinfo') as f:
for line in f:
if ':' not in line:
@@ -160,26 +176,29 @@ def get_cpu_model():
key, value = line.split(':', 1)
key = key.strip().lower()
value = normalize_cpu_model(value)
if not value:
continue
if key == 'model name':
return value
if key in ('hardware', 'processor') and not value.isdigit() and not fallback:
fallback = value
if fallback:
return fallback
if value and key not in result:
result[key] = value
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
return result
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)
if value and not value.isdigit() and not is_generic_cpu_model(value):
return value
vendor = normalize_cpu_model(lscpu.get('vendor id') or cpuinfo.get('vendor_id'))
if vendor:
return vendor
return normalize_cpu_model(lscpu.get('architecture') or platform.machine() or platform.processor())
def liuliang():
NET_IN = 0
+34 -30
View File
@@ -28,7 +28,6 @@ import sys
import json
import errno
import psutil
import subprocess
import threading
import platform
from queue import Queue
@@ -103,36 +102,41 @@ def is_generic_cpu_model(value):
v = normalize_cpu_model(value).lower().replace('-', '').replace('_', '').replace(' ', '')
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():
try:
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)
if not value:
continue
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:
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
for value in (platform.processor(), getattr(platform.uname(), 'processor', '')):
value = normalize_cpu_model(value)
if value and not is_generic_cpu_model(value):
return value
vendor = normalize_cpu_model(get_platform_cpu_vendor())
if vendor:
return vendor
return get_platform_cpu_arch()
def liuliang():
NET_IN = 0