view sensors-record @ 23:489ba6ea3c35

Add some more directories to back up Also reformats the command for readability
author IBBoard <dev@ibboard.co.uk>
date Sun, 09 Jun 2019 15:53:48 +0100
parents 3adc69ceb249
children fb4dd1974129
line wrap: on
line source

#! /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