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

View File

@ -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 |

View File

@ -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)

View File

@ -532,6 +532,46 @@
<td></td>
<td>mount point</td>
</tr>
<tr>
<td>si.fsOpenFiles(cb)</td>
<td>{...}</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td></td>
<td></td>
<td>count max/allocated file descriptors</td>
</tr>
<tr>
<td></td>
<td>max</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td></td>
<td></td>
<td>count max</td>
</tr>
<tr>
<td></td>
<td>allocated</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td></td>
<td></td>
<td>count allocated</td>
</tr>
<tr>
<td></td>
<td>available</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td></td>
<td></td>
<td>count available</td>
</tr>
<tr>
<td>si.fsStats(cb)</td>
<td>{...}</td>

View File

@ -80,6 +80,11 @@
</tr>
</thead>
<tbody>
<tr>
<th scope="row">4.5.0</th>
<td>2019-05-17</td>
<td><span class="code">fsOpenFiles()</span> added open file descriptor count</td>
</tr>
<tr>
<th scope="row">4.4.1</th>
<td>2019-05-11</td>

View File

@ -170,7 +170,7 @@
<img class="logo" src="assets/logo.png">
<div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span></div>
<div class="version">Current Version: <span id="version">4.4.1</span></div>
<div class="version">Current Version: <span id="version">4.5.0</span></div>
<button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
</div>
<div class="down">

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
lib/index.d.ts vendored
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>;

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;