mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-10 05:23:09 +02:00
memory usage excludes buffer and cache.
This commit is contained in:
parent
3fb26534b7
commit
178093861b
2 changed files with 52 additions and 18 deletions
|
@ -159,7 +159,6 @@
|
||||||
"nprogress": "0.2.0",
|
"nprogress": "0.2.0",
|
||||||
"object-assign-deep": "0.4.0",
|
"object-assign-deep": "0.4.0",
|
||||||
"on-build-webpack": "0.1.0",
|
"on-build-webpack": "0.1.0",
|
||||||
"os-utils": "0.0.14",
|
|
||||||
"parse5": "5.0.0",
|
"parse5": "5.0.0",
|
||||||
"portscanner": "2.2.0",
|
"portscanner": "2.2.0",
|
||||||
"progress-bar-webpack-plugin": "1.11.0",
|
"progress-bar-webpack-plugin": "1.11.0",
|
||||||
|
@ -187,6 +186,7 @@
|
||||||
"stylus": "0.54.5",
|
"stylus": "0.54.5",
|
||||||
"stylus-loader": "3.0.2",
|
"stylus-loader": "3.0.2",
|
||||||
"summaly": "2.0.6",
|
"summaly": "2.0.6",
|
||||||
|
"systeminformation": "3.42.4",
|
||||||
"syuilo-password-strength": "0.0.1",
|
"syuilo-password-strength": "0.0.1",
|
||||||
"textarea-caret": "3.1.0",
|
"textarea-caret": "3.1.0",
|
||||||
"tmp": "0.0.33",
|
"tmp": "0.0.33",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
const osUtils = require('os-utils');
|
const sysUtils = require('systeminformation');
|
||||||
import * as diskusage from 'diskusage';
|
import * as diskusage from 'diskusage';
|
||||||
import Xev from 'xev';
|
import Xev from 'xev';
|
||||||
|
|
||||||
|
@ -18,13 +18,16 @@ export default function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
async function tick() {
|
async function tick() {
|
||||||
osUtils.cpuUsage((cpuUsage: number) => {
|
const cpu = await cpuUsage();
|
||||||
|
const freemem = await freeMem();
|
||||||
|
const totalmem = await totalMem();
|
||||||
const disk = diskusage.checkSync(os.platform() == 'win32' ? 'c:' : '/');
|
const disk = diskusage.checkSync(os.platform() == 'win32' ? 'c:' : '/');
|
||||||
|
|
||||||
const stats = {
|
const stats = {
|
||||||
cpu_usage: cpuUsage,
|
cpu_usage: cpu,
|
||||||
mem: {
|
mem: {
|
||||||
total: os.totalmem(),
|
total: totalmem,
|
||||||
free: os.freemem()
|
free: freemem
|
||||||
},
|
},
|
||||||
disk,
|
disk,
|
||||||
os_uptime: os.uptime(),
|
os_uptime: os.uptime(),
|
||||||
|
@ -32,11 +35,42 @@ export default function() {
|
||||||
};
|
};
|
||||||
ev.emit('serverStats', stats);
|
ev.emit('serverStats', stats);
|
||||||
log.push(stats);
|
log.push(stats);
|
||||||
if (log.length > 50) log.shift();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
setInterval(tick, interval);
|
setInterval(tick, interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CPU STAT
|
||||||
|
async function cpuUsage() {
|
||||||
|
try {
|
||||||
|
const data = await sysUtils.currentLoad();
|
||||||
|
return Math.floor(data.currentload);
|
||||||
|
}
|
||||||
|
catch(error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MEMORY(excl buffer + cache) STAT
|
||||||
|
async function freeMem() {
|
||||||
|
try {
|
||||||
|
const data = await sysUtils.mem();
|
||||||
|
return data.active;
|
||||||
|
}
|
||||||
|
catch(error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TOTAL MEMORY STAT
|
||||||
|
async function totalMem() {
|
||||||
|
try {
|
||||||
|
const data = await sysUtils.mem();
|
||||||
|
return data.total;
|
||||||
|
}
|
||||||
|
catch(error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue