先安装sensors插件:
apt-get install lm-sensors
传感器探测:
sensors-detect
传感器探测基本上一直按Y就可以了,中途可能有一个地方需要按ENTER继续。
测试显示传感器:
sensors
修改PVE文件,添加修改代码
编辑Nodes.pm文件:
vi /usr/share/perl5/PVE/API2/Nodes.pm
定位编辑位置,查找内容:$res->{ksm} = {
在vi中,按冒号“:”,然后按斜杠“/”,输入查找的内容:$res->{ksm} = {
也就是在编辑文件时最下面一行会显示:
:/$res->{ksm} = {
按回车,就会跳转到查找的内容那一行。
添加代码:$res->{sensinfo} = `sensors -j`;
修改后的代码如下:
$res->{ksm} = {
shared => $meminfo->{memshared},
};
$res->{sensinfo} = `sensors -j`; # JSON格式输出传感器数据
编辑pvemanagerlib.js文件:
vi /usr/share/pve-manager/js/pvemanagerlib.js
定位编辑位置,查找内容:Proxmox.Utils.render_cpu_model,
方法跟上面一样。
添加如下代码:
{
itemId: 'sensinfo',
colspan: 2,
printBar: false,
title: gettext('温度传感器'), // WEB显示内容
textField: 'sensinfo',
renderer:function(value){
value = JSON.parse(value.replaceAll('Â', ''));
const c0 = value['coretemp-isa-0000']['Core 0']['temp2_input'].toFixed(1);
const c1 = value['coretemp-isa-0000']['Core 1']['temp3_input'].toFixed(1);
const c2 = value['coretemp-isa-0000']['Core 2']['temp4_input'].toFixed(1);
const c3 = value['coretemp-isa-0000']['Core 3']['temp5_input'].toFixed(1);
const f1 = value['it8786-isa-0a40']['fan1']['fan1_input'].toFixed(1);
return `CPU核心温度: ${c0}℃ | ${c1}℃ | ${c2}℃ | ${c3}℃ <br> 风扇转速:${f1}`; // 输出格式
}
},
修改之后的代码如下:
{
itemId: 'cpus',
colspan: 2,
printBar: false,
title: gettext('CPU(s)'),
textField: 'cpuinfo',
renderer: Proxmox.Utils.render_cpu_model,
value: '',
},
{
itemId: 'sensinfo',
colspan: 2,
printBar: false,
title: gettext('温度传感器'), // WEB显示内容
textField: 'sensinfo',
renderer:function(value){
value = JSON.parse(value.replaceAll('Â', ''));
const c0 = value['coretemp-isa-0000']['Core 0']['temp2_input'].toFixed(1);
const c1 = value['coretemp-isa-0000']['Core 1']['temp3_input'].toFixed(1);
const c2 = value['coretemp-isa-0000']['Core 2']['temp4_input'].toFixed(1);
const c3 = value['coretemp-isa-0000']['Core 3']['temp5_input'].toFixed(1);
const f1 = value['it8786-isa-0a40']['fan1']['fan1_input'].toFixed(1);
return `CPU核心温度: ${c0}℃ | ${c1}℃ | ${c2}℃ | ${c3}℃ <br> 风扇转速:${f1}`; // 输出格式
}
},
{
itemId: 'kversion',
colspan: 2,
title: gettext('Kernel Version'),
printBar: false,
textField: 'kversion',
value: '',
},
代码详解:
"coretemp-isa-0000" 是 CPU 传感器,其中 "Core 0" 是核心编号,"temp2_input": 56.000 是核心温度
"Package id 0" 是封装传感器,对应的 "temp1_input": xx.000 是封装温度,具体看代码
"acpitz-acpi-0" 是主板传感器,对应的参数大伙看自己的代码
转速在 "it8786-isa-0a40" 模块中的 "fan1" 或者 "fan2",看具体插在 CPU 或者 SYS 针脚上
return 输出显示详解:
获取数据格式为【const xxxx = value['xxxx']['xxxx']['xxxx_input'].toFixed(1)】
【result】输出字符串的格式根据实际情况或者个人需求进行修改
比如在作者的基础上加入 CPU 封装温度和主板温度,不需要显示风扇转速
修改布局显示
编辑pvemanagerlib.js文件:
vi /usr/share/pve-manager/js/pvemanagerlib.js
定位编辑位置,查找内容:Ext.create('Ext.window.Window', {
将这里面的height这一项的数值修改为600,默认是400
继续查找内容跳转:widget.pveNodeStatus
将这里面的height这一项的数值修改为350,默认是300
两处 height 的值需按情况修改,每多一行数据增加 20。根据实际情况修改,比如不想看到订阅,可适当调整。
重启PVE的WEB服务:
systemctl restart pveproxy
稍等几秒钟之后,刷新PVE管理网页或者重新打开PVE管理页面。
此教程太复杂,一般的小白弄不好,比如我。折腾了几次都没有成功。后来找到一位大佬的脚本,直接使用脚本进行自动修改,简单,轻量,效果好。