Show in color when temperatures exceed critical values
This commit is contained in:
parent
2f05163369
commit
0c2138ccf2
@ -8,9 +8,9 @@
|
|||||||
# Display configuration for HDD, NVME, CPU
|
# Display configuration for HDD, NVME, CPU
|
||||||
# Set to 0 to disable line breaks
|
# Set to 0 to disable line breaks
|
||||||
# Note: use these settings only if the displayed layout is broken
|
# Note: use these settings only if the displayed layout is broken
|
||||||
CPU_ITEMS_PER_ROW=0;
|
CPU_ITEMS_PER_ROW=0
|
||||||
NVME_ITEMS_PER_ROW=0;
|
NVME_ITEMS_PER_ROW=0
|
||||||
HDD_ITEMS_PER_ROW=0;
|
HDD_ITEMS_PER_ROW=0
|
||||||
|
|
||||||
# Known CPU sensor names. They can be full or partial but should ensure unambiguous identification.
|
# Known CPU sensor names. They can be full or partial but should ensure unambiguous identification.
|
||||||
# Should new ones be added, also update logic in configure() function.
|
# Should new ones be added, also update logic in configure() function.
|
||||||
@ -57,21 +57,21 @@ function usage {
|
|||||||
# Define a function to install packages
|
# Define a function to install packages
|
||||||
function install_packages {
|
function install_packages {
|
||||||
# Check if the 'sensors' command is available on the system
|
# Check if the 'sensors' command is available on the system
|
||||||
if (! command -v sensors &> /dev/null); then
|
if (! command -v sensors &>/dev/null); then
|
||||||
# If the 'sensors' command is not available, prompt the user to install lm-sensors
|
# If the 'sensors' command is not available, prompt the user to install lm-sensors
|
||||||
read -p "lm-sensors is not installed. Would you like to install it? (y/n) " choice
|
read -p "lm-sensors is not installed. Would you like to install it? (y/n) " choice
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
y|Y )
|
y | Y)
|
||||||
# If the user chooses to install lm-sensors, update the package list and install the package
|
# If the user chooses to install lm-sensors, update the package list and install the package
|
||||||
apt-get update
|
apt-get update
|
||||||
apt-get install lm-sensors
|
apt-get install lm-sensors
|
||||||
;;
|
;;
|
||||||
n|N )
|
n | N)
|
||||||
# If the user chooses not to install lm-sensors, exit the script with a zero status code
|
# If the user chooses not to install lm-sensors, exit the script with a zero status code
|
||||||
msg "Decided to not install lm-sensors. The mod cannot run without it. Exiting..."
|
msg "Decided to not install lm-sensors. The mod cannot run without it. Exiting..."
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
* )
|
*)
|
||||||
# If the user enters an invalid input, print an error message and exit the script with a non-zero status code
|
# If the user enters an invalid input, print an error message and exit the script with a non-zero status code
|
||||||
err "Invalid input. Exiting..."
|
err "Invalid input. Exiting..."
|
||||||
;;
|
;;
|
||||||
@ -89,7 +89,7 @@ function configure {
|
|||||||
msg "\nDetecting support for HDD/SDD temperature sensors..."
|
msg "\nDetecting support for HDD/SDD temperature sensors..."
|
||||||
if (lsmod | grep -wq "drivetemp"); then
|
if (lsmod | grep -wq "drivetemp"); then
|
||||||
# Check if SDD/HDD data is available
|
# Check if SDD/HDD data is available
|
||||||
if (echo "$sensorsOutput" | grep -q "drivetemp-scsi-" ); then
|
if (echo "$sensorsOutput" | grep -q "drivetemp-scsi-"); then
|
||||||
msg "Detected sensors:\n$(echo "$sensorsOutput" | grep -o '"drivetemp-scsi[^"]*"' | sed 's/"//g')"
|
msg "Detected sensors:\n$(echo "$sensorsOutput" | grep -o '"drivetemp-scsi[^"]*"' | sed 's/"//g')"
|
||||||
enableHddTemp=true
|
enableHddTemp=true
|
||||||
else
|
else
|
||||||
@ -102,7 +102,7 @@ function configure {
|
|||||||
|
|
||||||
# Check if NVMe data is available
|
# Check if NVMe data is available
|
||||||
msg "\nDetecting support for NVMe temperature sensors..."
|
msg "\nDetecting support for NVMe temperature sensors..."
|
||||||
if (echo "$sensorsOutput" | grep -q "nvme-" ); then
|
if (echo "$sensorsOutput" | grep -q "nvme-"); then
|
||||||
msg "Detected sensors:\n$(echo "$sensorsOutput" | grep -o '"nvme[^"]*"' | sed 's/"//g')"
|
msg "Detected sensors:\n$(echo "$sensorsOutput" | grep -o '"nvme[^"]*"' | sed 's/"//g')"
|
||||||
enableNvmeTemp=true
|
enableNvmeTemp=true
|
||||||
else
|
else
|
||||||
@ -160,7 +160,7 @@ function configure {
|
|||||||
|
|
||||||
# Look for fan speeds
|
# Look for fan speeds
|
||||||
msg "\nDetecting support for fan speeds..."
|
msg "\nDetecting support for fan speeds..."
|
||||||
if (echo "$sensorsOutput" | grep -q "fan[0-9]*_input" ); then
|
if (echo "$sensorsOutput" | grep -q "fan[0-9]*_input"); then
|
||||||
msg "Fan speeds detected:\n$(echo "$sensorsOutput" | grep -o 'fan[0-9]*_input[^"]*')"
|
msg "Fan speeds detected:\n$(echo "$sensorsOutput" | grep -o 'fan[0-9]*_input[^"]*')"
|
||||||
enableFanSpeed=true
|
enableFanSpeed=true
|
||||||
else
|
else
|
||||||
@ -232,30 +232,44 @@ function install_mod {
|
|||||||
const itemsPerRow = $CPU_ITEMS_PER_ROW;\n\
|
const itemsPerRow = $CPU_ITEMS_PER_ROW;\n\
|
||||||
// ---\n\
|
// ---\n\
|
||||||
const objValue = JSON.parse(value);\n\
|
const objValue = JSON.parse(value);\n\
|
||||||
if(objValue.hasOwnProperty(cpuAddress)) {\n\
|
if (objValue.hasOwnProperty(cpuAddress)) {\n\
|
||||||
const items = objValue[cpuAddress],\n\
|
const items = objValue[cpuAddress];\n\
|
||||||
itemKeys = Object.keys(items).filter(item => { return String(item).startsWith(cpuItemPrefix); });\n\
|
const itemKeys = Object.keys(items).filter(item => { return String(item).startsWith(cpuItemPrefix); });\n\
|
||||||
let temps = [];\n\
|
let temps = [];\n\
|
||||||
itemKeys.forEach((coreKey) => {\n\
|
itemKeys.forEach((coreKey) => {\n\
|
||||||
try {\n\
|
try {\n\
|
||||||
|
let tempVal = NaN, tempMax = NaN, tempCrit = NaN;\n\
|
||||||
Object.keys(items[coreKey]).forEach((secondLevelKey) => {\n\
|
Object.keys(items[coreKey]).forEach((secondLevelKey) => {\n\
|
||||||
if (secondLevelKey.includes('_input')) {\n\
|
if (secondLevelKey.endsWith('_input')) {\n\
|
||||||
let tempStr = '';\n\
|
tempVal = parseFloat(items[coreKey][secondLevelKey]);\n\
|
||||||
let temp = items[coreKey][secondLevelKey];\n\
|
} else if (secondLevelKey.endsWith('_max')) {\n\
|
||||||
let index = coreKey.match(/\\\S+\\\s*(\\\d+)/);\n\
|
tempMax = parseFloat(items[coreKey][secondLevelKey]);\n\
|
||||||
if(index !== null && index.length > 1) {\n\
|
} else if (secondLevelKey.endsWith('_crit')) {\n\
|
||||||
index = index[1];\n\
|
tempCrit = parseFloat(items[coreKey][secondLevelKey]);\n\
|
||||||
tempStr = \`\${cpuTempCaption} \${index}: \${temp}°C\`;\n\
|
|
||||||
}\n\
|
}\n\
|
||||||
else {\n\
|
});\n\
|
||||||
tempStr = \`\${cpuTempCaption}: \${temp}°C\`;\n\
|
if (!isNaN(tempVal)) {\n\
|
||||||
|
let tempStyle = '';\n\
|
||||||
|
if (!isNaN(tempMax) && tempVal > tempMax) {\n\
|
||||||
|
tempStyle = 'color: #FFC300; font-weight: bold;';\n\
|
||||||
|
}\n\
|
||||||
|
if (!isNaN(tempCrit) && tempVal > tempCrit) {\n\
|
||||||
|
tempStyle = 'color: red; font-weight: bold;';\n\
|
||||||
|
}\n\
|
||||||
|
let tempStr = '';\n\
|
||||||
|
let tempIndex = coreKey.match(/\\\S+\\\s*(\\\d+)/);\n\
|
||||||
|
if (tempIndex !== null && tempIndex.length > 1) {\n\
|
||||||
|
tempIndex = tempIndex[1];\n\
|
||||||
|
tempStr = \`\${cpuTempCaption} \${tempIndex}: <span style=\"\${tempStyle}\">\${tempVal}°C</span>\`;\n\
|
||||||
|
} else {\n\
|
||||||
|
tempStr = \`\${cpuTempCaption}: \${tempVal}°C\`;\n\
|
||||||
}\n\
|
}\n\
|
||||||
temps.push(tempStr);\n\
|
temps.push(tempStr);\n\
|
||||||
}\n\
|
}\n\
|
||||||
})\n\
|
} catch (e) { /*_*/\n\
|
||||||
} catch(e) { /*_*/ }\n\
|
}\n\
|
||||||
});\n\
|
});\n\
|
||||||
const result = temps.map((strTemp, index, arr) => { return strTemp + (index + 1 < arr.length ? (itemsPerRow > 0 && (index + 1) % itemsPerRow === 0 ? '<br>' : ' | ') : '')});\n\
|
const result = temps.map((strTemp, index, arr) => { return strTemp + (index + 1 < arr.length ? (itemsPerRow > 0 && (index + 1) % itemsPerRow === 0 ? '<br>' : ' | ') : ''); });\n\
|
||||||
return '<div style=\"text-align: left; margin-left: 28px;\">' + (result.length > 0 ? result.join('') : 'N/A') + '</div>';\n\
|
return '<div style=\"text-align: left; margin-left: 28px;\">' + (result.length > 0 ? result.join('') : 'N/A') + '</div>';\n\
|
||||||
}\n\
|
}\n\
|
||||||
}\n\
|
}\n\
|
||||||
@ -292,12 +306,27 @@ function install_mod {
|
|||||||
let temps = [];\n\
|
let temps = [];\n\
|
||||||
drvKeys.forEach((drvKey, index) => {\n\
|
drvKeys.forEach((drvKey, index) => {\n\
|
||||||
try {\n\
|
try {\n\
|
||||||
|
let tempVal = NaN, tempMax = NaN, tempCrit = NaN;\n\
|
||||||
Object.keys(objValue[drvKey][sensorName]).forEach((secondLevelKey) => {\n\
|
Object.keys(objValue[drvKey][sensorName]).forEach((secondLevelKey) => {\n\
|
||||||
if (secondLevelKey.includes('_input')) {\n\
|
if (secondLevelKey.endsWith('_input')) {\n\
|
||||||
let temp = objValue[drvKey][sensorName][secondLevelKey];\n\
|
tempVal = parseFloat(objValue[drvKey][sensorName][secondLevelKey]);\n\
|
||||||
temps.push(\`Drive \${index + 1}: \${temp}°C\`);\n\
|
} else if (secondLevelKey.endsWith('_max')) {\n\
|
||||||
|
tempMax = parseFloat(objValue[drvKey][sensorName][secondLevelKey]);\n\
|
||||||
|
} else if (secondLevelKey.endsWith('_crit')) {\n\
|
||||||
|
tempCrit = parseFloat(objValue[drvKey][sensorName][secondLevelKey]);\n\
|
||||||
|
}\n\
|
||||||
|
});\n\
|
||||||
|
if (!isNaN(tempVal)) {\n\
|
||||||
|
let tempStyle = '';\n\
|
||||||
|
if (!isNaN(tempMax) && tempVal > tempMax) {\n\
|
||||||
|
tempStyle = 'color: #FFC300; font-weight: bold;';\n\
|
||||||
|
}\n\
|
||||||
|
if (!isNaN(tempCrit) && tempVal > tempCrit) {\n\
|
||||||
|
tempStyle = 'color: red; font-weight: bold;';\n\
|
||||||
|
}\n\
|
||||||
|
const tempStr = \`Drive \${index + 1}: <span style=\"\${tempStyle}\">\${tempVal}°C</span>\`;\n\
|
||||||
|
temps.push(tempStr);\n\
|
||||||
}\n\
|
}\n\
|
||||||
})\n\
|
|
||||||
} catch(e) { /*_*/ }\n\
|
} catch(e) { /*_*/ }\n\
|
||||||
});\n\
|
});\n\
|
||||||
const result = temps.map((strTemp, index, arr) => { return strTemp + (index + 1 < arr.length ? ((index + 1) % itemsPerRow === 0 ? '<br>' : ' | ') : ''); });\n\
|
const result = temps.map((strTemp, index, arr) => { return strTemp + (index + 1 < arr.length ? ((index + 1) % itemsPerRow === 0 ? '<br>' : ' | ') : ''); });\n\
|
||||||
@ -334,12 +363,27 @@ function install_mod {
|
|||||||
let temps = [];\n\
|
let temps = [];\n\
|
||||||
nvmeKeys.forEach((nvmeKey, index) => {\n\
|
nvmeKeys.forEach((nvmeKey, index) => {\n\
|
||||||
try {\n\
|
try {\n\
|
||||||
|
let tempVal = NaN, tempMax = NaN, tempCrit = NaN;\n\
|
||||||
Object.keys(objValue[nvmeKey][sensorName]).forEach((secondLevelKey) => {\n\
|
Object.keys(objValue[nvmeKey][sensorName]).forEach((secondLevelKey) => {\n\
|
||||||
if (secondLevelKey.includes('_input')) {\n\
|
if (secondLevelKey.endsWith('_input')) {\n\
|
||||||
let temp = objValue[nvmeKey][sensorName][secondLevelKey];\n\
|
tempVal = parseFloat(objValue[nvmeKey][sensorName][secondLevelKey]);\n\
|
||||||
temps.push(\`Drive \${index + 1}: \${temp}°C\`);\n\
|
} else if (secondLevelKey.endsWith('_max')) {\n\
|
||||||
|
tempMax = parseFloat(objValue[nvmeKey][sensorName][secondLevelKey]);\n\
|
||||||
|
} else if (secondLevelKey.endsWith('_crit')) {\n\
|
||||||
|
tempCrit = parseFloat(objValue[nvmeKey][sensorName][secondLevelKey]);\n\
|
||||||
|
}\n\
|
||||||
|
});\n\
|
||||||
|
if (!isNaN(tempVal)) {\n\
|
||||||
|
let tempStyle = '';\n\
|
||||||
|
if (!isNaN(tempMax) && tempVal > tempMax) {\n\
|
||||||
|
tempStyle = 'color: #FFC300; font-weight: bold;';\n\
|
||||||
|
}\n\
|
||||||
|
if (!isNaN(tempCrit) && tempVal > tempCrit) {\n\
|
||||||
|
tempStyle = 'color: red; font-weight: bold;';\n\
|
||||||
|
}\n\
|
||||||
|
const tempStr = \`Drive \${index + 1}: <span style=\"\${tempStyle}\">\${tempVal}°C</span>\`;\n\
|
||||||
|
temps.push(tempStr);\n\
|
||||||
}\n\
|
}\n\
|
||||||
})\n\
|
|
||||||
} catch(e) { /*_*/ }\n\
|
} catch(e) { /*_*/ }\n\
|
||||||
});\n\
|
});\n\
|
||||||
const result = temps.map((strTemp, index, arr) => { return strTemp + (index + 1 < arr.length ? ((index + 1) % itemsPerRow === 0 ? '<br>' : ' | ') : ''); });\n\
|
const result = temps.map((strTemp, index, arr) => { return strTemp + (index + 1 < arr.length ? ((index + 1) % itemsPerRow === 0 ? '<br>' : ' | ') : ''); });\n\
|
||||||
|
|||||||
@ -81,7 +81,7 @@ function install_mod {
|
|||||||
|
|
||||||
if [ ! -h "$proxmoxlibminjs" ]; then
|
if [ ! -h "$proxmoxlibminjs" ]; then
|
||||||
msg "Disabling minified front-end library file..."
|
msg "Disabling minified front-end library file..."
|
||||||
(mv "$proxmoxlibminjs" "$BACKUP_DIR/proxmoxlib.min.js.$timestamp" && \
|
(mv "$proxmoxlibminjs" "$BACKUP_DIR/proxmoxlib.min.js.$timestamp" &&
|
||||||
ln -s "$proxmoxlibjs" "$proxmoxlibminjs") || err "Error disabling minified front-end library file."
|
ln -s "$proxmoxlibjs" "$proxmoxlibminjs") || err "Error disabling minified front-end library file."
|
||||||
restart=true
|
restart=true
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user