fsOpenFiles() added open file descriptor count

This commit is contained in:
Sebastian Hildebrandt
2019-05-17 19:13:37 +02:00
parent f614fd550d
commit 40d7e2b055
8 changed files with 121 additions and 6 deletions
+65 -5
View File
@@ -76,7 +76,7 @@ function fsSize(callback) {
}
if (_windows) {
try {
util.wmic('logicaldisk get Caption,FileSystem,FreeSpace,Size').then((stdout, error) => {
util.wmic('logicaldisk get Caption,FileSystem,FreeSpace,Size').then((stdout) => {
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) {
if (line !== '') {
@@ -107,6 +107,66 @@ function fsSize(callback) {
exports.fsSize = fsSize;
// --------------------------
// FS - open files count
function fsOpenFiles(callback) {
return new Promise((resolve) => {
process.nextTick(() => {
const result = {
max: -1,
allocated: -1,
available: -1
};
if (_freebsd || _openbsd || _darwin) {
let cmd = 'sysctl -a | grep \'kern.*files\'';
exec(cmd, function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
result.max = parseInt(util.getValue(lines, 'kern.maxfiles', ':'), 10);
result.allocated = parseInt(util.getValue(lines, 'kern.num_files', ':'), 10);
}
if (callback) {
callback(result);
}
resolve(result);
});
}
if (_linux) {
let cmd = 'cat /proc/sys/fs/file-nr';
exec(cmd, function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
if (lines[0]) {
const parts = lines[0].replace(/\s+/g, ' ').split(' ');
if (parts.length === 3) {
result.allocated = parseInt(parts[0], 10);
result.available = parseInt(parts[1], 10);
result.max = parseInt(parts[2], 10);
}
}
}
if (callback) {
callback(result);
}
resolve(result);
});
}
if (_sunos) {
if (callback) { callback(result); }
resolve(result);
}
if (_windows) {
if (callback) { callback(result); }
resolve(result);
}
});
});
}
exports.fsOpenFiles = fsOpenFiles;
// --------------------------
// disks
@@ -638,9 +698,9 @@ function diskLayout(callback) {
model = model.toUpperCase();
diskManufacturers.forEach((manufacturer) => {
const re = RegExp(manufacturer.pattern);
if (re.test(model)) { result = manufacturer.manufacturer }
})
return result
if (re.test(model)) { result = manufacturer.manufacturer; }
});
return result;
}
return new Promise((resolve) => {
@@ -656,7 +716,7 @@ function diskLayout(callback) {
const out = stdout.toString().trim();
const outJSON = JSON.parse(out);
if (outJSON && outJSON.hasOwnProperty('blockdevices')) {
let devices = outJSON.blockdevices.filter(item => { return item.group === 'disk' && item.size > 0 && item.model !== null });
let devices = outJSON.blockdevices.filter(item => { return item.group === 'disk' && item.size > 0 && item.model !== null; });
devices.forEach((device) => {
let mediumType = '';
const BSDName = '/dev/' + device.name;
+7
View File
@@ -250,6 +250,12 @@ export namespace Systeminformation {
mount: string;
}
interface FsOpenFilesData {
max: number;
allocated: number;
available: number;
}
interface BlockDevicesData {
name: string;
identifier: string;
@@ -511,6 +517,7 @@ export function battery(cb?: (data: Systeminformation.BatteryData) => any): Prom
export function graphics(cb?: (data: Systeminformation.GraphicsData) => any): Promise<Systeminformation.GraphicsData>;
export function fsSize(cb?: (data: Systeminformation.FsSizeData[]) => any): Promise<Systeminformation.FsSizeData[]>;
export function fsOpenFiles(cb?: (data: Systeminformation.FsOpenFilesData[]) => any): Promise<Systeminformation.FsOpenFilesData[]>;
export function blockDevices(cb?: (data: Systeminformation.BlockDevicesData[]) => any): Promise<Systeminformation.BlockDevicesData[]>;
export function fsStats(cb?: (data: Systeminformation.FsStatsData) => any): Promise<Systeminformation.FsStatsData>;
export function disksIO(cb?: (data: Systeminformation.DisksIoData) => any): Promise<Systeminformation.DisksIoData>;
+1
View File
@@ -337,6 +337,7 @@ exports.battery = battery;
exports.graphics = graphics.graphics;
exports.fsSize = filesystem.fsSize;
exports.fsOpenFiles = filesystem.fsOpenFiles;
exports.blockDevices = filesystem.blockDevices;
exports.fsStats = filesystem.fsStats;
exports.disksIO = filesystem.disksIO;