mem() added reclaimable (Linux, macOS)

This commit is contained in:
Sebastian Hildebrandt
2025-05-24 06:52:52 +02:00
parent 5b79685f5e
commit 63b01c4418
8 changed files with 76 additions and 16 deletions
+43 -6
View File
@@ -575,7 +575,7 @@ function blockDevices(callback) {
if (_linux) {
// see https://wiki.ubuntuusers.de/lsblk/
// exec("lsblk -bo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,TRAN,SERIAL,LABEL,MODEL,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,SCHED,RQ-SIZE,RA,WSAME", function (error, stdout) {
exec('lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,TRAN,SERIAL,LABEL,MODEL,OWNER 2>/dev/null', { maxBuffer: 1024 * 1024 }, function (error, stdout) {
const procLsblk1 = exec('lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,TRAN,SERIAL,LABEL,MODEL,OWNER 2>/dev/null', { maxBuffer: 1024 * 1024 }, function (error, stdout) {
if (!error) {
let lines = blkStdoutToObject(stdout).split('\n');
data = parseBlk(lines);
@@ -586,7 +586,7 @@ function blockDevices(callback) {
}
resolve(data);
} else {
exec('lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER 2>/dev/null', { maxBuffer: 1024 * 1024 }, function (error, stdout) {
const procLsblk2 = exec('lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER 2>/dev/null', { maxBuffer: 1024 * 1024 }, function (error, stdout) {
if (!error) {
let lines = blkStdoutToObject(stdout).split('\n');
data = parseBlk(lines);
@@ -597,11 +597,23 @@ function blockDevices(callback) {
}
resolve(data);
});
procLsblk2.on('error', function () {
if (callback) {
callback(data);
}
resolve(data);
});
}
});
procLsblk1.on('error', function () {
if (callback) {
callback(data);
}
resolve(data);
});
}
if (_darwin) {
exec('diskutil info -all', { maxBuffer: 1024 * 1024 }, function (error, stdout) {
const procDskutil = exec('diskutil info -all', { maxBuffer: 1024 * 1024 }, function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
// parse lines into temp array of devices
@@ -613,6 +625,12 @@ function blockDevices(callback) {
}
resolve(data);
});
procDskutil.on('error', function () {
if (callback) {
callback(data);
}
resolve(data);
});
}
if (_sunos) {
if (callback) { callback(data); }
@@ -747,7 +765,7 @@ function fsStats(callback) {
if ((_fs_speed && !_fs_speed.ms) || (_fs_speed && _fs_speed.ms && Date.now() - _fs_speed.ms >= 500)) {
if (_linux) {
// exec("df -k | grep /dev/", function(error, stdout) {
exec('lsblk -r 2>/dev/null | grep /', { maxBuffer: 1024 * 1024 }, function (error, stdout) {
const procLsblk = exec('lsblk -r 2>/dev/null | grep /', { maxBuffer: 1024 * 1024 }, function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
let fs_filter = [];
@@ -759,7 +777,7 @@ function fsStats(callback) {
});
let output = fs_filter.join('|');
exec('cat /proc/diskstats | egrep "' + output + '"', { maxBuffer: 1024 * 1024 }, function (error, stdout) {
const procCat = exec('cat /proc/diskstats | egrep "' + output + '"', { maxBuffer: 1024 * 1024 }, function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
lines.forEach(function (line) {
@@ -778,6 +796,12 @@ function fsStats(callback) {
}
resolve(result);
});
procCat.on('error', function () {
if (callback) {
callback(result);
}
resolve(result);
});
} else {
if (callback) {
callback(result);
@@ -785,9 +809,16 @@ function fsStats(callback) {
resolve(result);
}
});
procLsblk.on('error', function () {
if (callback) {
callback(result);
}
resolve(result);
});
}
if (_darwin) {
exec('ioreg -c IOBlockStorageDriver -k Statistics -r -w0 | sed -n "/IOBlockStorageDriver/,/Statistics/p" | grep "Statistics" | tr -cd "01234567890,\n"', { maxBuffer: 1024 * 1024 }, function (error, stdout) {
const procIoreg = exec('ioreg -c IOBlockStorageDriver -k Statistics -r -w0 | sed -n "/IOBlockStorageDriver/,/Statistics/p" | grep "Statistics" | tr -cd "01234567890,\n"', { maxBuffer: 1024 * 1024 }, function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
lines.forEach(function (line) {
@@ -806,6 +837,12 @@ function fsStats(callback) {
}
resolve(result);
});
procIoreg.on('error', function () {
if (callback) {
callback(result);
}
resolve(result);
});
}
} else {
result.ms = _fs_speed.last_ms;
+1
View File
@@ -123,6 +123,7 @@ export namespace Systeminformation {
buffers: number;
cached: number;
slab: number;
reclaimable: number;
swaptotal: number;
swapused: number;
swapfree: number;
+10 -6
View File
@@ -31,13 +31,13 @@ const _sunos = (_platform === 'sunos');
const RAM_manufacturers = {
'00CE': 'Samsung Electronics Inc',
'014F': 'Transcend Information',
'017A': 'Apacer Technology Inc',
'014F': 'Transcend Information Inc.',
'017A': 'Apacer Technology Inc.',
'0198': 'HyperX',
'029E': 'Corsair',
'02FE': 'Elpida',
'04CB': 'A-DATA',
'04CD': 'G-Skill International Enterprise',
'04CD': 'G.Skill International Enterprise',
'059B': 'Crucial',
'1315': 'Crucial',
'2C00': 'Micron Technology Inc.',
@@ -52,6 +52,7 @@ const RAM_manufacturers = {
'SAMSUNG': 'Samsung Electronics Inc.',
'HYNIX': 'Hynix Semiconductor Inc.',
'G-SKILL': 'G-Skill International Enterprise',
'G.SKILL': 'G-Skill International Enterprise',
'TRANSCEND': 'Transcend Information',
'APACER': 'Apacer Technology Inc',
'MICRON': 'Micron Technology Inc.',
@@ -151,6 +152,7 @@ function mem(callback) {
cached: 0,
slab: 0,
buffcache: 0,
reclaimable: 0,
swaptotal: 0,
swapused: 0,
@@ -191,6 +193,8 @@ function mem(callback) {
result.writeback = result.writeback ? result.writeback * 1024 : 0;
result.dirty = parseInt(util.getValue(lines, 'dirty'), 10);
result.dirty = result.dirty ? result.dirty * 1024 : 0;
result.reclaimable = parseInt(util.getValue(lines, 'sreclaimable'), 10);
result.reclaimable = result.reclaimable ? result.reclaimable * 1024 : 0;
}
if (callback) { callback(result); }
resolve(result);
@@ -242,11 +246,11 @@ function mem(callback) {
util.noop();
}
try {
exec('vm_stat 2>/dev/null | grep "Pages active"', function (error, stdout) {
exec('vm_stat 2>/dev/null | egrep "Pages active|Pages inactive"', function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
result.active = parseInt(lines[0].split(':')[1], 10) * pageSize;
result.active = (parseInt(util.getValue(lines, 'Pages active'), 10) || 0) * pageSize;
result.reclaimable = (parseInt(util.getValue(lines, 'Pages inactive'), 10) || 0) * pageSize;
result.buffcache = result.used - result.active;
result.available = result.free + result.buffcache;
}