mem() refactoring parsing linux, code cleanup
This commit is contained in:
parent
ba14dab53a
commit
fd2d81245c
@ -100,6 +100,7 @@ Other changes
|
|||||||
|
|
||||||
| Version | Date | Comment |
|
| Version | Date | Comment |
|
||||||
| -------------- | -------------- | -------- |
|
| -------------- | -------------- | -------- |
|
||||||
|
| 3.51.3 | 2018-11-27 | `mem()` refactoring parsing linux, code cleanup |
|
||||||
| 3.51.2 | 2018-11-26 | `mem()` bugfix parsing `free` output linux |
|
| 3.51.2 | 2018-11-26 | `mem()` bugfix parsing `free` output linux |
|
||||||
| 3.51.1 | 2018-11-26 | `processLoad()` bugfix windows |
|
| 3.51.1 | 2018-11-26 | `processLoad()` bugfix windows |
|
||||||
| 3.51.0 | 2018-11-25 | `processLoad()` added for windows |
|
| 3.51.0 | 2018-11-25 | `processLoad()` added for windows |
|
||||||
|
|||||||
@ -89,6 +89,20 @@ const OSX_RAM_manufacturers = {
|
|||||||
//
|
//
|
||||||
// Reference: http://www.software-architect.net/blog/article/date/2015/06/12/-826c6e5052.html
|
// Reference: http://www.software-architect.net/blog/article/date/2015/06/12/-826c6e5052.html
|
||||||
|
|
||||||
|
// /procs/meminfo - sample (all in kB)
|
||||||
|
//
|
||||||
|
// MemTotal: 32806380 kB
|
||||||
|
// MemFree: 19220948 kB
|
||||||
|
// MemAvailable: 20851100 kB
|
||||||
|
// Buffers: 532892 kB
|
||||||
|
// Cached: 1935000 kB
|
||||||
|
// SwapCached: 0 kB
|
||||||
|
// Active: 11953672 kB
|
||||||
|
// Inactive: 1069288 kB
|
||||||
|
// SwapTotal: 16768892 kB
|
||||||
|
// SwapFree: 16768892 kB
|
||||||
|
|
||||||
|
|
||||||
function mem(callback) {
|
function mem(callback) {
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
@ -109,32 +123,36 @@ function mem(callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (_linux) {
|
if (_linux) {
|
||||||
exec('export LC_ALL=C; free -b ; unset LC_ALL', function (error, stdout) {
|
exec('export LC_ALL=C; cat /proc/meminfo ; unset LC_ALL', function (error, stdout) {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
const lines = stdout.toString().split('\n');
|
const lines = stdout.toString().split('\n');
|
||||||
console.log(lines);
|
result.total = parseInt(util.getValue(lines, 'memtotal'), 10);
|
||||||
const parsedHeads = util.parseHead(lines[0], 100);
|
result.total = result.total ? result.total * 1024 : os.totalmem();
|
||||||
parsedHeads[0].from = 6;
|
result.free = parseInt(util.getValue(lines, 'memfree'), 10);
|
||||||
let mem = lines[1];
|
result.free = result.free ? result.free * 1024 : os.freemem();
|
||||||
result.total = parseInt(mem.substring(parsedHeads[0].from - 1, parsedHeads[0].to), 10);
|
|
||||||
result.free = parseInt(mem.substring(parsedHeads[2].from - 1, parsedHeads[2].to), 10);
|
|
||||||
result.used = result.total - result.free;
|
result.used = result.total - result.free;
|
||||||
|
|
||||||
if (lines.length === 4) { // free (since free von procps-ng 3.3.10)
|
let buffers = parseInt(util.getValue(lines, 'buffers'), 10);
|
||||||
result.buffcache = parseInt(mem.substring(parsedHeads[4].from - 1, parsedHeads[4].to), 10);
|
buffers = buffers ? buffers * 1024 : 0;
|
||||||
result.available = parseInt(mem.substring(parsedHeads[5].from - 1, parsedHeads[5].to), 10);
|
let cached = parseInt(util.getValue(lines, 'cached'), 10);
|
||||||
mem = lines[2];
|
cached = cached ? cached * 1024 : 0;
|
||||||
} else { // free (older versions)
|
result.buffcache = buffers + cached;
|
||||||
result.buffcache = parseInt(mem.substring(parsedHeads[4].from - 1, parsedHeads[4].to), 10) + parseInt(mem.substring(parsedHeads[5].from - 1, parsedHeads[5].to), 10);
|
|
||||||
result.available = result.free + result.buffcache;
|
|
||||||
mem = lines[3];
|
|
||||||
}
|
|
||||||
result.active = result.total - result.free - result.buffcache;
|
|
||||||
|
|
||||||
result.swaptotal = parseInt(mem.substring(parsedHeads[0].from - 1, parsedHeads[0].to), 10);
|
result.available = parseInt(util.getValue(lines, 'memavailable'), 10);
|
||||||
result.swapfree = parseInt(mem.substring(parsedHeads[2].from - 1, parsedHeads[2].to), 10);
|
result.available = result.available ? result.available * 1024 : os.freemem();
|
||||||
result.swapused = parseInt(mem.substring(parsedHeads[1].from - 1, parsedHeads[1].to), 10);
|
|
||||||
|
|
||||||
|
// result.active = result.total - result.free - result.buffcache;
|
||||||
|
|
||||||
|
result.active = parseInt(util.getValue(lines, 'active'), 10);
|
||||||
|
result.active = result.active ? result.active * 1024 : 0;
|
||||||
|
result.buffcache = result.total - result.free - result.active;
|
||||||
|
|
||||||
|
result.swaptotal = parseInt(util.getValue(lines, 'swaptotal'), 10);
|
||||||
|
result.swaptotal = result.swaptotal ? result.swaptotal * 1024 : 0;
|
||||||
|
result.swapfree = parseInt(util.getValue(lines, 'swapfree'), 10);
|
||||||
|
result.swapfree = result.swapfree ? result.swapfree * 1024 : 0;
|
||||||
|
result.swapused = parseInt(util.getValue(lines, 'swapcached'), 10);
|
||||||
|
result.swapused = result.swapused ? result.swapused * 1024 : 0;
|
||||||
}
|
}
|
||||||
if (callback) { callback(result); }
|
if (callback) { callback(result); }
|
||||||
resolve(result);
|
resolve(result);
|
||||||
|
|||||||
@ -792,7 +792,6 @@ function processLoad(proc, callback) {
|
|||||||
exec(util.getWmic() + ' process get /value', util.execOptsWin, function (error, stdout) {
|
exec(util.getWmic() + ' process get /value', util.execOptsWin, function (error, stdout) {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
let processSections = stdout.split(/\n\s*\n/);
|
let processSections = stdout.split(/\n\s*\n/);
|
||||||
let procs = [];
|
|
||||||
let procStats = [];
|
let procStats = [];
|
||||||
let list_new = {};
|
let list_new = {};
|
||||||
let allcpuu = 0;
|
let allcpuu = 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user