view sensors-record @ 38:737061eac1d0 default tip

Skip more large videos and some permission issues
author IBBoard <dev@ibboard.co.uk>
date Wed, 18 Aug 2021 20:40:17 +0100
parents fe0a21557acd
children
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
	# We can't guarantee order, so sort the results
	# People also report that the ACPI sensor is unreliable, so only take temps with "low" properties, which ACPI seems to lack
	SENSORS=$(sensors | grep '^\(fan\|temp.*low\|Core\)' | sort | 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