PVE 默认是没有CPU和主板温度显示的,为方便使用,我们自己加上
实际效果
版本和软件
- Virtual Environment 6.1-3
- putty 或 PVE自带的Shell 或 MobaXterm 等工具
安装硬件温度监控软件 lm-sensors
lm-sensors(Linux-monitoring sensors,Linux监控传感器)是一款linux的硬件监控的软件,可以帮助我们来监控主板,CPU的工作电压,风扇转速、温度等数据。
- 安装lm-sensor
apt-get install lm-sensors
- 验证lm-sensors的版本
sensors -v
显示
sensors version 3.5.0 with libsensors version 3.5.0
- 执行sensors-detect命令,获取可显示的温度
lm-sensors使用之前需要使用sensors-detect
命令去配置它。
sensors-detect是一个与硬件传感器交互的脚本,用来探测哪些传感器可用并加载相关的内核模块。
运行下面的命令,然后按照屏幕提示进行操作。
sensors-detect
确认项目比较多,全部默认yes就行,最后回车,yes
4. 执行sensors命令
使用sensors
命令验证lm-sensors
是否正常运行,显示出系统运行的温度状态和风扇转速等信息,这个信息就是我们所需要的。
sensors
显示
root@pve:~# sensors
iwlwifi-virtual-0
Adapter: Virtual device
temp1: N/A
acpitz-acpi-0
Adapter: ACPI interface
temp1: +27.8°C (crit = +119.0°C)
temp2: +29.8°C (crit = +119.0°C)
coretemp-isa-0000
Adapter: ISA adapter
Package id 0: +38.0°C (high = +84.0°C, crit = +100.0°C)
Core 0: +32.0°C (high = +84.0°C, crit = +100.0°C)
Core 1: +33.0°C (high = +84.0°C, crit = +100.0°C)
Core 2: +32.0°C (high = +84.0°C, crit = +100.0°C)
Core 3: +32.0°C (high = +84.0°C, crit = +100.0°C)
i350bb-pci-0100
Adapter: PCI adapter
loc1: +0.0°C (high = +0.0°C, crit = +0.0°C)
我们可以看出
acpitz-acpi-0
是主板温度coretemp-isa-0000
是 CPU 温度
定制显示温度内容
PVE 的 WebUI 控制台是使用Node.js
实现的,所以要修改对应的文件,使得其可以定期执行sensors
命令,并将结果输出 Web 页面上。
修改Nodes.pm,获取温度
- 打开文件
vi /usr/share/perl5/PVE/API2/Nodes.pm
- 增加内容
$res->{temperature} = `sensors`; # 获取 CPU 和 主板 的温度
/my $dinfo = df('/', 1);
在搜索内容的上面,注意位置进行添加,比如我的在 352 行进行添加
...
$res->{ksm} = {
shared => $meminfo->{memshared},
};
$res->{swap} = {
free => $meminfo->{swapfree},
total => $meminfo->{swaptotal},
used => $meminfo->{swapused},
};
$res->{pveversion} = PVE::pvecfg::package() . "/" .
PVE::pvecfg::version_text();
$res->{temperature} = `sensors`; # 获取 CPU 和 主板 的温度
my $dinfo = df('/', 1); # output is bytes
$res->{rootfs} = {
total => $dinfo->{blocks},
avail => $dinfo->{bavail},
used => $dinfo->{used},
free => $dinfo->{blocks} - $dinfo->{used},
};
return $res;
...
修改pvemanagerlib.js,显示温度
- 打开文件
vi /usr/share/pve-manager/js/pvemanagerlib.js
- 增加内容,添加页面显示内容
- 增加的内容,内容要根据自己的实际情况修改,注意逗号“ , ”
,
{
itemId: 'temperature',
colspan: 2,
printBar: false,
title: gettext('Temperature'),
textField: 'temperature',
renderer: function(value){
const p0 = value.match(/Package id 0.*?\+([\d\.]+)?/)[1];
const b0 = value.match(/temp1.*?\+([\d\.]+)?/)[1];
const b1 = value.match(/temp2.*?\+([\d\.]+)?/)[1];
const c0 = value.match(/Core 0.*?\+([\d\.]+)?/)[1];
const c1 = value.match(/Core 1.*?\+([\d\.]+)?/)[1];
const c2 = value.match(/Core 2.*?\+([\d\.]+)?/)[1];
const c3 = value.match(/Core 3.*?\+([\d\.]+)?/)[1];
return `CPU: ${p0}℃ | Core0: ${c0}℃ | Core1: ${c1}℃ | Core2: ${c2}℃ | Core3: ${c3}℃ | Board: ${b0} ℃ ${b1}℃ `
}
const
开头的常量名称和数量是由前文所说的sensors
命令的输出结果决定的,对于不同的CPU类型其内容会有所不同,可能主板只有一个temp1,可能没有Package的名称,也可能会有多个Socket。
/itemId: 'version',
在内容的下面,注意位置进行添加,我的在 18719 行开始进行添加
...
{
itemId: 'version',
colspan: 2,
printBar: false,
title: gettext('PVE Manager Version'),
textField: 'pveversion',
value: ''
},
{
itemId: 'temperature',
colspan: 2,
printBar: false,
title: gettext('Temperature'),
textField: 'temperature',
renderer: function(value){
const p0 = value.match(/Package id 0.*?\+([\d\.]+)?/)[1];
const b0 = value.match(/temp1.*?\+([\d\.]+)?/)[1];
const b1 = value.match(/temp2.*?\+([\d\.]+)?/)[1];
const c0 = value.match(/Core 0.*?\+([\d\.]+)?/)[1];
const c1 = value.match(/Core 1.*?\+([\d\.]+)?/)[1];
const c2 = value.match(/Core 2.*?\+([\d\.]+)?/)[1];
const c3 = value.match(/Core 3.*?\+([\d\.]+)?/)[1];
return `CPU: ${p0}℃ | Core0: ${c0}℃ | Core1: ${c1}℃ | Core2: ${c2}℃ | Core3: ${c3}℃ | Board: ${b0} ℃ ${b1}℃ `
}
}
],
updateTitle: function() {
var me = this;
var uptime = Proxmox.Utils.render_uptime(me.getRecordValue('uptime'));
me.setTitle(me.pveSelNode.data.node + ' (' + gettext('Uptime') + ': ' + uptime + ')');
}
});
...
修改完成,重启Web控制台
systemctl restart pveproxy
注意:
- 若浏览器显示内容没有发生变化,可以按ctrl+F5强制刷新或者清理缓存后重试。
- 若 Web 管理页面不能正常显示,如白屏,则可能代码有错误,应修改后重试。
- 若 温度的显示值为
null
,请打开开发者工具
,在Console
中进行查看
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)