#!/usr/bin/python2
import sensors
import subprocess
from glob import glob
import re
sensorsToShow = {'Physical id 0': ["C", 70,100],
'temp1' : ["C", 70,100],
'Left side ' : ["RPM", 3000,5000]}
cpuGovernors = { "powersave" : 's',
"performance": 'p',
"ondemand": 'o'}
out = ""
cpuGovernor = ""
sensors.init()
try:
for chip in sensors.iter_detected_chips():
for feature in chip:
if feature.label in sensorsToShow:
color = ("#00B000" if feature.get_value() < sensorsToShow[feature.label][1]
else ("yellow" if feature.get_value() < sensorsToShow[feature.label][2]
else "red"))
out += '%.f%s ' % (color, feature.get_value(), sensorsToShow[feature.label][0])
CPUFreq = 0
for line in open("/proc/cpuinfo"):
if "cpu MHz" in line:
speed = float(line.replace("cpu MHz : ", "").replace("\n", ""))
CPUFreq = max(speed, CPUFreq)
#print CPUFreq
out += '%.2fGHz' % (CPUFreq/1000)
out += " "
for i in glob("/sys/devices/system/cpu/cpu[0-9]/cpufreq/scaling_governor"):
out += cpuGovernors[open(i).read().replace("\n", "")]
print "" + out + ""
finally:
sensors.cleanup()