linux-monitor
Version:
linux ubuntu 性能监控
66 lines (60 loc) • 1.28 kB
JavaScript
let Monitor = require('../lib/Monitor');
let monitor = new Monitor({debug: true});
let __monitorData = {
cpu: {
ratio: []
},
mem: {
MemTotal: [],
MemFree: [],
UsageRatio: []
},
disk: {
Used: [],
UsageRatio: []
},
io: {
util: []
}
};
let TypeFilter = {
cpu: {
ratio: 'cpu使用率'
},
mem: {
MemTotal: '总内存大小',
MemFree: '空闲内存大小',
UsageRatio: '内存使用率'
},
disk: {
Used: '硬盘使用量',
UsageRatio: '硬盘使用率'
},
io: {
util: '使用率'
}
};
getMonitor(1);
setInterval(() => {
getMonitor();
}, 5000);
function getMonitor(netTime) {
monitor.GetMonitorData(netTime)
.then(data => {
__saveData(data);
})
.catch(error => {
__monitorData = {};
console.error('Interval:error:', error)
})
}
function __saveData(data) {
for(let type in TypeFilter){
for(let attr in TypeFilter[type]){
if(!! data && data[type] && data[type][attr]){
__monitorData[type][attr].push(data[type][attr].value)
}
}
}
console.log(__monitorData);
}