fixes
This commit is contained in:
parent
d52f4b0fac
commit
595bd96af6
@ -144,7 +144,7 @@ function configure {
|
||||
info "Detected CPU sensors (${#cpuList[@]}): $(IFS=,; echo "${cpuList[*]}")"
|
||||
SENSORS_DETECTED=true
|
||||
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
|
||||
[cC]|"")
|
||||
CPU_TEMP_TARGET="Core"
|
||||
@ -775,146 +775,161 @@ generate_cpu_widget() {
|
||||
|
||||
cat <<'EOF' | envsubst '$CPU_ITEMS_PER_ROW $CPU_TEMP_TARGET $HELPERCTORPARAMS' > "$1"
|
||||
{
|
||||
itemId: 'thermalCpu',
|
||||
colspan: 2,
|
||||
printBar: false,
|
||||
title: gettext('CPU Thermal State'),
|
||||
iconCls: 'fa fa-fw fa-thermometer-half',
|
||||
textField: 'sensorsOutput',
|
||||
renderer: function(value){
|
||||
// sensors configuration
|
||||
itemId: 'thermalCpu',
|
||||
colspan: 2,
|
||||
printBar: false,
|
||||
title: gettext('CPU Thermal State'),
|
||||
iconCls: 'fa fa-fw fa-thermometer-half',
|
||||
textField: 'sensorsOutput',
|
||||
renderer: function(value){
|
||||
// sensors configuration
|
||||
const cpuTempHelper = Ext.create('PVE.mod.TempHelper', $HELPERCTORPARAMS);
|
||||
// display configuration
|
||||
// display configuration
|
||||
const itemsPerRow = $CPU_ITEMS_PER_ROW;
|
||||
// ---
|
||||
let objValue;
|
||||
try {
|
||||
objValue = JSON.parse(value) || {};
|
||||
} catch(e) {
|
||||
objValue = {};
|
||||
}
|
||||
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 bINTEL = cpuKeysI.length > 0 ? true : false;
|
||||
// ---
|
||||
let objValue;
|
||||
try {
|
||||
objValue = JSON.parse(value) || {};
|
||||
} catch(e) {
|
||||
objValue = {};
|
||||
}
|
||||
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 bINTEL = cpuKeysI.length > 0 ? true : false;
|
||||
const INTELPackagePrefix = '$CPU_TEMP_TARGET' == 'Core' ? 'Core ' : 'Package id';
|
||||
const INTELPackageCaption = '$CPU_TEMP_TARGET' == 'Core' ? 'Core' : 'Package';
|
||||
let AMDPackagePrefix = 'Tccd';
|
||||
let AMDPackageCaption = 'Chiplet';
|
||||
let AMDPackagePrefix = 'Tccd';
|
||||
let AMDPackageCaption = 'CCD';
|
||||
|
||||
if (cpuKeysA.length > 0) {
|
||||
let bTccd = false;
|
||||
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 = 'Ccd';
|
||||
} else if (bTdie) {
|
||||
AMDPackagePrefix = 'Tdie';
|
||||
AMDPackageCaption = 'Die';
|
||||
} else if (bTctl) {
|
||||
AMDPackagePrefix = 'Tctl';
|
||||
AMDPackageCaption = 'Ctl';
|
||||
} else {
|
||||
AMDPackagePrefix = 'temp';
|
||||
AMDPackageCaption = 'Temp';
|
||||
}
|
||||
}
|
||||
if (cpuKeysA.length > 0) {
|
||||
let bTccd = false;
|
||||
let bTctl = false;
|
||||
let bTdie = false;
|
||||
let bCpuCoreTemp = 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;
|
||||
bCpuCoreTemp = Object.keys(items).findIndex(item => { return String(item) === 'CPU Core Temp'; }) >= 0;
|
||||
});
|
||||
if (bTccd && '$CPU_TEMP_TARGET' == 'Core') {
|
||||
AMDPackagePrefix = 'Tccd';
|
||||
AMDPackageCaption = 'CCD';
|
||||
} else if (bCpuCoreTemp && '$CPU_TEMP_TARGET' == 'Package') {
|
||||
AMDPackagePrefix = 'CPU Core Temp';
|
||||
AMDPackageCaption = 'CPU';
|
||||
} else if (bTdie) {
|
||||
AMDPackagePrefix = 'Tdie';
|
||||
AMDPackageCaption = 'Die';
|
||||
} else if (bTctl) {
|
||||
AMDPackagePrefix = 'Tctl';
|
||||
AMDPackageCaption = 'Die';
|
||||
} 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 = [];
|
||||
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) || String(item).startsWith('Tccd');
|
||||
});
|
||||
cpuKeys.forEach((cpuKey, cpuIndex) => {
|
||||
let cpuTemps = [];
|
||||
const items = objValue[cpuKey];
|
||||
const itemKeys = Object.keys(items).filter(item => {
|
||||
if ('$CPU_TEMP_TARGET' == 'Core') {
|
||||
// In Core mode: only show individual cores/CCDs, exclude overall CPU temp
|
||||
return String(item).includes(cpuItemPrefix) || String(item).startsWith('Tccd');
|
||||
} else {
|
||||
// In Package mode: show overall CPU temp and package-level readings
|
||||
return String(item).includes(cpuItemPrefix) || String(item) === 'CPU Core Temp';
|
||||
}
|
||||
});
|
||||
|
||||
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]));
|
||||
}
|
||||
});
|
||||
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;';
|
||||
}
|
||||
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 tempStr = '';
|
||||
|
||||
// Enhanced parsing for AMD Tccd temperatures
|
||||
if (coreKey.startsWith('Tccd')) {
|
||||
let tempIndex = coreKey.match(/Tccd(\d+)/);
|
||||
if (tempIndex !== null && tempIndex.length > 1) {
|
||||
tempIndex = tempIndex[1];
|
||||
tempStr = `${cpuTempCaption} ${tempIndex}: <span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`;
|
||||
} else {
|
||||
tempStr = `${cpuTempCaption}: <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+)/);
|
||||
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} ${tempIndex}: <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}: <span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`;
|
||||
}
|
||||
}
|
||||
// Enhanced parsing for AMD temperatures
|
||||
if (coreKey.startsWith('Tccd')) {
|
||||
let tempIndex = coreKey.match(/Tccd(\d+)/);
|
||||
if (tempIndex !== null && tempIndex.length > 1) {
|
||||
tempIndex = tempIndex[1];
|
||||
tempStr = `${cpuTempCaption} ${tempIndex}: <span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`;
|
||||
} else {
|
||||
tempStr = `${cpuTempCaption}: <span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`;
|
||||
}
|
||||
}
|
||||
// Handle CPU Core Temp (single overall temperature)
|
||||
else if (coreKey === 'CPU Core Temp') {
|
||||
tempStr = `${cpuTempCaption}: <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+)/);
|
||||
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} ${tempIndex}: <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}: <span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`;
|
||||
}
|
||||
}
|
||||
|
||||
cpuTemps.push(tempStr);
|
||||
}
|
||||
} catch (e) { /*_*/ }
|
||||
});
|
||||
cpuTemps.push(tempStr);
|
||||
}
|
||||
} catch (e) { /*_*/ }
|
||||
});
|
||||
|
||||
if(cpuTemps.length > 0) {
|
||||
temps.push(cpuTemps);
|
||||
}
|
||||
});
|
||||
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>' : ' | ') : '');
|
||||
})
|
||||
if(strCoreTemps.length > 0) {
|
||||
result += (cpuCount > 1 ? `CPU ${cpuIndex+1}: ` : '') + strCoreTemps.join('') + (cpuIndex < cpuCount ? '<br>' : '');
|
||||
}
|
||||
});
|
||||
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>' : ' | ') : '');
|
||||
})
|
||||
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>';
|
||||
}
|
||||
},
|
||||
return '<div style="text-align: left; margin-left: 28px;">' + (result.length > 0 ? result : 'N/A') + '</div>';
|
||||
}
|
||||
},
|
||||
EOF
|
||||
)
|
||||
#endregion cpu widget heredoc
|
||||
|
||||
Loading…
Reference in New Issue
Block a user