This commit is contained in:
Meliox 2025-09-07 00:22:46 +02:00
parent d52f4b0fac
commit 595bd96af6

View File

@ -144,7 +144,7 @@ function configure {
info "Detected CPU sensors (${#cpuList[@]}): $(IFS=,; echo "${cpuList[*]}")" info "Detected CPU sensors (${#cpuList[@]}): $(IFS=,; echo "${cpuList[*]}")"
SENSORS_DETECTED=true SENSORS_DETECTED=true
while true; do while true; do
local choice=$(ask "Display temperatures for all cores [C] or average per CPU [a] (AMD only supports average)? (C/a)") local choice=$(ask "Display temperatures for all cores [C] or average per CPU [a] (some newer AMD variants support per die)? (C/a)")
case "$choice" in case "$choice" in
[cC]|"") [cC]|"")
CPU_TEMP_TARGET="Core" CPU_TEMP_TARGET="Core"
@ -775,146 +775,161 @@ generate_cpu_widget() {
cat <<'EOF' | envsubst '$CPU_ITEMS_PER_ROW $CPU_TEMP_TARGET $HELPERCTORPARAMS' > "$1" cat <<'EOF' | envsubst '$CPU_ITEMS_PER_ROW $CPU_TEMP_TARGET $HELPERCTORPARAMS' > "$1"
{ {
itemId: 'thermalCpu', itemId: 'thermalCpu',
colspan: 2, colspan: 2,
printBar: false, printBar: false,
title: gettext('CPU Thermal State'), title: gettext('CPU Thermal State'),
iconCls: 'fa fa-fw fa-thermometer-half', iconCls: 'fa fa-fw fa-thermometer-half',
textField: 'sensorsOutput', textField: 'sensorsOutput',
renderer: function(value){ renderer: function(value){
// sensors configuration // sensors configuration
const cpuTempHelper = Ext.create('PVE.mod.TempHelper', $HELPERCTORPARAMS); const cpuTempHelper = Ext.create('PVE.mod.TempHelper', $HELPERCTORPARAMS);
// display configuration // display configuration
const itemsPerRow = $CPU_ITEMS_PER_ROW; const itemsPerRow = $CPU_ITEMS_PER_ROW;
// --- // ---
let objValue; let objValue;
try { try {
objValue = JSON.parse(value) || {}; objValue = JSON.parse(value) || {};
} catch(e) { } catch(e) {
objValue = {}; objValue = {};
} }
const cpuKeysI = Object.keys(objValue).filter(item => String(item).startsWith('coretemp-isa-')).sort(); const cpuKeysI = Object.keys(objValue).filter(item => String(item).startsWith('coretemp-isa-')).sort();
const cpuKeysA = Object.keys(objValue).filter(item => String(item).startsWith('k10temp-pci-')).sort(); const cpuKeysA = Object.keys(objValue).filter(item => String(item).startsWith('k10temp-pci-')).sort();
const bINTEL = cpuKeysI.length > 0 ? true : false; const bINTEL = cpuKeysI.length > 0 ? true : false;
const INTELPackagePrefix = '$CPU_TEMP_TARGET' == 'Core' ? 'Core ' : 'Package id'; const INTELPackagePrefix = '$CPU_TEMP_TARGET' == 'Core' ? 'Core ' : 'Package id';
const INTELPackageCaption = '$CPU_TEMP_TARGET' == 'Core' ? 'Core' : 'Package'; const INTELPackageCaption = '$CPU_TEMP_TARGET' == 'Core' ? 'Core' : 'Package';
let AMDPackagePrefix = 'Tccd'; let AMDPackagePrefix = 'Tccd';
let AMDPackageCaption = 'Chiplet'; let AMDPackageCaption = 'CCD';
if (cpuKeysA.length > 0) { if (cpuKeysA.length > 0) {
let bTccd = false; let bTccd = false;
let bTctl = false; let bTctl = false;
let bTdie = false; let bTdie = false;
cpuKeysA.forEach((cpuKey, cpuIndex) => { let bCpuCoreTemp = false;
let items = objValue[cpuKey]; cpuKeysA.forEach((cpuKey, cpuIndex) => {
bTccd = Object.keys(items).findIndex(item => { return String(item).startsWith('Tccd'); }) >= 0; let items = objValue[cpuKey];
bTctl = Object.keys(items).findIndex(item => { return String(item).startsWith('Tctl'); }) >= 0; bTccd = Object.keys(items).findIndex(item => { return String(item).startsWith('Tccd'); }) >= 0;
bTdie = Object.keys(items).findIndex(item => { return String(item).startsWith('Tdie'); }) >= 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') { bCpuCoreTemp = Object.keys(items).findIndex(item => { return String(item) === 'CPU Core Temp'; }) >= 0;
AMDPackagePrefix = 'Tccd'; });
AMDPackageCaption = 'Ccd'; if (bTccd && '$CPU_TEMP_TARGET' == 'Core') {
} else if (bTdie) { AMDPackagePrefix = 'Tccd';
AMDPackagePrefix = 'Tdie'; AMDPackageCaption = 'CCD';
AMDPackageCaption = 'Die'; } else if (bCpuCoreTemp && '$CPU_TEMP_TARGET' == 'Package') {
} else if (bTctl) { AMDPackagePrefix = 'CPU Core Temp';
AMDPackagePrefix = 'Tctl'; AMDPackageCaption = 'CPU';
AMDPackageCaption = 'Ctl'; } else if (bTdie) {
} else { AMDPackagePrefix = 'Tdie';
AMDPackagePrefix = 'temp'; AMDPackageCaption = 'Die';
AMDPackageCaption = 'Temp'; } else if (bTctl) {
} AMDPackagePrefix = 'Tctl';
} AMDPackageCaption = 'Die';
} else {
const cpuKeys = bINTEL ? cpuKeysI : cpuKeysA; AMDPackagePrefix = 'temp';
const cpuItemPrefix = bINTEL ? INTELPackagePrefix : AMDPackagePrefix; AMDPackageCaption = 'Temp';
const cpuTempCaption = bINTEL ? INTELPackageCaption : AMDPackageCaption; }
const formatTemp = bINTEL ? '0' : '0.0'; }
const cpuCount = cpuKeys.length;
let temps = []; const cpuKeys = bINTEL ? cpuKeysI : cpuKeysA;
const cpuItemPrefix = bINTEL ? INTELPackagePrefix : AMDPackagePrefix;
cpuKeys.forEach((cpuKey, cpuIndex) => { const cpuTempCaption = bINTEL ? INTELPackageCaption : AMDPackageCaption;
let cpuTemps = []; const formatTemp = bINTEL ? '0' : '0.0';
const items = objValue[cpuKey]; const cpuCount = cpuKeys.length;
const itemKeys = Object.keys(items).filter(item => { let temps = [];
return String(item).includes(cpuItemPrefix) || String(item).startsWith('Tccd');
}); cpuKeys.forEach((cpuKey, cpuIndex) => {
let cpuTemps = [];
itemKeys.forEach((coreKey) => { const items = objValue[cpuKey];
try { const itemKeys = Object.keys(items).filter(item => {
let tempVal = NaN, tempMax = NaN, tempCrit = NaN; if ('$CPU_TEMP_TARGET' == 'Core') {
Object.keys(items[coreKey]).forEach((secondLevelKey) => { // In Core mode: only show individual cores/CCDs, exclude overall CPU temp
if (secondLevelKey.endsWith('_input')) { return String(item).includes(cpuItemPrefix) || String(item).startsWith('Tccd');
tempVal = cpuTempHelper.getTemp(parseFloat(items[coreKey][secondLevelKey])); } else {
} else if (secondLevelKey.endsWith('_max')) { // In Package mode: show overall CPU temp and package-level readings
tempMax = cpuTempHelper.getTemp(parseFloat(items[coreKey][secondLevelKey])); return String(item).includes(cpuItemPrefix) || String(item) === 'CPU Core Temp';
} else if (secondLevelKey.endsWith('_crit')) { }
tempCrit = cpuTempHelper.getTemp(parseFloat(items[coreKey][secondLevelKey])); });
}
}); itemKeys.forEach((coreKey) => {
try {
if (!isNaN(tempVal)) { let tempVal = NaN, tempMax = NaN, tempCrit = NaN;
let tempStyle = ''; Object.keys(items[coreKey]).forEach((secondLevelKey) => {
if (!isNaN(tempMax) && tempVal >= tempMax) { if (secondLevelKey.endsWith('_input')) {
tempStyle = 'color: #FFC300; font-weight: bold;'; tempVal = cpuTempHelper.getTemp(parseFloat(items[coreKey][secondLevelKey]));
} } else if (secondLevelKey.endsWith('_max')) {
if (!isNaN(tempCrit) && tempVal >= tempCrit) { tempMax = cpuTempHelper.getTemp(parseFloat(items[coreKey][secondLevelKey]));
tempStyle = 'color: red; font-weight: bold;'; } else if (secondLevelKey.endsWith('_crit')) {
} tempCrit = cpuTempHelper.getTemp(parseFloat(items[coreKey][secondLevelKey]));
}
let tempStr = ''; });
// Enhanced parsing for AMD Tccd temperatures if (!isNaN(tempVal)) {
if (coreKey.startsWith('Tccd')) { let tempStyle = '';
let tempIndex = coreKey.match(/Tccd(\d+)/); if (!isNaN(tempMax) && tempVal >= tempMax) {
if (tempIndex !== null && tempIndex.length > 1) { tempStyle = 'color: #FFC300; font-weight: bold;';
tempIndex = tempIndex[1]; }
tempStr = `${cpuTempCaption}&nbsp;${tempIndex}:&nbsp;<span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`; if (!isNaN(tempCrit) && tempVal >= tempCrit) {
} else { tempStyle = 'color: red; font-weight: bold;';
tempStr = `${cpuTempCaption}:&nbsp;<span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`; }
}
} let tempStr = '';
// Enhanced parsing for Intel cores (P-Core, E-Core, regular Core)
else { // Enhanced parsing for AMD temperatures
let tempIndex = coreKey.match(/(?:P\s+Core|E\s+Core|Core)\s*(\d+)/); if (coreKey.startsWith('Tccd')) {
if (tempIndex !== null && tempIndex.length > 1) { let tempIndex = coreKey.match(/Tccd(\d+)/);
tempIndex = tempIndex[1]; if (tempIndex !== null && tempIndex.length > 1) {
let coreType = coreKey.startsWith('P Core') ? 'P Core' : tempIndex = tempIndex[1];
coreKey.startsWith('E Core') ? 'E Core' : tempStr = `${cpuTempCaption}&nbsp;${tempIndex}:&nbsp;<span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`;
cpuTempCaption; } else {
tempStr = `${coreType}&nbsp;${tempIndex}:&nbsp;<span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`; tempStr = `${cpuTempCaption}:&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' : // Handle CPU Core Temp (single overall temperature)
coreKey.startsWith('E Core') ? 'E Core' : else if (coreKey === 'CPU Core Temp') {
cpuTempCaption; tempStr = `${cpuTempCaption}:&nbsp;<span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`;
tempStr = `${coreType}:&nbsp;<span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`; }
} // Enhanced parsing for Intel cores (P-Core, E-Core, regular Core)
} else {
let tempIndex = coreKey.match(/(?:P\s+Core|E\s+Core|Core)\s*(\d+)/);
cpuTemps.push(tempStr); if (tempIndex !== null && tempIndex.length > 1) {
} tempIndex = tempIndex[1];
} catch (e) { /*_*/ } let coreType = coreKey.startsWith('P Core') ? 'P Core' :
}); coreKey.startsWith('E Core') ? 'E Core' :
cpuTempCaption;
if(cpuTemps.length > 0) { tempStr = `${coreType}&nbsp;${tempIndex}:&nbsp;<span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`;
temps.push(cpuTemps); } 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' :
let result = ''; cpuTempCaption;
temps.forEach((cpuTemps, cpuIndex) => { tempStr = `${coreType}:&nbsp;<span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`;
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) { cpuTemps.push(tempStr);
result += (cpuCount > 1 ? `CPU ${cpuIndex+1}: ` : '') + strCoreTemps.join('') + (cpuIndex < cpuCount ? '<br>' : ''); }
} } catch (e) { /*_*/ }
}); });
return '<div style="text-align: left; margin-left: 28px;">' + (result.length > 0 ? result : 'N/A') + '</div>'; if(cpuTemps.length > 0) {
} 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