Created
April 26, 2013 12:09
-
-
Save fsodogandji/5466988 to your computer and use it in GitHub Desktop.
Monitor the CPU Temperature with sched module and linux command sensors from lm_sensors software
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sched, time | |
from time import strftime, localtime | |
import sys | |
from subprocess import check_output | |
import re | |
scheduler = sched.scheduler(time.time, time.sleep) | |
def sched_call(calls_per_second, callback, *args, **kw): | |
period = 1.0 / calls_per_second | |
def reload(): | |
callback(*args, **kw) | |
scheduler.enter(period, 0, reload, ()) | |
scheduler.enter(period, 0, reload, ()) | |
def sensors(): | |
result = check_output(["sensors"]) | |
for line in result.split("\n"): | |
match = re.search("CPU Temperature.*\+(.*)°C.*high",line) | |
if match: | |
date = strftime("%Y-%m-%d %H:%M:%S", localtime()) | |
with open("cpu_temperature","a") as FD: | |
FD.write(date+" "+match.group(1)+"\n") | |
sched_call(2, sensors) # call sensors two times per second | |
scheduler.run() | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment