Since RedHat/Ubuntu/Debian’s /proc/cpuinfo
has a separate entry for each CPU core, you can use this command to count them:cat /proc/cpuinfo | grep processor | wc -l
Or do it with the following Python script:
—-
!/usr/bin/env python3
import os
import psutil
l1, l2, l3 = psutil.getloadavg()
CPU_use = (l3/os.cpu_count()) * 100
print(“CPU_use as computed by psutil.getloadavg: ” + str(CPU_use))
print(“cpu percent reported by psutil: ” + str(psutil.cpu_percent()))
print(“cpu count reported by psutil: ” + str(psutil.cpu_count()))
print(“cpu count reported by psutil with logical set to False: ” + str(psutil.cpu_count(logical=False)))
current_process = psutil.Process()
print(“cpu percent reported by psutil.Process ” + str(current_process.cpu_percent()))
—-