multiple fixes.

This commit is contained in:
Meliox 2025-09-06 16:20:32 +02:00
parent f42b363d90
commit a5a3e3968c

View File

@ -389,7 +389,7 @@ function install_mod {
# Add new item to the items array in PVE.node.StatusView # Add new item to the items array in PVE.node.StatusView
if [[ -z $(cat "$PVE_MANAGER_LIB_JS_FILE" | grep -e "itemId: 'thermal[[:alnum:]]*'") ]]; then if [[ -z $(cat "$PVE_MANAGER_LIB_JS_FILE" | grep -e "itemId: 'thermal[[:alnum:]]*'") ]]; then
local tempHelperCtorParams=$([[ "$TEMP_UNIT" = "F" ]] && echo '{srcUnit: PVE.mod.TempHelper.CELSIUS, dstUnit: PVE.mod.TempHelper.FAHRENHEIT}' || echo '{srcUnit: PVE.mod.TempHelper.CELSIUS, dstUnit: PVE.mod.TempHelper.CELSIUS}') HELPERCTORPARAMS=$([[ "$TEMP_UNIT" = "F" ]] && echo '{srcUnit: PVE.mod.TempHelper.CELSIUS, dstUnit: PVE.mod.TempHelper.FAHRENHEIT}' || echo '{srcUnit: PVE.mod.TempHelper.CELSIUS, dstUnit: PVE.mod.TempHelper.CELSIUS}')
# Expand space in StatusView # Expand space in StatusView
expand_statusview_space expand_statusview_space
@ -399,6 +399,7 @@ function install_mod {
# Generate and insert widgets using the helper function # Generate and insert widgets using the helper function
generate_and_insert_widget "$ENABLE_SYSTEM_INFO" "generate_system_info" "system_info" generate_and_insert_widget "$ENABLE_SYSTEM_INFO" "generate_system_info" "system_info"
ENABLE_CPU=true
generate_and_insert_widget "$ENABLE_CPU" "generate_cpu_widget" "cpu" generate_and_insert_widget "$ENABLE_CPU" "generate_cpu_widget" "cpu"
# #
@ -455,17 +456,16 @@ generate_and_insert_widget() {
local temp_js_file="/tmp/${widget_name}_widget.js" local temp_js_file="/tmp/${widget_name}_widget.js"
"$generator_func" "$temp_js_file" "$generator_func" "$temp_js_file"
insert_widget_after_thermal "$temp_js_file" insert_widget_after_thermal "$temp_js_file"
rm "$temp_js_file" #rm "$temp_js_file"
fi fi
} }
# Function to generate drive header # Function to generate drive header
generate_drive_header() { generate_drive_header() {
if [ "$ENABLE_NVME_TEMP" = true ] || [ "$ENABLE_HDD_TEMP" = true ]; then if [ "$ENABLE_NVME_TEMP" = true ] || [ "$ENABLE_HDD_TEMP" = true ]; then
local temp_js_file="/tmp/drive_header.js" local temp_js_file="/tmp/drive_header.js"
#region drive header heredoc #region drive header heredoc
cat > "$1" <<'EOF' cat > "$temp_js_file" <<'EOF'
{ {
xtype: 'box', xtype: 'box',
colspan: 2, colspan: 2,
@ -552,9 +552,6 @@ EOF
fi fi
} }
# Call the function
setup_node_summary_container
# Function to add visual spacing separator after the last widget # Function to add visual spacing separator after the last widget
add_visual_separator() { add_visual_separator() {
# Check for the presence of items in the reverse order of display # Check for the presence of items in the reverse order of display
@ -702,10 +699,10 @@ generate_and_insert_temp_helper() {
getUnit: function(plainText) { getUnit: function(plainText) {
switch (this.dstUnit) { switch (this.dstUnit) {
case this.self.CELSIUS: case this.self.CELSIUS:
return plainText !== true ? '\&deg;C' : '\\\'C'; return plainText !== true ? '&deg;C' : '\'C';
case this.self.FAHRENHEIT: case this.self.FAHRENHEIT:
return plainText !== true ? '\&deg;F' : '\\\'F'; return plainText !== true ? '&deg;F' : '\'F';
default: default:
Ext.raise({ Ext.raise({
@ -728,121 +725,128 @@ EOF
# Function to generate CPU widget # Function to generate CPU widget
generate_cpu_widget() { generate_cpu_widget() {
#region cpu widget heredoc #region cpu widget heredoc
cat > "$1" <<'EOF' # use subshell to allow variable expansion
{ (
itemId: 'thermalCpu', export CPU_ITEMS_PER_ROW
colspan: 2, export CPU_TEMP_TARGET
printBar: false, export HELPERCTORPARAMS
title: gettext('CPU Thermal State'),
iconCls: 'fa fa-fw fa-thermometer-half', cat <<'EOF' | envsubst > "$1"
textField: 'sensorsOutput', {
renderer: function(value){ itemId: 'thermalCpu',
// sensors configuration colspan: 2,
const cpuTempHelper = Ext.create('PVE.mod.TempHelper', $tempHelperCtorParams); printBar: false,
// display configuration title: gettext('CPU Thermal State'),
const itemsPerRow = $CPU_ITEMS_PER_ROW; iconCls: 'fa fa-fw fa-thermometer-half',
// --- textField: 'sensorsOutput',
let objValue; renderer: function(value){
try { // sensors configuration
objValue = JSON.parse(value) || {}; const cpuTempHelper = Ext.create('PVE.mod.TempHelper', $HELPERCTORPARAMS);
} catch(e) { // display configuration
objValue = {}; const itemsPerRow = $CPU_ITEMS_PER_ROW;
} // ---
const cpuKeysI = Object.keys(objValue).filter(item => String(item).startsWith('coretemp-isa-')).sort(); let objValue;
const cpuKeysA = Object.keys(objValue).filter(item => String(item).startsWith('k10temp-pci-')).sort(); try {
const bINTEL = cpuKeysI.length > 0 ? true : false; objValue = JSON.parse(value) || {};
const INTELPackagePrefix = '$CPU_TEMP_TARGET' == 'Core' ? 'Core ' : 'Package id'; } catch(e) {
const INTELPackageCaption = '$CPU_TEMP_TARGET' == 'Core' ? 'Core' : 'Package'; objValue = {};
let AMDPackagePrefix = 'Tccd'; }
let AMDPackageCaption = 'Chiplet'; const cpuKeysI = Object.keys(objValue).filter(item => String(item).startsWith('coretemp-isa-')).sort();
if (cpuKeysA.length > 0) { const cpuKeysA = Object.keys(objValue).filter(item => String(item).startsWith('k10temp-pci-')).sort();
let bTccd = false; const bINTEL = cpuKeysI.length > 0 ? true : false;
let bTctl = false; const INTELPackagePrefix = '$CPU_TEMP_TARGET' == 'Core' ? 'Core ' : 'Package id';
let bTdie = false; const INTELPackageCaption = '$CPU_TEMP_TARGET' == 'Core' ? 'Core' : 'Package';
cpuKeysA.forEach((cpuKey, cpuIndex) => { let AMDPackagePrefix = 'Tccd';
let items = objValue[cpuKey]; let AMDPackageCaption = 'Chiplet';
bTccd = Object.keys(items).findIndex(item => { return String(item).startsWith('Tccd'); }) >= 0; if (cpuKeysA.length > 0) {
bTctl = Object.keys(items).findIndex(item => { return String(item).startsWith('Tctl'); }) >= 0; let bTccd = false;
bTdie = Object.keys(items).findIndex(item => { return String(item).startsWith('Tdie'); }) >= 0; let bTctl = false;
let bTdie = false;
cpuKeysA.forEach((cpuKey, cpuIndex) => {
let items = objValue[cpuKey];
bTccd = Object.keys(items).findIndex(item => { return String(item).startsWith('Tccd'); }) >= 0;
bTctl = Object.keys(items).findIndex(item => { return String(item).startsWith('Tctl'); }) >= 0;
bTdie = Object.keys(items).findIndex(item => { return String(item).startsWith('Tdie'); }) >= 0;
});
if (bTccd && bTctl && '$CPU_TEMP_TARGET' == 'Core') {
AMDPackagePrefix = 'Tccd';
AMDPackageCaption = 'Chiplet';
} else if (bTdie) {
AMDPackagePrefix = 'Tdie';
AMDPackageCaption = 'Temp';
} else if (bTctl) {
AMDPackagePrefix = 'Tctl';
AMDPackageCaption = 'Temp';
} else {
AMDPackagePrefix = 'temp';
AMDPackageCaption = 'Temp';
}
}
const cpuKeys = bINTEL ? cpuKeysI : cpuKeysA;
const cpuItemPrefix = bINTEL ? INTELPackagePrefix : AMDPackagePrefix;
const cpuTempCaption = bINTEL ? INTELPackageCaption : AMDPackageCaption;
const formatTemp = bINTEL ? '0' : '0.0';
const cpuCount = cpuKeys.length;
let temps = [];
cpuKeys.forEach((cpuKey, cpuIndex) => {
let cpuTemps = [];
const items = objValue[cpuKey];
const itemKeys = Object.keys(items).filter(item => { return String(item).includes(cpuItemPrefix); });
itemKeys.forEach((coreKey) => {
try {
let tempVal = NaN, tempMax = NaN, tempCrit = NaN;
Object.keys(items[coreKey]).forEach((secondLevelKey) => {
if (secondLevelKey.endsWith('_input')) {
tempVal = cpuTempHelper.getTemp(parseFloat(items[coreKey][secondLevelKey]));
} else if (secondLevelKey.endsWith('_max')) {
tempMax = cpuTempHelper.getTemp(parseFloat(items[coreKey][secondLevelKey]));
} else if (secondLevelKey.endsWith('_crit')) {
tempCrit = cpuTempHelper.getTemp(parseFloat(items[coreKey][secondLevelKey]));
}
});
if (!isNaN(tempVal)) {
let tempStyle = '';
if (!isNaN(tempMax) && tempVal >= tempMax) {
tempStyle = 'color: #FFC300; font-weight: bold;';
}
if (!isNaN(tempCrit) && tempVal >= tempCrit) {
tempStyle = 'color: red; font-weight: bold;';
}
let tempStr = '';
let tempIndex = coreKey.match(/(?:P\s+Core|E\s+Core|Core)\s*(\d+)/);
if (tempIndex !== null && tempIndex.length > 1) {
tempIndex = tempIndex[1];
let coreType = coreKey.startsWith('P Core') ? 'P Core' :
coreKey.startsWith('E Core') ? 'E Core' :
cpuTempCaption;
tempStr = `${coreType}&nbsp;${tempIndex}:&nbsp;<span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`;
} else {
// fallback for CPUs which do not have a core index
let coreType = coreKey.startsWith('P Core') ? 'P Core' :
coreKey.startsWith('E Core') ? 'E Core' :
cpuTempCaption;
tempStr = `${coreType}:&nbsp;<span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`;
}
cpuTemps.push(tempStr);
}
} catch (e) { /*_*/ }
});
if(cpuTemps.length > 0) {
temps.push(cpuTemps);
}
}); });
if (bTccd && bTctl && '$CPU_TEMP_TARGET' == 'Core') { let result = '';
AMDPackagePrefix = 'Tccd'; temps.forEach((cpuTemps, cpuIndex) => {
AMDPackageCaption = 'Chiplet'; const strCoreTemps = cpuTemps.map((strTemp, index, arr) => { return strTemp + (index + 1 < arr.length ? (itemsPerRow > 0 && (index + 1) % itemsPerRow === 0 ? '<br>' : '&nbsp;| ') : ''); })
} else if (bTdie) { if(strCoreTemps.length > 0) {
AMDPackagePrefix = 'Tdie'; result += (cpuCount > 1 ? `CPU ${cpuIndex+1}: ` : '') + strCoreTemps.join('') + (cpuIndex < cpuCount ? '<br>' : '');
AMDPackageCaption = 'Temp'; }
} else if (bTctl) {
AMDPackagePrefix = 'Tctl';
AMDPackageCaption = 'Temp';
} else {
AMDPackagePrefix = 'temp';
AMDPackageCaption = 'Temp';
}
}
const cpuKeys = bINTEL ? cpuKeysI : cpuKeysA;
const cpuItemPrefix = bINTEL ? INTELPackagePrefix : AMDPackagePrefix;
const cpuTempCaption = bINTEL ? INTELPackageCaption : AMDPackageCaption;
const formatTemp = bINTEL ? '0' : '0.0';
const cpuCount = cpuKeys.length;
let temps = [];
cpuKeys.forEach((cpuKey, cpuIndex) => {
let cpuTemps = [];
const items = objValue[cpuKey];
const itemKeys = Object.keys(items).filter(item => { return String(item).includes(cpuItemPrefix); });
itemKeys.forEach((coreKey) => {
try {
let tempVal = NaN, tempMax = NaN, tempCrit = NaN;
Object.keys(items[coreKey]).forEach((secondLevelKey) => {
if (secondLevelKey.endsWith('_input')) {
tempVal = cpuTempHelper.getTemp(parseFloat(items[coreKey][secondLevelKey]));
} else if (secondLevelKey.endsWith('_max')) {
tempMax = cpuTempHelper.getTemp(parseFloat(items[coreKey][secondLevelKey]));
} else if (secondLevelKey.endsWith('_crit')) {
tempCrit = cpuTempHelper.getTemp(parseFloat(items[coreKey][secondLevelKey]));
}
});
if (!isNaN(tempVal)) {
let tempStyle = '';
if (!isNaN(tempMax) && tempVal >= tempMax) {
tempStyle = 'color: #FFC300; font-weight: bold;';
}
if (!isNaN(tempCrit) && tempVal >= tempCrit) {
tempStyle = 'color: red; font-weight: bold;';
}
let tempStr = '';
let tempIndex = coreKey.match(/(?:P\s+Core|E\s+Core|Core)\s*(\d+)/);
if (tempIndex !== null && tempIndex.length > 1) {
tempIndex = tempIndex[1];
let coreType = coreKey.startsWith('P Core') ? 'P Core' :
coreKey.startsWith('E Core') ? 'E Core' :
cpuTempCaption;
tempStr = `${coreType}&nbsp;${tempIndex}:&nbsp;<span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`;
} else {
// fallback for CPUs which do not have a core index
let coreType = coreKey.startsWith('P Core') ? 'P Core' :
coreKey.startsWith('E Core') ? 'E Core' :
cpuTempCaption;
tempStr = `${coreType}:&nbsp;<span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`;
}
cpuTemps.push(tempStr);
}
} catch (e) { /*_*/ }
}); });
if(cpuTemps.length > 0) { return '<div style="text-align: left; margin-left: 28px;">' + (result.length > 0 ? result : 'N/A') + '</div>';
temps.push(cpuTemps); }
} },
});
let result = '';
temps.forEach((cpuTemps, cpuIndex) => {
const strCoreTemps = cpuTemps.map((strTemp, index, arr) => { return strTemp + (index + 1 < arr.length ? (itemsPerRow > 0 && (index + 1) % itemsPerRow === 0 ? '<br>' : '&nbsp;| ') : ''); })
if(strCoreTemps.length > 0) {
result += (cpuCount > 1 ? `CPU ${cpuIndex+1}: ` : '') + strCoreTemps.join('') + (cpuIndex < cpuCount ? '<br>' : '');
}
});
return '<div style="text-align: left; margin-left: 28px;">' + (result.length > 0 ? result : 'N/A') + '</div>';
}
},
EOF EOF
)
#endregion cpu widget heredoc #endregion cpu widget heredoc
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "Error: Failed to generate cpu widget code" >&2 echo "Error: Failed to generate cpu widget code" >&2
@ -853,7 +857,10 @@ EOF
# Function to generate UPS widget # Function to generate UPS widget
generate_nvme_widget() { generate_nvme_widget() {
#region nvme widget heredoc #region nvme widget heredoc
cat > "$1" <<'EOF' # use subshell to allow variable expansion
(
export HELPERCTORPARAMS
cat <<'EOF' | envsubst > "$1"
{ {
itemId: 'thermalNvme', itemId: 'thermalNvme',
colspan: 2, colspan: 2,
@ -865,7 +872,7 @@ generate_nvme_widget() {
// sensors configuration // sensors configuration
const addressPrefix = "nvme-pci-"; const addressPrefix = "nvme-pci-";
const sensorName = "Composite"; const sensorName = "Composite";
const tempHelper = Ext.create('PVE.mod.TempHelper', $tempHelperCtorParams); const tempHelper = Ext.create('PVE.mod.TempHelper', $HELPERCTORPARAMS);
// display configuration // display configuration
const itemsPerRow = ${NVME_ITEMS_PER_ROW}; const itemsPerRow = ${NVME_ITEMS_PER_ROW};
// --- // ---
@ -907,6 +914,7 @@ generate_nvme_widget() {
} }
}, },
EOF EOF
)
#endregion nvme widget heredoc #endregion nvme widget heredoc
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "Error: Failed to generate nvme widget code" >&2 echo "Error: Failed to generate nvme widget code" >&2
@ -991,7 +999,10 @@ EOF
# Function to generate UPS widget # Function to generate UPS widget
generate_hdd_widget() { generate_hdd_widget() {
#region hdd widget heredoc #region hdd widget heredoc
cat > "$1" <<'EOF' # use subshell to allow variable expansion
(
export HELPERCTORPARAMS
cat <<'EOF' | envsubst > "$1"
{ {
itemId: 'thermalHdd', itemId: 'thermalHdd',
colspan: 2, colspan: 2,
@ -1003,7 +1014,7 @@ generate_hdd_widget() {
// sensors configuration // sensors configuration
const addressPrefix = "drivetemp-scsi-"; const addressPrefix = "drivetemp-scsi-";
const sensorName = "temp1"; const sensorName = "temp1";
const tempHelper = Ext.create('PVE.mod.TempHelper', $tempHelperCtorParams); const tempHelper = Ext.create('PVE.mod.TempHelper', $HELPERCTORPARAMS);
// display configuration // display configuration
const itemsPerRow = ${HDD_ITEMS_PER_ROW}; const itemsPerRow = ${HDD_ITEMS_PER_ROW};
// --- // ---
@ -1045,6 +1056,7 @@ generate_hdd_widget() {
} }
}, },
EOF EOF
)
#endregion hdd widget heredoc #endregion hdd widget heredoc
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "Error: Failed to generate hhd widget code" >&2 echo "Error: Failed to generate hhd widget code" >&2
@ -1055,7 +1067,11 @@ EOF
# Function to generate RAM widget # Function to generate RAM widget
generate_ram_widget() { generate_ram_widget() {
#region ram widget heredoc #region ram widget heredoc
cat > "$1" <<'EOF' # use subshell to allow variable expansion
(
export HELPERCTORPARAMS
cat <<'EOF' | envsubst > "$1"
{
{ {
xtype: 'box', xtype: 'box',
colspan: 2, colspan: 2,
@ -1069,7 +1085,7 @@ generate_ram_widget() {
iconCls: 'fa fa-fw fa-thermometer-half', iconCls: 'fa fa-fw fa-thermometer-half',
textField: 'sensorsOutput', textField: 'sensorsOutput',
renderer: function(value) { renderer: function(value) {
const cpuTempHelper = Ext.create('PVE.mod.TempHelper', {srcUnit: PVE.mod.TempHelper.CELSIUS, dstUnit: PVE.mod.TempHelper.CELSIUS}); const cpuTempHelper = Ext.create('PVE.mod.TempHelper', $HELPERCTORPARAMS);
// Make SODIMM unique keys // Make SODIMM unique keys
value = value.split('\n'); // Split by newlines value = value.split('\n'); // Split by newlines
for (let i = 0; i < value.length; i++) { for (let i = 0; i < value.length; i++) {
@ -1134,6 +1150,7 @@ generate_ram_widget() {
} }
}, },
EOF EOF
)
#endregion ram widget heredoc #endregion ram widget heredoc
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "Error: Failed to generate ram widget code" >&2 echo "Error: Failed to generate ram widget code" >&2