Facebook
From Pedro Ponte, 4 Months ago, written in LaTeX.
Embed
Download Paste or View Raw
Hits: 115
  1. # Temp sensors
  2.  
  3. # **Displaying CPU Temperature in Proxmox Summery in Real Time**
  4.  
  5. [Tutorial](https://www.reddit.com/r/homelab/comments/rhq56e/displaying_cpu_temperature_in_proxmox_summery_in/?rdt=45894)
  6.  
  7. **Here is an image of how it will look:**
  8.  
  9. ![](/files/0194db24-6a31-70f9-aa13-bed490fea3ed/Screenshot_2025-02-06_at_12.02.54.png)
  10.  
  11. Edit: You may have to add more Cores in the code below, depending on how many cores your systems has. Always start with 0.
  12.  
  13. This tutorial is a bit old now and If you are running this on a future version of proxmox that doesn’t support this code, you could try the following to roll back your manager as pointed by some in the comments ([u/RemarkableSteak](https://www.reddit.com/user/RemarkableSteak/)): apt install --reinstall pve-manager proxmox-widget-toolkit libjs-extjs
  14.  
  15. # 1) Lets install lm-sensors to show us the information we need. Type the following in the proxmox shell
  16.  
  17. ```
  18.     apt-get install lm-sensors
  19. ```
  20.  
  21. Next we can check if its working. To do this we can type `sensors`
  22.  
  23. The main part we are interested in is:
  24.  
  25. ```
  26.  root@pve:~# sensors
  27.  
  28.  coretemp-isa-0000
  29.  Adapter: ISA adapter
  30.  Package id 0:  +23.0°C  (high = +84.0°C, crit = +100.0°C)
  31.  Core 0:        +21.0°C  (high = +84.0°C, crit = +100.0°C)
  32.  Core 1:        +21.0°C  (high = +84.0°C, crit = +100.0°C)
  33.  Core 2:        +22.0°C  (high = +84.0°C, crit = +100.0°C)
  34.  Core 3:        +19.0°C  (high = +84.0°C, crit = +100.0°C)
  35. ```
  36.  
  37. If you see this you are good to go!
  38.  
  39. # 2) Adding the output of sensors to information
  40.  
  41. Here we will use `Nano` to edit some files. In your shell, type the following:
  42.  
  43. ```
  44.     nano /usr/share/perl5/PVE/API2/Nodes.pm
  45. ```
  46.  
  47. Next, you can press **F6** to search for `my $dinfo` and press **Enter**
  48.  
  49. The code should look like this:
  50.  
  51. ```
  52.         $res->{pveversion} = PVE::pvecfg::package() . "/" .
  53.             PVE::pvecfg::version_text();
  54.  
  55.         my $dinfo = df('/', 1);     # output is bytes
  56. ```
  57. We are going to add the following line of code in between: `$res->{thermalstate} = \sensors\;`
  58.  
  59. So the final result should look like this:
  60.  
  61. ```
  62.        $res->{pveversion} = PVE::pvecfg::package() . "/" .
  63.            PVE::pvecfg::version_text();
  64.        $res->{thermalstate} = `sensors -j`;
  65.  
  66.        my $dinfo = df('/', 1);     # output is bytes
  67. ```
  68. Now press **Ctrl+O** to save and **Ctrl+X** to exit.
  69. # 3) Making space for the new information
  70. Next we will need to edit another file, So once again we will use `Nano`
  71. Type the following command into your shell: `nano /usr/share/pve-manager/js/pvemanagerlib.js`
  72. Ok so you know the drill by now press **F6** to search for `wait` and press **Enter**
  73. You will see a section of code like this:
  74. ```
  75.         {
  76.          itemId: 'wait',
  77.          iconCls: 'fa fa-fw fa-clock-o',
  78.          title: gettext('IO delay'),
  79.          valueField: 'wait',
  80.           rowspan: 2,
  81.         },
  82. ```
  83. Ok now we need to add some code after this part. The code is:
  84. ```
  85.        {
  86.           itemId: 'thermal',
  87.           colspan: 2,
  88.           printBar: false,
  89.           iconCls: 'fa fa-fw fa-thermometer-half',
  90.          title: gettext('Temperature ºC'),
  91.           textField: 'thermalstate',
  92.           renderer: function(value) {
  93.            const cpu_temp_arr = JSON.parse(value);
  94.            const sections = [];
  95.            const deviceCount = {}; // Contador para dispositivos repetidos
  96.            for (const [dev, arr] of Object.entries(cpu_temp_arr)) {
  97.              const temp_arr = [];
  98.              for (const [name, temps] of Object.entries(arr)) {
  99.                if (name === 'Adapter') continue;
  100.                for (const [tempName, temp] of Object.entries(temps)) {
  101.                  if (tempName.includes("_input")) {
  102.                    temp_arr.push(parseFloat(temp).toFixed(2) + "°C"); // Formata temperatura
  103.                  }
  104.                }
  105.              }
  106.              if (temp_arr.length > 0) {
  107.                // Adiciona índice para dispositivos repetidos
  108.                const baseName = dev.split('-')[0]; // Remove possíveis sufixos indesejados
  109.                if (!deviceCount[baseName]) {
  110.                  deviceCount[baseName] = 1;
  111.                } else {
  112.                  deviceCount[baseName]++;
  113.                }
  114.                const uniqueName = deviceCount[baseName] > 1 ? `${baseName}-${deviceCount[baseName]}` : baseName;
  115.                sections.push(`<b>${uniqueName}</b>: ${temp_arr.join(" | ")}`);
  116.              }
  117.            }
  118.            return sections.join(" "); // Usa quebras de linha para melhor legibilidade
  119.           }
  120.         },
  121. ```
  122. Therefore your final result should look something like this:
  123. ```
  124.        {
  125.          itemId: 'wait',
  126.          iconCls: 'fa fa-fw fa-clock-o',
  127.          title: gettext('IO delay'),
  128.          valueField: 'wait',
  129.          //commented to add room for cpu temp. Added by PEdro Ponte
  130.           //rowspan: 2,
  131.         },
  132.         {
  133.           itemId: 'thermal',
  134.           colspan: 2,
  135.           printBar: false,
  136.           title: gettext('Thermal State(℃)'),
  137.           textField: 'thermalstate',
  138.           renderer: function(value) {
  139.            const cpu_temp_arr = JSON.parse(value);
  140.            const sections = [];
  141.            const deviceCount = {}; // Contador para dispositivos repetidos
  142.            for (const [dev, arr] of Object.entries(cpu_temp_arr)) {
  143.              const temp_arr = [];
  144.              for (const [name, temps] of Object.entries(arr)) {
  145.                if (name === 'Adapter') continue;
  146.                for (const [tempName, temp] of Object.entries(temps)) {
  147.                  if (tempName.includes("_input")) {
  148.                    temp_arr.push(parseFloat(temp).toFixed(2) + "°C"); // Formata temperatura
  149.                  }
  150.                }
  151.              }
  152.              if (temp_arr.length > 0) {
  153.                // Adiciona índice para dispositivos repetidos
  154.                const baseName = dev.split('-')[0]; // Remove possíveis sufixos indesejados
  155.                if (!deviceCount[baseName]) {
  156.                  deviceCount[baseName] = 1;
  157.                } else {
  158.                  deviceCount[baseName]++;
  159.                }
  160.                const uniqueName = deviceCount[baseName] > 1 ? `${baseName}-${deviceCount[baseName]}` : baseName;
  161.                sections.push(`<b>${uniqueName}</b>: ${temp_arr.join(" | ")}`);
  162.              }
  163.            }
  164.  
  165.            return sections.join(" "); // Usa quebras de linha para melhor legibilidade
  166.           }
  167.         },
  168. ```
  169.  
  170. Now we can finally press **Ctrl+O** to save and **Ctrl+X** to exit.
  171.  
  172. # 3)Restart the summary page
  173.  
  174. To do this you will have to type in the following command: `systemctl restart pveproxy`
  175.  
  176. If you got kicked out of the shell or it froze, dont worry this is normal! As the final step, either refresh your webpage with **F5** or ideally close you browser and open proxmox again.