From 40d7e2b05562c87417670cbc1e210033ab66740d Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Fri, 17 May 2019 19:13:37 +0200 Subject: [PATCH] fsOpenFiles() added open file descriptor count --- CHANGELOG.md | 1 + README.md | 1 + docs/filesystem.html | 40 +++++++++++++++++++++++++ docs/history.html | 5 ++++ docs/index.html | 2 +- lib/filesystem.js | 70 ++++++++++++++++++++++++++++++++++++++++---- lib/index.d.ts | 7 +++++ lib/index.js | 1 + 8 files changed, 121 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03ffa1b..bf53375 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | +| 4.5.0 | 2019-05-17 | `fsOpenFiles()` added open file descriptor count | | 4.4.1 | 2019-05-11 | updated docs | | 4.4.0 | 2019-05-11 | `dockerContainers()` added started, finished time | | 4.3.0 | 2019-05-09 | `dockerContainers()` `dockerStats()` added restartCount | diff --git a/README.md b/README.md index 5435cc9..dd55015 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ si.cpu() (last 7 major and minor version releases) +- Version 4.5.0: `fsOpenFiles()` added open file descriptor count - Version 4.4.0: `dockerContainers()` added started, finished time - Version 4.3.0: `dockerContainers()` `dockerStats()` added restartCount - Version 4.2.0: `networkInterfaceDefault()` time delay fix (linux) diff --git a/docs/filesystem.html b/docs/filesystem.html index cb6e77a..a9e277b 100644 --- a/docs/filesystem.html +++ b/docs/filesystem.html @@ -532,6 +532,46 @@ mount point + + si.fsOpenFiles(cb) + {...} + X + X + X + + + count max/allocated file descriptors + + + + max + X + X + X + + + count max + + + + allocated + X + X + X + + + count allocated + + + + available + X + X + X + + + count available + si.fsStats(cb) {...} diff --git a/docs/history.html b/docs/history.html index 484c138..da9e6e8 100644 --- a/docs/history.html +++ b/docs/history.html @@ -80,6 +80,11 @@ + + 4.5.0 + 2019-05-17 + fsOpenFiles() added open file descriptor count + 4.4.1 2019-05-11 diff --git a/docs/index.html b/docs/index.html index eb2f835..f4f0d75 100644 --- a/docs/index.html +++ b/docs/index.html @@ -170,7 +170,7 @@
systeminformation
-
Current Version: 4.4.1
+
Current Version: 4.5.0
diff --git a/lib/filesystem.js b/lib/filesystem.js index 9044833..a6cc8ab 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -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; diff --git a/lib/index.d.ts b/lib/index.d.ts index f8c0442..379e499 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -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; export function fsSize(cb?: (data: Systeminformation.FsSizeData[]) => any): Promise; +export function fsOpenFiles(cb?: (data: Systeminformation.FsOpenFilesData[]) => any): Promise; export function blockDevices(cb?: (data: Systeminformation.BlockDevicesData[]) => any): Promise; export function fsStats(cb?: (data: Systeminformation.FsStatsData) => any): Promise; export function disksIO(cb?: (data: Systeminformation.DisksIoData) => any): Promise; diff --git a/lib/index.js b/lib/index.js index fc75554..5fffd4b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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;