From 3490d3a07e63359027c8c261af31f09e8d7cb162 Mon Sep 17 00:00:00 2001 From: Meliox <5264368+Meliox@users.noreply.github.com> Date: Sun, 16 Jun 2024 11:42:31 +0200 Subject: [PATCH 1/2] Add "remote" debug option of json file (#50) --- pve-mod-gui-sensors.sh | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/pve-mod-gui-sensors.sh b/pve-mod-gui-sensors.sh index 21d504f..ba01218 100644 --- a/pve-mod-gui-sensors.sh +++ b/pve-mod-gui-sensors.sh @@ -30,7 +30,11 @@ nodespm="/usr/share/perl5/PVE/API2/Nodes.pm" DEBUG_SAVE_PATH="$SCRIPT_CWD" DEBUG_SAVE_FILENAME="sensorsdata.json" -############################################### +##################### DO NOT EDIT BELOW ####################### +# Only to be used to debug on other systems. Save the "sensor -j" output into a json file. +# Information will be loaded for script configuration and presented in Proxmox. +DEBUG_REMOTE=false +JSON_FILE="/tmp/sensordata.json" # Helper functions function msg { @@ -89,7 +93,15 @@ function install_packages { function configure { sensorsDetected=false - local sensorsOutput=$(sensors -j) + local sensorsOutput + + if [ $DEBUG_REMOTE = true ]; then + warn "Remote debugging is used. Sensor readings from dump file $JSON_FILE will be used." + sensorsOutput=$(cat $JSON_FILE) + else + sensorsOutput=$(sensors -j) + fi + if [ $? -ne 0 ]; then err "Sensor output error.\n\nCommand output:\n${sensorsOutput}\n\nExiting...\n" fi @@ -249,9 +261,14 @@ function install_mod { enableSensors=true if [[ "$enableSensors" == true ]]; then - # WTF: sensors -f used for Fahrenheit breaks the fan speeds :| - #local sensorsCmd=$([[ "$TEMP_UNIT" = "F" ]] && echo "sensors -j -f" || echo "sensors -j") - local sensorsCmd="sensors -j" + local sensorsCmd + if [ $DEBUG_REMOTE = true ]; then + sensorsCmd="cat \"$JSON_FILE\"" + else + # WTF: sensors -f used for Fahrenheit breaks the fan speeds :| + #local sensorsCmd=$([[ "$TEMP_UNIT" = "F" ]] && echo "sensors -j -f" || echo "sensors -j") + sensorsCmd="sensors -j" + fi sed -i '/my \$dinfo = df('\''\/'\'', 1);/i\'$'\t''$res->{sensorsOutput} = `'"$sensorsCmd"'`;\n\t# sanitize JSON output\n\t$res->{sensorsOutput} =~ s/ERROR:.+\\s(\\w+):\\s(.+)/\\"$1\\": 0.000,/g;\n\t$res->{sensorsOutput} =~ s/ERROR:.+\\s(\\w+)!/\\"$1\\": 0.000,/g;\n\t$res->{sensorsOutput} =~ s/,(.*[.\\n]*.+})/$1/g;\n' "$nodespm" msg "Sensors' output added to \"$nodespm\"." fi From ba3991a3a2d62847b114ba6c75c4676a06f3596a Mon Sep 17 00:00:00 2001 From: Meliox <5264368+Meliox@users.noreply.github.com> Date: Sun, 16 Jun 2024 13:01:46 +0200 Subject: [PATCH 2/2] Add support for multiple AMD temp types (#49) --- pve-mod-gui-sensors.sh | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/pve-mod-gui-sensors.sh b/pve-mod-gui-sensors.sh index ba01218..1895c02 100644 --- a/pve-mod-gui-sensors.sh +++ b/pve-mod-gui-sensors.sh @@ -112,15 +112,27 @@ function configure { if (echo "$sensorsOutput" | grep -q "$item"); then case "$item" in "coretemp-"*) - CPU_ADDRESS_PREFIX=$item - CPU_ITEM_PREFIX="Core " - CPU_TEMP_CAPTION="Core" + # Intel CPU + # Set temperature search criteria + if (echo "$sensorsOutput" | grep -A 10 "$item" | grep -q "Core "); then + CPU_ADDRESS_PREFIX=$item + CPU_ITEM_PREFIX="Core " + CPU_TEMP_CAPTION="Core" + fi break ;; "k10temp-"*) - CPU_ADDRESS_PREFIX=$item - CPU_ITEM_PREFIX="Tccd" - CPU_TEMP_CAPTION="Temp" + # AMD CPU + # Find and set temperature search criteria + if (echo "$sensorsOutput" | grep -A 4 "$item" | grep -q -e "Tctl" -e "Tccd"); then + CPU_ADDRESS_PREFIX=$item + CPU_ITEM_PREFIX="Tccd" + CPU_TEMP_CAPTION="Temp" + elif (echo "$sensorsOutput" | grep -A 4 "$item" | grep -q "temp"); then + CPU_ADDRESS_PREFIX=$item + CPU_ITEM_PREFIX="temp" + CPU_TEMP_CAPTION="Temp" + fi break ;; *)