From 34075feb96356d9f9bc05d406c75243a238d4d21 Mon Sep 17 00:00:00 2001 From: Meliox Date: Mon, 6 Jan 2025 14:38:56 +0100 Subject: [PATCH] first --- pve-mod-gui-sensors.sh | 103 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-) diff --git a/pve-mod-gui-sensors.sh b/pve-mod-gui-sensors.sh index 58745d2..36610de 100644 --- a/pve-mod-gui-sensors.sh +++ b/pve-mod-gui-sensors.sh @@ -188,6 +188,18 @@ function configure { SENSORS_DETECTED=true fi + # Look for ram temps + msg "\nDetecting support for Ram temperature sensors..." + if (echo "$sensorsOutput" | grep -q '"SODIMM":'); then + msg "Detected Ram temperature sensors:\n$(echo "$sensorsOutput" | grep -o '"SODIMM[^"]*"' | sed 's/"//g')" + ENABLE_RAM_TEMP=true + SENSORS_DETECTED=true + + else + warn "No Ram temperature sensors found." + ENABLE_RAM_TEMP=false + fi + # Check if HDD/SSD data is installed msg "\nDetecting support for HDD/SDD temperature sensors..." if (lsmod | grep -wq "drivetemp"); then @@ -746,6 +758,95 @@ Ext.define('PVE.mod.TempHelper', {\n\ }" "$PVE_MANAGER_LIB_JS_FILE" fi + if [ $ENABLE_RAM_TEMP = true ]; then + # Add Ram temperature display + sed -i "/^Ext.define('PVE.node.StatusView',/ { + :a; + /items:/!{N;ba;} + :b; + /'thermal.*},/!{N;bb;} + a\ + \\ + {\n\ + xtype: 'box',\n\ + colspan: 2,\n\ + html: gettext('Cooling'),\n\ + },\n\ + {\n\ + itemId: 'thermalMemory',\n\ + colspan: 2,\n\ + printBar: false,\n\ + title: gettext('Memory Thermal State'),\n\ + iconCls: 'fa fa-fw fa-thermometer-half',\n\ + textField: 'sensorsOutput',\n\ + renderer: function(value) {\n\ + const cpuTempHelper = Ext.create('PVE.mod.TempHelper', {srcUnit: PVE.mod.TempHelper.CELSIUS, dstUnit: PVE.mod.TempHelper.CELSIUS});\n\ + // Make SODIMM unique keys\n\ + value = value.split('\\\n'); // Split by newlines\n\ + for (let i = 0; i < value.length; i++) {\n\ + // Check if the current line contains 'SODIMM'\n\ + if (value[i].includes('SODIMM') && i + 1 < value.length) {\n\ + // Extract the number '3' following 'temp' from the next line (e.g., "temp3_input": 25.000)\n\ + let nextLine = value[i + 1];\n\ + let match = nextLine.match(/\"temp(\\\d+)_input\": (\\\d+\\\.\\\d+)/);\n\ +\n\ + if (match) {\n\ + let number = match[1]; // Extracted number\n\ + // Replace the current line with SODIMM by the extracted number\n\ + value[i] = value[i].replace('SODIMM', \`SODIMM\${number}\`);\n\ + }\n\ + }\n\ + }\n\ + value = value.join('\\\n'); // Reverse line split\n\ +\n\ + let objValue;\n\ + try {\n\ + objValue = JSON.parse(value) || {};\n\ + } catch(e) {\n\ + objValue = {};\n\ + }\n\ +\n\ + // Recursive function to find Ram keys and values\n\ + function findMemoryKeys(obj, memoryKeys, parentKey = null) {\n\ + Object.keys(obj).forEach(key => {\n\ + const value = obj[key];\n\ + if (typeof value === 'object' && value !== null) {\n\ + // If the value is an object, recursively call the function\n\ + findMemoryKeys(value, memoryKeys, key);\n\ + } else if (/^temp\\\d+_input$/.test(key) && parentKey && parentKey.startsWith(\"SODIMM\")) {\n\ + if (value !== 0) {\n\ + memoryKeys.push({ key: parentKey, value: value});\n\ + }\n\ + }\n\ + });\n\ + }\n\ +\n\ + let memoryTemps = [];\n\ + // Loop through the parent keys\n\ + Object.keys(objValue).forEach(parentKey => {\n\ + const parentObj = objValue[parentKey];\n\ + // Array to store memory keys and values\n\ + const memoryKeys = [];\n\ + // Call the recursive function to find memory keys and values\n\ + findMemoryKeys(parentObj, memoryKeys);\n\ + // Sort the memoryKeys keys\n\ + memoryKeys.sort();\n\ + // Process each memory key and value\n\ + memoryKeys.forEach(({ key: memoryKey, value: memoryTemp }) => {\n\ + try {\n\ + memory = memoryKey.replace('SODIMM', 'SODIMM ');\n\ + memoryTemps.push(\`\${memory}: \${memoryTemp}\${cpuTempHelper.getUnit()}\`);\n\ + } catch(e) {\n\ + console.error(\`Error retrieving Memory Temp for \${memoryTemps} in \${parentKey}:\`, e); // Debug: Log specific error\n\ + }\n\ + });\n\ + });\n\ + return '
' + (memoryTemps.length > 0 ? memoryTemps.join(' | ') : 'N/A') + '
';\n\ + }\n\ + }, + }" "$PVE_MANAGER_LIB_JS_FILE" + fi + # Add an empty line to separate modified items as a visual group # NOTE: Check for the presence of items in the reverse order of display local lastItemId="" @@ -913,4 +1014,4 @@ done # If no arguments were provided or all arguments have been processed, print the usage message if [[ $executed -eq 0 ]]; then usage -fi +fi \ No newline at end of file