首先阅读源码,恩山大佬的方式是全部展示,但是有很多数据是我们在快速管理页面根本不需要注意的数据,但是恩山大佬的显示方式不够DIY 并不能够自己任意选择需要监控的数据,就想某种monitor软件一样,可以在电脑的副屏展示很多参数。
那么你应该看到的状态是这样的:
对个人来说过于冗余,不够直观迅速
修改后
需求:确定需要的参数并单独归类,按需打开显示。
1.代码
地址文件通过mobaxterm直接拉下来:
/usr/share/pve-manager/js/pvemanagerlib.js
1.1根据需求调整需要的温度
{
itemId: 'thermal',
colspan: 2,
printBar: false,
title: gettext('温度'),
textField: 'thermalstatus',
renderer: function(value) {
//cpu
const p0 = value.match(/Package id 0.*?\+([\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];
//board
//NVMe
const NVMe_t_composite = value.match(/Composite.*?\+([\d\.]+)?/)[1];
//const NVMe_t_Sensor1 = value.match(/Sensor 1.*?\+([\d\.]+)?/)[1];
//const NVMe_t_Sensor2 = value.match(/Sensor 2.*?\+([\d\.]+)?/)[1];
//fan
const cpu_fan = value.match(/(?<=:\s+)([1-9]\d*)(?=\s+RPM)/)[1];
return `CPU: ${p0}℃ | NVMe: ${NVMe_t_composite}℃ | 风扇:${cpu_fan} RPM `
}
},
关联文件及代码:
/usr/share/perl5/PVE/API2/Nodes.pm
$res->{thermalstatus} = `sensors -A`;
1.2cpu性能只需要cpu的状态即可
{
itemId: 'cpumhz',
colspan: 2,
printBar: false,
title: gettext('CPU状态'),
textField: 'cpuFreq',
renderer:function(v){
//return v;
/*console.log(v);
let m = v.match(/(?<=^cpu[^\d]+)\d+/img);
let m2 = m.map( e => ( e / 1000 ).toFixed(1) );
m2 = m2.join(' | ');*/
let gov = v.match(/(?<=^gov:).+/im)[0].toUpperCase();
/*let min = (v.match(/(?<=^min:).+/im)[0]);
if ( min !== 'none' ) {
min=(min/1000000).toFixed(1);
}
let max = (v.match(/(?<=^max:).+/im)[0])
if ( max !== 'none' ) {
max=(max/1000000).toFixed(1);
}
let watt= v.match(/(?<=^pkgwatt:)[\d.]+$/im);
watt = watt? " | 功耗: " + (watt[0]/1).toFixed(1) + 'W' : '';*/
//return `${m2} | MAX: ${max}GHz| MIN: ${min}GHz ${watt} | CPU性能: ${gov}`
return `CPU性能: ${gov}`
}
},
1.3nvme 和sata信息简单进行修改即可
{
itemId: 'nvme00',
colspan: 2,
printBar: false,
title: gettext('NVMe'),
textField: 'nvme0',
renderer:function(value){
//return value;
try{
let v = JSON.parse(value);
//名字
let model = v.model_name;
if (! model) {
return '找不到硬盘,直通或已被卸载';
}
// 温度
let temp = v.temperature?.current;
temp = ( temp !== undefined ) ? " | " + temp + '°C' : '' ;
// 通电时间
let pot = v.power_on_time?.hours;
let poth = v.power_cycle_count;
pot = ( pot !== undefined ) ? (" | 通电: " + pot + '时' + ( poth ? ',次: '+ poth : '' )) : '';
// 读写
let log = v.nvme_smart_health_information_log;
let rw=''
let health=''
if (log) {
let read = log.data_units_read;
let write = log.data_units_written;
read = read ? (log.data_units_read / 1956882).toFixed(1) + 'T' : '';
write = write ? (log.data_units_written / 1956882).toFixed(1) + 'T' : '';
if (read && write) {
rw = ' | R/W: ' + read + '/' + write;
}
//let pu = log.percentage_used;
//let me = log.media_errors;
/*if ( pu !== undefined ) {
health = ' | 健康: ' + ( 100 - pu ) + '%'
if ( me !== undefined ) {
health += ',0E: ' + me
}
}*/
}
// smart状态
let smart = v.smart_status?.passed;
if (smart === undefined ) {
smart = '';
} else {
smart = ' | SMART: ' + (smart ? '正常' : '警告!');
}
let t = model + temp + health + smart;
//console.log(t);
return t;
}catch(e){
return '无法获得有效消息';
};
}
},
{
itemId: 'sd00',
colspan: 2,
printBar: false,
title: gettext('HDD'),
textField: 'sd0',
renderer:function(value){
//return value;
try{
let v = JSON.parse(value);
console.log(v)
if (v.standy === true) {
return '休眠中'
}
//名字
let model = v.model_name;
if (! model) {
return '找不到硬盘,直通或已被卸载';
}
// 温度
let temp = v.temperature?.current;
temp = ( temp !== undefined ) ? " | 温度: " + temp + '°C' : '' ;
// 通电时间
let pot = v.power_on_time?.hours;
let poth = v.power_cycle_count;
pot = ( pot !== undefined ) ? (" | 通电: " + pot + '时' + ( poth ? ',次: '+ poth : '' )) : '';
// smart状态
let smart = v.smart_status?.passed;
if (smart === undefined ) {
smart = '';
} else {
smart = ' | SMART: ' + (smart ? '正常' : '警告!');
}
//let t = model + temp + pot + smart;
let t = model + temp + smart;
//console.log(t);
return t;
}catch(e){
return '无法获得有效消息';
};
}
}, {
itemId: 'nvme00',
colspan: 2,
printBar: false,
title: gettext('NVMe'),
textField: 'nvme0',
renderer:function(value){
//return value;
try{
let v = JSON.parse(value);
//名字
let model = v.model_name;
if (! model) {
return '找不到硬盘,直通或已被卸载';
}
// 温度
let temp = v.temperature?.current;
temp = ( temp !== undefined ) ? " | " + temp + '°C' : '' ;
// 通电时间
let pot = v.power_on_time?.hours;
let poth = v.power_cycle_count;
pot = ( pot !== undefined ) ? (" | 通电: " + pot + '时' + ( poth ? ',次: '+ poth : '' )) : '';
// 读写
let log = v.nvme_smart_health_information_log;
let rw=''
let health=''
if (log) {
let read = log.data_units_read;
let write = log.data_units_written;
read = read ? (log.data_units_read / 1956882).toFixed(1) + 'T' : '';
write = write ? (log.data_units_written / 1956882).toFixed(1) + 'T' : '';
if (read && write) {
rw = ' | R/W: ' + read + '/' + write;
}
//let pu = log.percentage_used;
//let me = log.media_errors;
/*if ( pu !== undefined ) {
health = ' | 健康: ' + ( 100 - pu ) + '%'
if ( me !== undefined ) {
health += ',0E: ' + me
}
}*/
}
// smart状态
let smart = v.smart_status?.passed;
if (smart === undefined ) {
smart = '';
} else {
smart = ' | SMART: ' + (smart ? '正常' : '警告!');
}
let t = model + temp + health + smart;
//console.log(t);
return t;
}catch(e){
return '无法获得有效消息';
};
}
},
{
itemId: 'sd00',
colspan: 2,
printBar: false,
title: gettext('HDD'),
textField: 'sd0',
renderer:function(value){
//return value;
try{
let v = JSON.parse(value);
console.log(v)
if (v.standy === true) {
return '休眠中'
}
//名字
let model = v.model_name;
if (! model) {
return '找不到硬盘,直通或已被卸载';
}
// 温度
let temp = v.temperature?.current;
temp = ( temp !== undefined ) ? " | 温度: " + temp + '°C' : '' ;
// 通电时间
let pot = v.power_on_time?.hours;
let poth = v.power_cycle_count;
pot = ( pot !== undefined ) ? (" | 通电: " + pot + '时' + ( poth ? ',次: '+ poth : '' )) : '';
// smart状态
let smart = v.smart_status?.passed;
if (smart === undefined ) {
smart = '';
} else {
smart = ' | SMART: ' + (smart ? '正常' : '警告!');
}
//let t = model + temp + pot + smart;
let t = model + temp + smart;
//console.log(t);
return t;
}catch(e){
return '无法获得有效消息';
};
}
},