A Python Module Command Output Request (on Linux)

Viewed 64

I need to know how following Python psutil module commands outputs are for a multiple CPU (CPU sockets) computer:

import psutil
print(psutil.cpu_percent(interval=0.3, percpu=True))
print(psutil.sensors_temperatures(fahrenheit=False))
print(psutil.sensors_fans())

Note: Python package psutil should be installed. Note2: Last two commands are not available on Windows. They should be run on Linux.

1 Answers

From psutil documentaion

  • cpu_percent : 1-or more CPU returns same : 1-d list of cpu_percent value

    • percpu=False returns int such as 2.3

    • percpu=True returns list[int] such as

      • for 1CPU-4cores-8threads [23.8, 5.0, 10.0, 5.0, 15.0, 5.0, 15.0, 23.8]
      • for 4CPU-4x4cores-4x8threads [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]
  • sensor_temparatures returns dict[str,list[namedtuple] such as

    {'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 returns dict[str,list[namedtuple] such as

    {'asus': [sfan(label='cpu_fan', current=3200)]}
    
Related