[mythtv-users] Tracking temperatures and fan speeds in mythweb status

Matt Beadon matt.beadon at gmail.com
Tue Sep 22 21:23:26 UTC 2009


After a recent thermal scare I started looking into thermal monitoring.  In
the process I re-wrote myth_sensors.pl (since it didn't work on my system)
as myth_sensors.py.  As much as anything it was an exercise in learning
python but I figured with a few comments it could be useful to other people.

It could use some html formatting in the output (in particular I'd like it
to line up the colons) but I'll leave that as a homework exercise.  ;)

To use this script check the prerequisites below, drop it someplace on your
system, and add the path in mythtv-setup->General->Miscellaneous
Settings->Miscellaneous Status Application

So here it is:
enjoy,
Matt

#!/usr/bin/python
> #
> # myth_sensors.py
> # Retrieves sensors output and formats it for inclusion in the MythTV
> backend
> # status page.
>
> # Prerequisites:
> #   install: hddtemp +(allow sudo hddtemp), lm-sensors, python n' stuff
> #   run: sensors-detect
> #   run: sensors and use that info to update the list of sensors names
> below.
>
> import re
> import glob
> import commands
>
> # Set this list of sensors to match what you want to track. Run "sensors"
> to
> # see a list of everything that's available on your system.  The left side
> # of this list is text that will be on the status page and the right is
> what
> # needs to match the output of "sensors"
> SensorNames = {'CPU0 Temp      :':"Core 0:",
>                'CPU1 Temp      :':"Core 1:",
>                'Fan Speed (CPU):':"CPU:",
>                'Fan Speed (Sys):':"System:"}
>
> # Set the following dictionary to name whatever drives (/dev/sd?) you have
> in
> # your system (or else live with the names I use)
> DriveNames = {'/dev/sda':"OS Drive ",
>               '/dev/sdb':"Media    ",
>               '/dev/sdc':"Backup #1",
>               '/dev/sdd':"Backup #2",
>               '/dev/sd?':"Your name"}
>
> # You shouldn't need to modify anything below here.
>
> print "Current Temperatures and fan speeds:"
> (sensors_status,sensors_output) = commands.getstatusoutput('sensors')
> sortedSensorNames = SensorNames.keys()
> sortedSensorNames.sort()
> if sensors_status == 0:
>   for patterns in sortedSensorNames:
>     sensorPat =
> re.compile('^'+SensorNames[patterns]+'\s+\+*(\d{1,4})(\.\d*..C|\
> \sRPM)', re.M)
>     sensorData = sensorPat.search(sensors_output)
>     if sensorData:
>       if re.search(r'RPM',patterns):
>         suffix=" RPM"
>       else:
>         suffix="°C"
>       print patterns+" "+sensorData.group(1)+suffix
>
> (hddtemp_status,hddtemp_output) = commands.getstatusoutput('sudo hddtemp
> /dev/s\
> d?')
> if hddtemp_status == 0:
>   driveList = glob.glob('/dev/sd?')
>   for drive in sorted(driveList):
>     drivePat  = re.compile(drive+':.*:\s+(\d{1,3})..C$', re.M)
>     driveTemp = drivePat.search(hddtemp_output)
>     if driveTemp:
>       if drive in DriveNames:
>         CurrentDriveName=DriveNames[drive]
>       else:
>         CurrentDriveName="Unknown  "
>       print CurrentDriveName+" Temp : "+driveTemp.group(1)+"°C"
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mythtv.org/pipermail/mythtv-users/attachments/20090922/813268df/attachment.htm>


More information about the mythtv-users mailing list