Commits (2)
......@@ -4,13 +4,18 @@ efforts.
cpu-temp-log is a tool to use the output of 'sensors -u' and write the
motherboard temperatures to stdout. Useful to create a log that can be used
by 'ntpviz --local-cpu-temp'
by 'ntpviz --local-temps'
pi-temp-log for the Raspberry Pi. It is a tool to read a magic /sys file
to get the CPU temperature and write the temperatures to stdout. Useful
to create a log that can be used by 'ntpviz --local-cpu-temp'
to create a log that can be used by 'ntpviz --local-temps'
smartctl-temp-log for hard drives. It is a tool to read a hard drive's
SMART data to get the disk temperature and write the temperature
to stdout. Useful to create a log that can be used by 'ntpviz
--local-temps'
temper-temp-log for TEMPer USB thermometer. Useful for logging room
temperature. This reads the thermometer using the temper-python command
line utility and writes the temperatures to stdout. Useful to create a
og that can be used by 'ntpviz --local-cpu-temp'
og that can be used by 'ntpviz --local-temps'
......@@ -29,7 +29,7 @@ Field 3: temperature in degrees C
Sample crontab usage:
# take and log cpu temp every 5 mins
*/5 * * * * /usr/local/sbin/cpu-temp-log >> /var/log/ntpstats/cputemp
*/5 * * * * /usr/local/sbin/cpu-temp-log >> /var/log/ntpstats/temps
This file may only be useful as a template. The way to read your system
temperatures will be hardware specific.
......
......@@ -23,7 +23,7 @@ Field 3: CPU Temerature
Sample crontab usage:
# take and log cpu temp every 5 mins
*/5 * * * * /usr/local/sbin/pi-temp-log >> /var/log/ntpstats/cputemp
*/5 * * * * /usr/local/sbin/pi-temp-log >> /var/log/ntpstats/temps
This ONLY works on a Raspberry Pi. Maybe not all of them. The way
to read your system temperatures will be hardware specific.
......
#!/usr/bin/env python
# coding: utf-8
"""\
Usage: smartctl-temper-log [device]
Reads 'smartctl -a device' for temperature data. If a device is not
sepecified on the commline line then /dev/sda is used. Writes the
temperature found to stdout. Each line contains the unix time in
seconds since the epoch, the identifier, and the temperature in Celcius.
Before you can use this utility smartctl must be installed and
configured. See their documentation for that procedure.
Sample log from a typical hard disk.
1471573103 SMART 37.000
Field 1: unix time in seconds since the star of the epoch
Field 2: Log source (SMART)
Field 3: temperature in degrees C
Sample crontab usage:
# take and log disk temp every 5 mins
*/5 * * * * /usr/local/sbin/smart-temp-log >> /var/log/ntpstats/temps
Not all hard drives support SMART.
Not all of SMART drives are supported by smartctl.
Not all smartctl compatible drives report temperature.
Not all reported temperatures are valid.
This file may only be useful as a template. The way to read your disk
temperatures will be hardware specific.
"""
import re, subprocess, sys, time
# check for device on command line, otherwise use /dev/sda
device = '/dev/sda'
if 1 < len(sys.argv):
# process device
device = sys.argv[1]
try:
output = subprocess.check_output(["smartctl", "-a", device], \
universal_newlines=True)
except :
sys.stderr.write("ERROR: 'smartctl -a %s' failed\n" % device)
raise SystemExit(2)
lines = output.split( '\n' )
# this regex matches temperature output lines from 'sensors -u'
pat = re.compile('194 Temperature_Celsius\s+\S+\s+(\d+)\s+')
now = int(time.time())
#lines = sys.stdin.readlines()
line = ''
for line in lines:
match = pat.match( line )
if match and match.group(1):
temp = match.group(1)
sys.stdout.write( '%d SMART %s\n' % (now, temp))
......@@ -24,7 +24,7 @@ Field 3: CPU temperature in degrees C
Sample crontab usage:
# take and log cpu temp every 5 mins
*/5 * * * * /usr/local/sbin/temper-temp-log >> /var/log/ntpstats/cputemp
*/5 * * * * /usr/local/sbin/temper-temp-log >> /var/log/ntpstats/temps
"""
......