我需要知道以下Pythonpsutil
模块命令输出如何用于多CPU(CPU插槽(计算机:
import psutil
print(psutil.cpu_percent(interval=0.3, percpu=True))
print(psutil.sensors_temperatures(fahrenheit=False))
print(psutil.sensors_fans())
注意:应该安装Python包psutil
。注意2:最后两个命令在Windows上不可用。它们应该在Linux上运行。
来自psutil documentaion
-
cpu_percent
:1个或多个CPU返回相同的cpu_percent
值的1-d列表-
percpu=False
返回int
,如2.3
-
percpu=True
返回等list[int]
- 对于1CPU-4核-8线程
[23.8, 5.0, 10.0, 5.0, 15.0, 5.0, 15.0, 23.8]
- 用于4CPU-4x4芯-4x8螺纹
[23.8, 5.0, 10.0, 5.0, 15.0, 5.0, 15.0, 23.8,23.8, 5.0, 10.0, 5.0, 15.0, 5.0, 15.0, 23.8,23.8, 5.0, 10.0, 5.0, 15.0, 5.0, 15.0, 23.8,23.8, 5.0, 10.0, 5.0, 15.0, 5.0, 15.0, 23.8]
- 对于1CPU-4核-8线程
-
-
sensor_temparatures
返回等dict[str,list[namedtuple]
{'acpitz' : [shwtemp(label='', current=47.0, high=103.0, critical=103.0)], 'asus' : [shwtemp(label='', current=47.0, high=None, critical=None)], 'coretemp': [shwtemp(label='Physical id 0', current=52.0, high=100.0, critical=100.0), shwtemp(label='Core 0', current=45.0, high=100.0, critical=100.0), shwtemp(label='Core 1', current=52.0, high=100.0, critical=100.0), shwtemp(label='Core 2', current=45.0, high=100.0, critical=100.0), shwtemp(label='Core 3', current=47.0, high=100.0, critical=100.0)]}
-
sensors_fans
返回dict[str,list[namedtuple]
,如{'asus': [sfan(label='cpu_fan', current=3200)]}