first
This commit is contained in:
parent
4d75d471fe
commit
d52f4b0fac
@ -775,118 +775,146 @@ 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 = 'Chiplet';
|
||||||
if (cpuKeysA.length > 0) {
|
|
||||||
let bTccd = false;
|
if (cpuKeysA.length > 0) {
|
||||||
let bTctl = false;
|
let bTccd = false;
|
||||||
let bTdie = false;
|
let bTctl = false;
|
||||||
cpuKeysA.forEach((cpuKey, cpuIndex) => {
|
let bTdie = 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') {
|
if (bTccd && bTctl && '$CPU_TEMP_TARGET' == 'Core') {
|
||||||
AMDPackagePrefix = 'Tccd';
|
AMDPackagePrefix = 'Tccd';
|
||||||
AMDPackageCaption = 'Chiplet';
|
AMDPackageCaption = 'Ccd';
|
||||||
} else if (bTdie) {
|
} else if (bTdie) {
|
||||||
AMDPackagePrefix = 'Tdie';
|
AMDPackagePrefix = 'Tdie';
|
||||||
AMDPackageCaption = 'Temp';
|
AMDPackageCaption = 'Die';
|
||||||
} else if (bTctl) {
|
} else if (bTctl) {
|
||||||
AMDPackagePrefix = 'Tctl';
|
AMDPackagePrefix = 'Tctl';
|
||||||
AMDPackageCaption = 'Temp';
|
AMDPackageCaption = 'Ctl';
|
||||||
} else {
|
} else {
|
||||||
AMDPackagePrefix = 'temp';
|
AMDPackagePrefix = 'temp';
|
||||||
AMDPackageCaption = 'Temp';
|
AMDPackageCaption = 'Temp';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const cpuKeys = bINTEL ? cpuKeysI : cpuKeysA;
|
|
||||||
const cpuItemPrefix = bINTEL ? INTELPackagePrefix : AMDPackagePrefix;
|
const cpuKeys = bINTEL ? cpuKeysI : cpuKeysA;
|
||||||
const cpuTempCaption = bINTEL ? INTELPackageCaption : AMDPackageCaption;
|
const cpuItemPrefix = bINTEL ? INTELPackagePrefix : AMDPackagePrefix;
|
||||||
const formatTemp = bINTEL ? '0' : '0.0';
|
const cpuTempCaption = bINTEL ? INTELPackageCaption : AMDPackageCaption;
|
||||||
const cpuCount = cpuKeys.length;
|
const formatTemp = bINTEL ? '0' : '0.0';
|
||||||
let temps = [];
|
const cpuCount = cpuKeys.length;
|
||||||
cpuKeys.forEach((cpuKey, cpuIndex) => {
|
let temps = [];
|
||||||
let cpuTemps = [];
|
|
||||||
const items = objValue[cpuKey];
|
cpuKeys.forEach((cpuKey, cpuIndex) => {
|
||||||
const itemKeys = Object.keys(items).filter(item => { return String(item).includes(cpuItemPrefix); });
|
let cpuTemps = [];
|
||||||
itemKeys.forEach((coreKey) => {
|
const items = objValue[cpuKey];
|
||||||
try {
|
const itemKeys = Object.keys(items).filter(item => {
|
||||||
let tempVal = NaN, tempMax = NaN, tempCrit = NaN;
|
return String(item).includes(cpuItemPrefix) || String(item).startsWith('Tccd');
|
||||||
Object.keys(items[coreKey]).forEach((secondLevelKey) => {
|
});
|
||||||
if (secondLevelKey.endsWith('_input')) {
|
|
||||||
tempVal = cpuTempHelper.getTemp(parseFloat(items[coreKey][secondLevelKey]));
|
itemKeys.forEach((coreKey) => {
|
||||||
} else if (secondLevelKey.endsWith('_max')) {
|
try {
|
||||||
tempMax = cpuTempHelper.getTemp(parseFloat(items[coreKey][secondLevelKey]));
|
let tempVal = NaN, tempMax = NaN, tempCrit = NaN;
|
||||||
} else if (secondLevelKey.endsWith('_crit')) {
|
Object.keys(items[coreKey]).forEach((secondLevelKey) => {
|
||||||
tempCrit = cpuTempHelper.getTemp(parseFloat(items[coreKey][secondLevelKey]));
|
if (secondLevelKey.endsWith('_input')) {
|
||||||
}
|
tempVal = cpuTempHelper.getTemp(parseFloat(items[coreKey][secondLevelKey]));
|
||||||
});
|
} else if (secondLevelKey.endsWith('_max')) {
|
||||||
if (!isNaN(tempVal)) {
|
tempMax = cpuTempHelper.getTemp(parseFloat(items[coreKey][secondLevelKey]));
|
||||||
let tempStyle = '';
|
} else if (secondLevelKey.endsWith('_crit')) {
|
||||||
if (!isNaN(tempMax) && tempVal >= tempMax) {
|
tempCrit = cpuTempHelper.getTemp(parseFloat(items[coreKey][secondLevelKey]));
|
||||||
tempStyle = 'color: #FFC300; font-weight: bold;';
|
}
|
||||||
}
|
});
|
||||||
if (!isNaN(tempCrit) && tempVal >= tempCrit) {
|
|
||||||
tempStyle = 'color: red; font-weight: bold;';
|
if (!isNaN(tempVal)) {
|
||||||
}
|
let tempStyle = '';
|
||||||
let tempStr = '';
|
if (!isNaN(tempMax) && tempVal >= tempMax) {
|
||||||
let tempIndex = coreKey.match(/(?:P\s+Core|E\s+Core|Core)\s*(\d+)/);
|
tempStyle = 'color: #FFC300; font-weight: bold;';
|
||||||
if (tempIndex !== null && tempIndex.length > 1) {
|
}
|
||||||
tempIndex = tempIndex[1];
|
if (!isNaN(tempCrit) && tempVal >= tempCrit) {
|
||||||
let coreType = coreKey.startsWith('P Core') ? 'P Core' :
|
tempStyle = 'color: red; font-weight: bold;';
|
||||||
coreKey.startsWith('E Core') ? 'E Core' :
|
}
|
||||||
cpuTempCaption;
|
|
||||||
tempStr = `${coreType} ${tempIndex}: <span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`;
|
let tempStr = '';
|
||||||
} else {
|
|
||||||
// fallback for CPUs which do not have a core index
|
// Enhanced parsing for AMD Tccd temperatures
|
||||||
let coreType = coreKey.startsWith('P Core') ? 'P Core' :
|
if (coreKey.startsWith('Tccd')) {
|
||||||
coreKey.startsWith('E Core') ? 'E Core' :
|
let tempIndex = coreKey.match(/Tccd(\d+)/);
|
||||||
cpuTempCaption;
|
if (tempIndex !== null && tempIndex.length > 1) {
|
||||||
tempStr = `${coreType}: <span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`;
|
tempIndex = tempIndex[1];
|
||||||
}
|
tempStr = `${cpuTempCaption} ${tempIndex}: <span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`;
|
||||||
cpuTemps.push(tempStr);
|
} else {
|
||||||
}
|
tempStr = `${cpuTempCaption}: <span style="${tempStyle}">${Ext.util.Format.number(tempVal, formatTemp)}${cpuTempHelper.getUnit()}</span>`;
|
||||||
} catch (e) { /*_*/ }
|
}
|
||||||
});
|
}
|
||||||
if(cpuTemps.length > 0) {
|
// Enhanced parsing for Intel cores (P-Core, E-Core, regular Core)
|
||||||
temps.push(cpuTemps);
|
else {
|
||||||
}
|
let tempIndex = coreKey.match(/(?:P\s+Core|E\s+Core|Core)\s*(\d+)/);
|
||||||
});
|
if (tempIndex !== null && tempIndex.length > 1) {
|
||||||
let result = '';
|
tempIndex = tempIndex[1];
|
||||||
temps.forEach((cpuTemps, cpuIndex) => {
|
let coreType = coreKey.startsWith('P Core') ? 'P Core' :
|
||||||
const strCoreTemps = cpuTemps.map((strTemp, index, arr) => { return strTemp + (index + 1 < arr.length ? (itemsPerRow > 0 && (index + 1) % itemsPerRow === 0 ? '<br>' : ' | ') : ''); })
|
coreKey.startsWith('E Core') ? 'E Core' :
|
||||||
if(strCoreTemps.length > 0) {
|
cpuTempCaption;
|
||||||
result += (cpuCount > 1 ? `CPU ${cpuIndex+1}: ` : '') + strCoreTemps.join('') + (cpuIndex < cpuCount ? '<br>' : '');
|
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
|
||||||
return '<div style="text-align: left; margin-left: 28px;">' + (result.length > 0 ? result : 'N/A') + '</div>';
|
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) { /*_*/ }
|
||||||
|
});
|
||||||
|
|
||||||
|
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>' : '');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user