mirror of
https://github.com//cppla/ServerStatus
synced 2026-08-06 12:33:56 +08:00
update client linux and psutil
This commit is contained in:
+39
-20
@@ -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():
|
||||||
value = normalize_cpu_model(value)
|
cpuinfo = get_cpuinfo_values()
|
||||||
if value:
|
lscpu = get_lscpu_info()
|
||||||
return value
|
for value in (
|
||||||
except Exception:
|
cpuinfo.get('model name'),
|
||||||
pass
|
lscpu.get('model name'),
|
||||||
value = normalize_cpu_model(platform.processor())
|
cpuinfo.get('hardware'),
|
||||||
return "" if is_generic_cpu_model(value) else value
|
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():
|
def liuliang():
|
||||||
NET_IN = 0
|
NET_IN = 0
|
||||||
|
|||||||
+34
-30
@@ -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 = ""
|
value = normalize_cpu_model(value)
|
||||||
with open('/proc/cpuinfo') as f:
|
if value and not is_generic_cpu_model(value):
|
||||||
for line in f:
|
return value
|
||||||
if ':' not in line:
|
vendor = normalize_cpu_model(get_platform_cpu_vendor())
|
||||||
continue
|
if vendor:
|
||||||
key, value = line.split(':', 1)
|
return vendor
|
||||||
key = key.strip().lower()
|
return get_platform_cpu_arch()
|
||||||
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
|
|
||||||
|
|
||||||
def liuliang():
|
def liuliang():
|
||||||
NET_IN = 0
|
NET_IN = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user