I have suddenly noticed that my computer’s fans have been more noisy than when I first bought it, and now it’s driving me crazy. I wondered if I could cut the fans’ power without increasing the temperatures inside the case too much, or even leave the case open. To test it, I spent five minutes writing a small script to monitor temperatures in Python, using smartmontools and lm-sensors.

This is that script:

#!/usr/bin/env python
# encoding: utf-8

import re
import subprocess
import time
import json

def get_temperatures(disks):
    sensors = subprocess.check_output("sensors")
    temperatures = {match[0]: float(match[1]) for match in re.findall("^(.*?)\:\s+\+?(.*?)°C", sensors, re.MULTILINE)}
    for disk in disks:
        output = subprocess.check_output(["smartctl", "-A", disk])
        temperatures[disk] = int(re.search("Temperature.*\s(\d+)\s*(?:\([\d\s]*\)|)$", output, re.MULTILINE).group(1))
    return temperatures

def main():
    while True:
        print json.dumps(get_temperatures(("/dev/sda", "/dev/sdc")))

if __name__ == "__main__":

Just launch it and redirect output to a file. It’ll dump a JSON-encoded dictionary, which you can then plot with your favorite plotting program. I hope you find this useful!