1、更新软件包列表:
apt update
2、安装lm-sensors:
apt install lm-sensors patch
3、初始化 sensors (一路yes,回车):
sensors-detect
4、给予 smartctl 权限 (如不需要硬盘信息可以忽略):
chmod +s /usr/sbin/smartctl
5、获取温度信息,查看可以设置的数据:
sensors
正式开始
修改 Nodes.pm 文件
/usr/share/perl5/PVE/API2/Nodes.pm
搜索:$res->{pveversion} = PVE::pvecfg::package() 下方添加
$res->{sensors_json} = `sensors -j`; # 获取 CPU 、主板温度及风扇转速
$res->{smartctl_nvme_json} = `smartctl -a -j /dev/nvme?`; # 读取 nvme 硬盘 S.M.A.R.T. 值,获取硬盘寿命、容量、温度等
$res->{smartctl_sda_json} = `smartctl -i -n standby /dev/sda|grep "STANDBY" || smartctl -i -n standby /dev/sda|grep "No such device" || smartctl -a -j /dev/sda`; #先检测硬盘是否为休眠状态,若否,则检查磁盘是否存在,若否,则返回 S.M.A.R.T. 值
$res->{smartctl_sdb_json} = `smartctl -i -n standby /dev/sdb|grep "STANDBY" || smartctl -i -n standby /dev/sdb|grep "No such device" || smartctl -a -j /dev/sdb`; #先检测硬盘是否为休眠状态,若否,则检查磁盘是否存在,若否,则返回 S.M.A.R.T. 值
修改 pvemanagerlib.js 文件
/usr/share/pve-manager/js/pvemanagerlib.js
搜索 PVE Manager Version 下方添加
{
itemId: 'thermal',
colspan: 2,
printBar: false,
title: gettext('温度'),
textField: 'sensors_json',
renderer: function(value) {
value = value.replace(/temp([0-9]{1,})_input/g,'input');
// Intel
if (value.indexOf("coretemp-isa") != -1 ) {
value = value.replace(/coretemp-isa-(.{4})/g,'coretemp-isa');
value = value.replace(/nct6798-isa-(.{4})/g,'nct6798-isa');
value = JSON.parse(value);
try {var cpu_Intel = 'CPU: ' + value['coretemp-isa']['Package id 0']['input'].toFixed(1) + '°C';} catch(e) {var cpu_Intel = '';}
try {var acpi = ' || 主板: ' + value['acpitz-acpi-0']['temp1']['input'].toFixed(1) + '°C';} catch(e) {var acpi = '';}
try {var pch = ' || 南桥: ' + value['pch_cometlake-virtual-0']['temp1']['input'].toFixed(1) + '°C';} catch(e) {var pch = '';}
try {var pci0 = ' || 网卡: ' + value['nct6798-isa']['PECI Agent 0']['input'].toFixed(1) + '°C';} catch(e) {var pci0 = '';}
// 如果存在主板、PCI网卡温度,优先显示
if (cpu_Intel.length > 0 && pch.length + acpi.length + pci0.length > 0) {
return `${cpu_Intel}${acpi}${pch}${pci0}`;
// 如果不存在,显示 CPU 全核温度,最高支持 8 核心
} else if (cpu_Intel.length > 0) {
try {var cpu0 = ' || 核心 0 : ' + value['coretemp-isa']['Core 0']['input'].toFixed(1) + '°C';} catch(e) {var cpu0 = '';}
try {var cpu1 = ' | 核心 1 : ' + value['coretemp-isa']['Core 1']['input'].toFixed(1) + '°C';} catch(e) {var cpu1 = '';}
try {var cpu2 = ' | 核心 2 : ' + value['coretemp-isa']['Core 2']['input'].toFixed(1) + '°C';} catch(e) {var cpu2 = '';}
try {var cpu3 = ' | 核心 3 : ' + value['coretemp-isa']['Core 3']['input'].toFixed(1) + '°C';} catch(e) {var cpu3 = '';}
try {var cpu4 = ' | 核心 4 : ' + value['coretemp-isa']['Core 4']['input'].toFixed(1) + '°C';} catch(e) {var cpu4 = '';}
try {var cpu5 = ' | 核心 5 : ' + value['coretemp-isa']['Core 5']['input'].toFixed(1) + '°C';} catch(e) {var cpu5 = '';}
try {var cpu6 = ' | 核心 6 : ' + value['coretemp-isa']['Core 6']['input'].toFixed(1) + '°C';} catch(e) {var cpu6 = '';}
try {var cpu7 = ' | 核心 7 : ' + value['coretemp-isa']['Core 7']['input'].toFixed(1) + '°C';} catch(e) {var cpu7 = '';}
return `${cpu_Intel}${cpu0}${cpu1}${cpu2}${cpu3}${cpu4}${cpu5}${cpu6}${cpu7}`;
}
// AMD
} else if (value.indexOf("amdgpu-pci") != -1 ) {
value = value.replace(/k10temp-pci-(.{4})/g,'k10temp-pci');
value = value.replace(/zenpower-pci-(.{4})/g,'zenpower-pci');
value = value.replace(/amdgpu-pci-(.{4})/g,'amdgpu-pci');
value = JSON.parse(value);
try {var cpu_amd_k10 = 'CPU: ' + value['k10temp-pci']['Tctl']['input'].toFixed(1) + '°C';} catch(e) {var cpu_amd_k10 = '';}
try {var cpu_amd_zen = 'CPU: ' + value['zenpower-pci']['Tctl']['input'].toFixed(1) + '°C';} catch(e) {var cpu_amd_zen = '';}
try {var amdgpu = ' | GPU: ' + value['amdgpu-pci']['edge']['input'].toFixed(1) + '°C';} catch(e) {var amdgpu = '';}
return `${cpu_amd_k10}${cpu_amd_zen}${amdgpu}`;
} else {
return `提示: CPU 及 主板 温度读取异常`;
}
}
},
{
itemId: 'nvme_ssd',
colspan: 2,
printBar: false,
title: gettext('NVME'),
textField: 'smartctl_nvme_json',
renderer: function(value) {
value = JSON.parse(value);
if (value['model_name']) {
try {var model_name = value['model_name'];} catch(e) {var model_name = '';}
try {var percentage_used = ' | 使用寿命: ' + value['nvme_smart_health_information_log']['percentage_used'].toFixed(0) + '% ';} catch(e) {var percentage_used = '';}
try {var data_units_read = value['nvme_smart_health_information_log']['data_units_read']*512/1024/1024/1024;var data_units_read = '(读: ' + data_units_read.toFixed(2) + 'TB, ';} catch(e) {var data_units_read = '';}
try {var data_units_written = value['nvme_smart_health_information_log']['data_units_written']*512/1024/1024/1024;var data_units_written = '写: ' + data_units_written.toFixed(2) + 'TB)';} catch(e) {var data_units_written = '';}
try {var power_on_time = ' | 通电: ' + value['power_on_time']['hours'].toFixed(0) + '小时';} catch(e) {var power_on_time = '';}
try {var temperature = ' | 温度: ' + value['temperature']['current'].toFixed(1) + '°C';} catch(e) {var temperature = '';}
return `${model_name}${percentage_used}${data_units_read}${data_units_written}${power_on_time}${temperature}`;
} else {
return `提示: 未安装硬盘或已直通硬盘控制器`;
}
}
},
{
itemId: 'SATA_sda',
colspan: 2,
printBar: false,
title: gettext('SATA_sda'),
textField: 'smartctl_sda_json',
renderer: function(value) {
if (value.indexOf("Device is in STANDBY mode") != -1 ) {
return `提示: 磁盘休眠中`;
} else if (value.indexOf("No such device") != -1 ) {
return `提示: 未安装硬盘或已直通硬盘控制器`;
} else {
value = JSON.parse(value);
try {var model_name = value['model_name'];} catch(e) {var model_name = '';}
try {var user_capacity = value['user_capacity']['bytes']/1024/1024/1024;var user_capacity = ' | 容量: ' + user_capacity.toFixed(2) + ' GB';} catch(e) {var user_capacity = '';}
try {var power_on_time = ' | 已通电: ' + value['power_on_time']['hours'].toFixed(0) + ' 小时';} catch(e) {var power_on_time = '';}
try {var error_count = value['ata_smart_error_log']['summary']['count'].toFixed(0);if (error_count != 0){error_count = ' | 磁盘错误: ' + error_count;} else {var error_count = '';} } catch(e) {var error_count = '';}
try {var self_count = value['ata_smart_self_test_log']['standard']['error_count_total'].toFixed(0);if (self_count != 0){self_count = ' | 自检错误: ' + self_count;} else {var self_count = '';} } catch(e) {var self_count = '';}
try {var temperature = ' | 温度: ' + value['temperature']['current'].toFixed(1) + '°C';} catch(e) {var temperature = '';}
return `${model_name}${user_capacity}${power_on_time}${error_count}${self_count}${temperature}`;
}
}
},
{
itemId: 'SATA_sdb',
colspan: 2,
printBar: false,
title: gettext('SATA_sdb'),
textField: 'smartctl_sdb_json',
renderer: function(value) {
if (value.indexOf("Device is in STANDBY mode") != -1 ) {
return `提示: 磁盘休眠中`;
} else if (value.indexOf("No such device") != -1 ) {
return `提示: 未安装硬盘或已直通硬盘控制器`;
} else {
value = JSON.parse(value);
try {var model_name = value['model_name'];} catch(e) {var model_name = '';}
try {var user_capacity = value['user_capacity']['bytes']/1024/1024/1024;var user_capacity = ' | 容量: ' + user_capacity.toFixed(2) + ' GB';} catch(e) {var user_capacity = '';}
try {var power_on_time = ' | 已通电: ' + value['power_on_time']['hours'].toFixed(0) + ' 小时';} catch(e) {var power_on_time = '';}
try {var error_count = value['ata_smart_error_log']['summary']['count'].toFixed(0);if (error_count != 0){error_count = ' | 磁盘错误: ' + error_count;} else {var error_count = '';} } catch(e) {var error_count = '';}
try {var self_count = value['ata_smart_self_test_log']['standard']['error_count_total'].toFixed(0);if (self_count != 0){self_count = ' | 自检错误: ' + self_count;} else {var self_count = '';} } catch(e) {var self_count = '';}
try {var temperature = ' | 温度: ' + value['temperature']['current'].toFixed(1) + '°C';} catch(e) {var temperature = '';}
return `${model_name}${user_capacity}${power_on_time}${error_count}${self_count}${temperature}`;
}
}
},
文章评论