Add cpufantemp.py, hddtemp.py, sysFanTemp.py
This commit is contained in:
55
cpufantemp.py
Executable file
55
cpufantemp.py
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import subprocess
|
||||
import json
|
||||
|
||||
|
||||
def runCmd(cmdString):
|
||||
result = subprocess.run(cmdString, stdout=subprocess.PIPE, shell=True).stdout.decode('utf-8')
|
||||
return result
|
||||
|
||||
|
||||
def getCpuTempAndFanSpeed():
|
||||
cmd = "sensors"
|
||||
ret = runCmd(cmd).split("\n")
|
||||
|
||||
fanTempDict = {
|
||||
"cpu": {},
|
||||
"fan": {}
|
||||
}
|
||||
for line in ret:
|
||||
if line.startswith("Core"):
|
||||
line = line.split(":")
|
||||
if len(line) > 1:
|
||||
cpuIndex, tempString = line[0], line[1]
|
||||
tempString = tempString.split(" ")
|
||||
tempString = [x for x in tempString if x != ""]
|
||||
if len(tempString) > 1:
|
||||
temp = float(tempString[0].replace("+", "").replace("°C", ""))
|
||||
else:
|
||||
temp = -999.9
|
||||
fanTempDict["cpu"][cpuIndex] = temp
|
||||
|
||||
elif line.startswith("fan"):
|
||||
line = line.split(":")
|
||||
if len(line) > 1:
|
||||
fanId, fanNumber = line[0], line[1]
|
||||
fanNumber = fanNumber.split(" ")
|
||||
fanNumber = [x for x in fanNumber if x != ""]
|
||||
if len(fanNumber) > 1:
|
||||
fanSpeed = int(fanNumber[0])
|
||||
else:
|
||||
fanSpeed = 0
|
||||
|
||||
if fanSpeed > 0:
|
||||
fanTempDict["fan"][fanId] = fanSpeed
|
||||
return fanTempDict
|
||||
|
||||
|
||||
def main():
|
||||
fanTempDict = getCpuTempAndFanSpeed()
|
||||
print(f"{json.dumps(fanTempDict, indent=4)}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user