Proxmox VE(PVE) 添加Web控制台显示CPU和主板温度

PVE 默认是没有CPU和主板温度显示的,为方便使用,我们自己加上

实际效果

pve添加Web控制台显示CPU和主板温度

版本和软件

  • Virtual Environment 6.1-3
  • putty 或 PVE自带的Shell 或 MobaXterm 等工具

安装硬件温度监控软件 lm-sensors

lm-sensors(Linux-monitoring sensors,Linux监控传感器)是一款linux的硬件监控的软件,可以帮助我们来监控主板,CPU的工作电压,风扇转速、温度等数据。

  1. 安装lm-sensor
apt-get install lm-sensors
  1. 验证lm-sensors的版本
sensors -v

显示

sensors version 3.5.0 with libsensors version 3.5.0
  1. 执行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,获取温度

  1. 打开文件
vi /usr/share/perl5/PVE/API2/Nodes.pm
  1. 增加内容
  • 增加的内容
$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,显示温度

  1. 打开文件
vi /usr/share/pve-manager/js/pvemanagerlib.js
  1. 增加内容,添加页面显示内容
  • 增加的内容,内容要根据自己的实际情况修改,注意逗号“ , ”
,
        {
            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中进行查看
  • 7
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值