fsSize() added optional drive parameter

This commit is contained in:
Sebastian Hildebrandt 2023-06-06 13:28:50 +02:00
parent 1df611af74
commit 8c22e42bf3
7 changed files with 99 additions and 81 deletions

View File

@ -82,6 +82,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page.
| Version | Date | Comment | | Version | Date | Comment |
| ------- | ---------- | --------------------------------------------------------------------------------------------------- | | ------- | ---------- | --------------------------------------------------------------------------------------------------- |
| 5.18.0 | 2023-06-06 | `fsSize()` added optional drive parameter |
| 5.17.17 | 2023-06-03 | `osInfo()` improved fqdn (linux) | | 5.17.17 | 2023-06-03 | `osInfo()` improved fqdn (linux) |
| 5.17.16 | 2023-05-30 | `usb()` fix parsing JSON (mac OS) | | 5.17.16 | 2023-05-30 | `usb()` fix parsing JSON (mac OS) |
| 5.17.15 | 2023-05-29 | `powershell()` added NoProfile to speed up powershell (windows) | | 5.17.15 | 2023-05-29 | `powershell()` added NoProfile to speed up powershell (windows) |

View File

@ -111,6 +111,7 @@ si.cpu()
(last 7 major and minor version releases) (last 7 major and minor version releases)
- Version 5.18.0: `fsSize()` added optional drive parameter
- Version 5.17.0: `graphics()` added positionX, positionY (mac OS) - Version 5.17.0: `graphics()` added positionX, positionY (mac OS)
- Version 5.16.0: `fsSize()` added rw property - Version 5.16.0: `fsSize()` added rw property
- Version 5.15.0: `blockDevices()` added device - Version 5.15.0: `blockDevices()` added device
@ -434,7 +435,7 @@ Full function reference with examples can be found at [https://systeminformation
#### 9. File System #### 9. File System
| Function | Result object | Linux | BSD | Mac | Win | Sun | Comments | | Function | Result object | Linux | BSD | Mac | Win | Sun | Comments |
| ------------------- | --------------------- | ----- | --- | --- | --- | --- | ------------------------------------------------------------------------ | | -------------------- | --------------------- | ----- | --- | --- | --- | --- | ------------------------------------------------------------------------ |
| si.diskLayout(cb) | [{...}] | X | | X | X | | physical disk layout (array) | | si.diskLayout(cb) | [{...}] | X | | X | X | | physical disk layout (array) |
| | [0].device | X | | X | | | e.g. /dev/sda | | | [0].device | X | | X | | | e.g. /dev/sda |
| | [0].type | X | | X | X | | HD, SSD, NVMe | | | [0].type | X | | X | X | | HD, SSD, NVMe |
@ -483,7 +484,7 @@ Full function reference with examples can be found at [https://systeminformation
| | wWaitPercent | X | | | | | write IO request time percent (* see notes) | | | wWaitPercent | X | | | | | write IO request time percent (* see notes) |
| | tWaitPercent | X | | | | | total IO request time percent (* see notes) | | | tWaitPercent | X | | | | | total IO request time percent (* see notes) |
| | ms | X | | X | | | interval length (for per second values) | | | ms | X | | X | | | interval length (for per second values) |
| si.fsSize(cb) | [{...}] | X | X | X | X | | returns array of mounted file systems | | si.fsSize(drive, cb) | [{...}] | X | X | X | X | | returns array of mounted file systems<br>drive param is optional |
| | [0].fs | X | X | X | X | | name of file system | | | [0].fs | X | X | X | X | | name of file system |
| | [0].type | X | X | X | X | | type of file system | | | [0].type | X | X | X | X | | type of file system |
| | [0].size | X | X | X | X | | sizes in bytes | | | [0].size | X | X | X | X | | sizes in bytes |

View File

@ -663,14 +663,14 @@ setInterval(function() {
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>si.fsSize(cb)</td> <td>si.fsSize(drive, cb)</td>
<td>[{...}]</td> <td>[{...}]</td>
<td>X</td> <td>X</td>
<td>X</td> <td>X</td>
<td>X</td> <td>X</td>
<td>X</td> <td>X</td>
<td></td> <td></td>
<td>returns array of mounted file systems</td> <td>returns array of mounted file systems<br>drive parameter is optional</td>
</tr> </tr>
<tr> <tr>
<td></td> <td></td>

View File

@ -57,6 +57,11 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr>
<th scope="row">5.18.0</th>
<td>2023-06-06</td>
<td><span class="code">fssize()</span> added optional drive parameter</td>
</tr>
<tr> <tr>
<th scope="row">5.17.17</th> <th scope="row">5.17.17</th>
<td>2023-06-03</td> <td>2023-06-03</td>

View File

@ -170,7 +170,7 @@
<img class="logo" src="assets/logo.png" alt="logo"> <img class="logo" src="assets/logo.png" alt="logo">
<div class="title">systeminformation</div> <div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span>&nbsp;</div> <div class="subtitle"><span id="typed"></span>&nbsp;</div>
<div class="version">New Version: <span id="version">5.17.17</span></div> <div class="version">New Version: <span id="version">5.18.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> <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>
<div class="down"> <div class="down">
@ -212,7 +212,7 @@
<div class="title">Downloads last month</div> <div class="title">Downloads last month</div>
</div> </div>
<div class="col-xl-4 col-lg-4 col-md-4 col-12"> <div class="col-xl-4 col-lg-4 col-md-4 col-12">
<div class="numbers">613</div> <div class="numbers">617</div>
<div class="title">Dependents</div> <div class="title">Dependents</div>
</div> </div>
</div> </div>

View File

@ -36,7 +36,12 @@ let _disk_io = {};
// -------------------------- // --------------------------
// FS - mounted file systems // FS - mounted file systems
function fsSize(callback) { function fsSize(drive, callback) {
if (util.isFunction(drive)) {
callback = drive;
drive = '';
}
let macOsDisks = []; let macOsDisks = [];
let osMounts = []; let osMounts = [];
@ -61,6 +66,7 @@ function fsSize(callback) {
function filterLines(stdout) { function filterLines(stdout) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
lines.shift();
if (stdout.toString().toLowerCase().indexOf('filesystem')) { if (stdout.toString().toLowerCase().indexOf('filesystem')) {
let removeLines = 0; let removeLines = 0;
for (let i = 0; i < lines.length; i++) { for (let i = 0; i < lines.length; i++) {
@ -131,7 +137,7 @@ function fsSize(callback) {
} }
} }
if (_linux) { if (_linux) {
cmd = 'df -lkPTx squashfs'; cmd = 'export LC_ALL=C; df -lkPTx squashfs; unset LC_ALL';
execSync('cat /proc/mounts 2>/dev/null').toString().split('\n').filter(line => { execSync('cat /proc/mounts 2>/dev/null').toString().split('\n').filter(line => {
return line.startsWith('/'); return line.startsWith('/');
}).forEach((line) => { }).forEach((line) => {
@ -147,6 +153,11 @@ function fsSize(callback) {
exec(cmd, { maxBuffer: 1024 * 1024 }, function (error, stdout) { exec(cmd, { maxBuffer: 1024 * 1024 }, function (error, stdout) {
let lines = filterLines(stdout); let lines = filterLines(stdout);
data = parseDf(lines); data = parseDf(lines);
if (drive) {
data = data.filter(item => {
return item.fs.toLowerCase().indexOf(drive.toLowerCase()) >= 0 || item.mount.toLowerCase().indexOf(drive.toLowerCase()) >= 0;
});
}
if (!error || data.length) { if (!error || data.length) {
if (callback) { if (callback) {
callback(data); callback(data);
@ -172,8 +183,8 @@ function fsSize(callback) {
} }
if (_windows) { if (_windows) {
try { try {
// util.wmic('logicaldisk get Caption,FileSystem,FreeSpace,Size').then((stdout) => { const cmd = `Get-WmiObject Win32_logicaldisk | select Caption,FileSystem,FreeSpace,Size ${drive ? '| where -property Caption -eq ' + drive : ''} | fl`;
util.powerShell('Get-CimInstance Win32_logicaldisk | select Access,Caption,FileSystem,FreeSpace,Size | fl').then((stdout, error) => { util.powerShell(cmd).then((stdout, error) => {
if (!error) { if (!error) {
let devices = stdout.toString().split(/\n\s*\n/); let devices = stdout.toString().split(/\n\s*\n/);
devices.forEach(function (device) { devices.forEach(function (device) {

2
lib/index.d.ts vendored
View File

@ -967,7 +967,7 @@ export function memLayout(cb?: (data: Systeminformation.MemLayoutData[]) => any)
export function battery(cb?: (data: Systeminformation.BatteryData) => any): Promise<Systeminformation.BatteryData>; export function battery(cb?: (data: Systeminformation.BatteryData) => any): Promise<Systeminformation.BatteryData>;
export function graphics(cb?: (data: Systeminformation.GraphicsData) => any): Promise<Systeminformation.GraphicsData>; export function graphics(cb?: (data: Systeminformation.GraphicsData) => any): Promise<Systeminformation.GraphicsData>;
export function fsSize(cb?: (data: Systeminformation.FsSizeData[]) => any): Promise<Systeminformation.FsSizeData[]>; export function fsSize(drive?: string, cb?: (data: Systeminformation.FsSizeData[]) => any): Promise<Systeminformation.FsSizeData[]>;
export function fsOpenFiles(cb?: (data: Systeminformation.FsOpenFilesData[]) => any): Promise<Systeminformation.FsOpenFilesData[]>; export function fsOpenFiles(cb?: (data: Systeminformation.FsOpenFilesData[]) => any): Promise<Systeminformation.FsOpenFilesData[]>;
export function blockDevices(cb?: (data: Systeminformation.BlockDevicesData[]) => any): Promise<Systeminformation.BlockDevicesData[]>; export function blockDevices(cb?: (data: Systeminformation.BlockDevicesData[]) => any): Promise<Systeminformation.BlockDevicesData[]>;
export function fsStats(cb?: (data: Systeminformation.FsStatsData) => any): Promise<Systeminformation.FsStatsData>; export function fsStats(cb?: (data: Systeminformation.FsStatsData) => any): Promise<Systeminformation.FsStatsData>;