Files
pistress/bin/plot_cpu_temp.sh
Olli Graf dcd6806e72 updated inline help
added check if gnuplot is installed correctly.
2026-02-06 07:13:36 +01:00

127 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
VERSION="1.00"
usage() {
local name=${0##*/}
cat <<-EOF
Version: ${VERSION}
Usage: ${name}
-h, --help display this help
-l, --logfile <logfile> logfile with temperature data to be plotted
-o, --output <output.png> output file the plotted chart should be written to
-c, --color <colorname> color in which the ghraph should be plotted ('red','blue'dtc.) defaults to 'red'
-t, --title <title> title of the graph
-v, --verbose verbose mode (not implemented yet)
Plots the graph of the <logfile> and writes it to <outfile>
<logfile> must contain
timestamp temperature
in seperate lines
EOF
}
check() {
if ! command -v gnuplot >/dev/null 2>&1; then
echo "gnuplot is not installed."
echo "Please use"
echo " sudo apt install -y gnuplot"
echo "and try again"
exit 5
fi
}
verbose=false
COLOR='red'
PADDING=5
VALID_ARGS=$(getopt -o vho:c:t:l: --long verbose,help,output,color:,title:,logfile: -- "$@")
if [[ $? -ne 0 ]]; then
exit 1;
fi
eval set -- "$VALID_ARGS"
while [ : ]; do
case "$1" in
-h | --help)
usage
exit 0
shift
;;
-l | --logfile)
LOGFILE="${2}"
echo "LOGFILE=${LOGFILE}"
shift 2
;;
-o | --output)
OUTFILE="${2}"
shift 2
;;
-c | --color)
COLOR="${2}"
shift 2
;;
-t | --title)
TITLE="${2}"
shift 2
;;
-v | --verbose)
verbose=true
shift
;;
--) shift;
break
;;
esac
done
check
#determine max and min values
read YMIN YMAX < <(
awk '
NR==1 { min=$2; max=$2 }
$2 < min { min=$2 }
$2 > max { max=$2 }
END { printf "%.1f %.1f\n", min, max }
' "${LOGFILE}"
)
echo "YMIN=${YMIN} YMAX=${YMAX}"
echo "Parameter geparsed."
# Eingabeparameter
if [ -z "$LOGFILE" ] || [ -z "$OUTFILE" ] || [ -z "$TITLE" ]; then
usage
exit 1
fi
echo "generating plot from ${LOGFILE}"
gnuplot \
-e "OUTFILE='${OUTFILE}'" \
-e "LOGFILE='${LOGFILE}'" \
-e "TITLE='${TITLE}'" \
-e "COLOR='${COLOR}'" \
-e "YMAX=${YMAX}" \
-e "PADDING=${PADDING}" \
-e "YMIN=${YMIN}" \
-e "
set terminal pngcairo size 1800,800;
set output OUTFILE;
set title TITLE;
set xlabel 'Zeit (s)';
set ylabel 'Temperatur (°C)';
set grid;
set key top left;
set label sprintf('Tmax: %.1f°C', YMAX-PADDING) at graph 0.98,0.02 right;
plot LOGFILE using 1:2 with lines lc rgb COLOR lw 2 title 'CPU-Temperatur';
"
echo "Plot erzeugt: $OUTFILE"
exit 0