mirror of
https://github.com/KevinMidboe/Node-Com-Handler.git
synced 2026-01-30 13:16:40 +00:00
Major cleanup, added all old files (python2) to 'old_v0.1' folder
This commit is contained in:
35
status/cpuTemp.py
Executable file
35
status/cpuTemp.py
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import psutil
|
||||
|
||||
def getCpuTemp():
|
||||
# Check if sensors_temperatures exists
|
||||
try:
|
||||
# Define cpu as function of sensors_temperatures
|
||||
cpu = psutil.sensors_temperatures()
|
||||
except AttributeError:
|
||||
error = "'sensors_temperatures' is not supported in this verison of psutil or your OS."
|
||||
print(error)
|
||||
return None
|
||||
|
||||
# Array for temps for each core.
|
||||
curCpuTemps = []
|
||||
# Itterate through all cores of coretemps
|
||||
for temp in cpu['coretemp']:
|
||||
curCpuTemps.append(temp[1]) # Append to list
|
||||
print(temp[0]+': '+str(temp[1])) # Print output
|
||||
|
||||
# Check if len of curCpuTemps is something so not to
|
||||
# calculate on a empty list
|
||||
if len(curCpuTemps) > 0:
|
||||
# Compute avg of curCpuTemps
|
||||
avgCpuTemps = sum(curCpuTemps)/len(curCpuTemps)
|
||||
return avgCpuTemps
|
||||
print("Avg: " + str(avgCpuTemps))
|
||||
else:
|
||||
print("Couldn't get cpu temp. (division by zero)")
|
||||
return None
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(getCpuTemp())
|
||||
Reference in New Issue
Block a user