pve 传感器温度显示改造 - PVE
pve web 端后端是依赖 node.js,前端基于 extjs 渲染,修改主要设计两个文件,文件位置如下:
- /usr/share/perl5/PVE/API2/Nodes.pm后端数据生成;
- /usr/share/pve-manager/js/pvemanagerlib.js前端展示渲染;
主要思路为,利用相关查询命令把数据查询出来,再在前端格式化渲染。
cpu 温度使用 sensors 命令,需要单独安装;apt-get install lm-sensors,命令如下:sensors -j。
硬盘温度使用 hddtemp 命令,需要单独安装:apt-get install hddtemp,命令如下:hddtemp /dev/sd?
nvme 使用 smartctl 命令,命令如下: smartctl /dev/nvme0 -a -j
也可添加其他信息。
详细需改如下,7.x 版本应该都适用。
Nodes.pm 修改如下:
...
    $res->{ksm} = {
	    shared => $meminfo->{memshared},
	};
	$res->{sensinfo} = `sensors -j`; // <-- 添加该条 cpu 温度
    $res->{cpuhz} = `lscpu |grep MHz`; // <-- 添加该条 cpu 主频
	$res->{swap} = {
	    free => $meminfo->{swapfree},
	    total => $meminfo->{swaptotal},
	    used => $meminfo->{swapused},
	};
	$res->{pveversion} = PVE::pvecfg::package() . "/" .
	    PVE::pvecfg::version_text();
...pvemanagerlib.js ,可搜 PVE.node.StatusView 定位,修改如下:
	{
	    itemId: 'cpus',
	    colspan: 2,
	    printBar: false,
	    title: gettext('CPU(s)'),
	    textField: 'cpuinfo',
	    renderer: Proxmox.Utils.render_cpu_model,
	    value: '',
	},
    {   // 新增cpu 温度渲染
        itemId: 'sensinfo',
        colspan: 2,
        printBar: false,
        title: gettext('CPU核心温度'),  
        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}℃`;  
                
        }
	},
	{   // 新增 硬盘温度渲染
        itemId: 'hddtempinfo',
        colspan: 2,
        printBar: false,
        title: gettext('硬盘温度'),
        textField: 'hddtempinfo',
        renderer: function(value) {
            value = value.replaceAll('Â', '',);
            return value.replaceAll('\n', '<br>');
        }
    },
	{
	    itemId: 'kversion',
	    colspan: 2,
	    title: gettext('Kernel Version'),
	    printBar: false,
	    textField: 'kversion',
	    value: '',
	},      
...修改前端页面高度:
Ext.define('PVE.node.StatusView', {
    extend: 'Proxmox.panel.StatusView',
    alias: 'widget.pveNodeStatus',
    height: 400,  // <-- 修改改高度 
    bodyPadding: '15 5 15 5',
    layout: {
	type: 'table',
	columns: 2,
	tableAttrs: {
	    style: {
		width: '100%',
	    },
	},
    },
    ...其他参考
- 一键处理脚本 https://www.right.com.cn/forum/thread-6754687-1-1.html
- pve 一键脚本工具 https://github.com/ivanhao/pvetools
