changeset 12:3adc69ceb249

Add sensor recording and graph generating scripts
author IBBoard <dev@ibboard.co.uk>
date Sat, 08 Jul 2017 18:28:27 +0100
parents d45ad0c070de
children 8052b4f3d142
files sensors-graph sensors-record
diffstat 2 files changed, 91 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sensors-graph	Sat Jul 08 18:28:27 2017 +0100
@@ -0,0 +1,46 @@
+#! /bin/bash
+
+start="-6h"
+
+if [ $# -eq 1 ]
+then
+	start=$1
+fi
+
+rrdtool graph /tmp/temps.png -w 800 -h 600 -a PNG --start "$start" \
+	--vertical-label "temps" \
+	--right-axis-label "speeds" \
+	--right-axis 100:0 \
+	DEF:core1=$HOME/.temps.rrd:core1-temp:AVERAGE \
+	DEF:core2=$HOME/.temps.rrd:core2-temp:AVERAGE \
+	DEF:core3=$HOME/.temps.rrd:core3-temp:AVERAGE \
+	DEF:core4=$HOME/.temps.rrd:core4-temp:AVERAGE \
+	DEF:isa1=$HOME/.temps.rrd:isa-temp1:AVERAGE \
+	DEF:isa2=$HOME/.temps.rrd:isa-temp2:AVERAGE \
+	DEF:isa3=$HOME/.temps.rrd:isa-temp3:AVERAGE \
+	DEF:gpu=$HOME/.temps.rrd:gpu:AVERAGE \
+	DEF:gpufan_raw=$HOME/.temps.rrd:gpu-fan:AVERAGE \
+	DEF:fan1_raw=$HOME/.temps.rrd:fan1:AVERAGE \
+	DEF:fan2_raw=$HOME/.temps.rrd:fan2:AVERAGE \
+	DEF:fan3_raw=$HOME/.temps.rrd:fan3:AVERAGE \
+	DEF:fan4_raw=$HOME/.temps.rrd:fan4:AVERAGE \
+	CDEF:fan1=fan1_raw,0.01,* \
+	CDEF:fan2=fan2_raw,0.01,* \
+	CDEF:fan3=fan3_raw,0.01,* \
+	CDEF:fan4=fan4_raw,0.01,* \
+	CDEF:gpufan=gpufan_raw,0.25,* \
+	LINE1:gpu#009900:"GPU" \
+	LINE1:core1#0000bb80:"Core 1" \
+	LINE1:core2#0000bb80:"Core 2" \
+	LINE1:core3#0000bb80:"Core 3" \
+	LINE1:core4#0000bb80:"Core 4" \
+	LINE1:isa1#bbbb0080:"ISA 1" \
+	LINE1:isa2#bbbb0080:"ISA 2" \
+	LINE1:isa3#bbbb0080:"ISA 3" \
+	AREA:fan1#99000080:"CPU Fan" \
+	AREA:fan2#99000080:"Rear Fan" \
+	AREA:gpufan#00990080:"GPU Fan" \
+	AREA:fan3#99000080:"Front Fan 1" \
+	AREA:fan4#99000080:"Front Fan 2" \
+	&& eog /tmp/temps.png
+rm /tmp/temps.png
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sensors-record	Sat Jul 08 18:28:27 2017 +0100
@@ -0,0 +1,45 @@
+#! /bin/bash
+# Record system temps and fan speeds in an RRD database
+# Built using http://web-tech.ga-usa.com/2011/08/simple-rrdtool-linux-system-temperatures/index.html as a reference
+
+type rrdtool >/dev/null 2>&1 ||  { echo "Could not find rrdtool" >&2; exit 1; }
+type sensors >/dev/null 2>&1 || { echo "Could not find sensors" >&2; exit 1; }
+
+DB=$HOME/.temps.rrd
+
+if [[ ! -e "${DB}" ]]
+then
+	#Note: "Virt" device also exists, but ALWAYS reports
+	# the same temperatures
+	rrdtool create "${DB}" --step 1 \
+		DS:core1-temp:GAUGE:2:0.0:100.0 \
+		DS:core2-temp:GAUGE:2:0.0:100.0 \
+		DS:core3-temp:GAUGE:2:0.0:100.0 \
+		DS:core4-temp:GAUGE:2:0.0:100.0 \
+		DS:fan1:GAUGE:2:0:5000 \
+		DS:fan2:GAUGE:2:0:5000 \
+		DS:fan3:GAUGE:2:0:5000 \
+		DS:fan4:GAUGE:2:0:5000 \
+		DS:fan5:GAUGE:2:0:5000 \
+		DS:isa-temp1:GAUGE:2:0.0:100.0 \
+		DS:isa-temp2:GAUGE:2:0.0:100.0 \
+		DS:isa-temp3:GAUGE:2:0.0:100.0 \
+		DS:gpu:GAUGE:2:0.0:100.0 \
+		DS:gpu-fan:GAUGE:2:0:100.0 \
+		RRA:AVERAGE:0.5:1:3600 \
+		RRA:AVERAGE:0.5:60:360 \
+		RRA:AVERAGE:0.5:300:8640 # 1hr of 1sec, 6hrs of 1min and 1mo of 5m resolution
+		# Temps above 100 are bad!
+		# Fans assume max 5000RPM
+		# nVidia fan reports in percent
+fi
+
+while true
+do
+	SENSORS=$(sensors | grep '^\(fan\|temp\|Core\)' | tail -n+3 | sed 's/Core /Core/g; s/^\([^:]\+\): [^0-9\.]*\([0-9\.]\+\)[^ ]*/\1 \2/g' | awk '{printf "%s:", $2}')
+	GPU=$(nvidia-smi -q | grep -oE "(Fan Speed|GPU Current Temp).*"|sort -r|cut -f2 -d:|cut -f2 -d" "|tr '\n' ':')
+	# "N" means record against current timestamp
+	rrdtool update "${DB}" "N:${SENSORS}${GPU%:}"
+	sleep 1
+done
+