Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Menu
Open sidebar
NTPsec
ntpsec
Compare Revisions
de0d8855c97f468f1dc7375a4d7956070c5293d5...881d3d72865f2d215ea5f26604464084d665dc20
Commits (2)
Add smartctl-temp-log, to read SMART temperatures.
· 9aa6dce4
Gary E. Miller
authored
Aug 31, 2016
Also some doc cleanup.
9aa6dce4
Catch subprocess failures, add device option, doc updates.
· 881d3d72
Gary E. Miller
authored
Aug 31, 2016
881d3d72
Hide whitespace changes
Inline
Side-by-side
contrib/README
View file @
881d3d72
...
...
@@ -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-temp
s
'
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-temp
s
'
contrib/cpu-temp-log
View file @
881d3d72
...
...
@@ -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/
cpu
temp
*/5 * * * * /usr/local/sbin/cpu-temp-log >> /var/log/ntpstats/temp
s
This file may only be useful as a template. The way to read your system
temperatures will be hardware specific.
...
...
contrib/pi-temp-log
View file @
881d3d72
...
...
@@ -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/
cpu
temp
*/5 * * * * /usr/local/sbin/pi-temp-log >> /var/log/ntpstats/temp
s
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
0 → 100755
View file @
881d3d72
#!/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
View file @
881d3d72
...
...
@@ -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/
cpu
temp
*/5 * * * * /usr/local/sbin/temper-temp-log >> /var/log/ntpstats/temp
s
"""
...
...