[Git][NTPsec/ntpsec][master] 2 commits: Add smartctl-temp-log, to read SMART temperatures.

Gary E. Miller gitlab at mg.gitlab.com
Wed Aug 31 21:00:51 UTC 2016


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
9aa6dce4 by Gary E. Miller at 2016-08-31T13:43:49-07:00
Add smartctl-temp-log, to read SMART temperatures.

Also some doc cleanup.

- - - - -
881d3d72 by Gary E. Miller at 2016-08-31T14:00:30-07:00
Catch subprocess failures, add device option, doc updates.

- - - - -


5 changed files:

- contrib/README
- contrib/cpu-temp-log
- contrib/pi-temp-log
- + contrib/smartctl-temp-log
- contrib/temper-temp-log


Changes:

=====================================
contrib/README
=====================================
--- a/contrib/README
+++ b/contrib/README
@@ -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'


=====================================
contrib/cpu-temp-log
=====================================
--- a/contrib/cpu-temp-log
+++ b/contrib/cpu-temp-log
@@ -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.


=====================================
contrib/pi-temp-log
=====================================
--- a/contrib/pi-temp-log
+++ b/contrib/pi-temp-log
@@ -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.


=====================================
contrib/smartctl-temp-log
=====================================
--- /dev/null
+++ b/contrib/smartctl-temp-log
@@ -0,0 +1,68 @@
+#!/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))
+


=====================================
contrib/temper-temp-log
=====================================
--- a/contrib/temper-temp-log
+++ b/contrib/temper-temp-log
@@ -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
 
 """
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/de0d8855c97f468f1dc7375a4d7956070c5293d5...881d3d72865f2d215ea5f26604464084d665dc20
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160831/23396ca9/attachment.html>


More information about the vc mailing list