From 8c22e42bf35c8ba057dfbfc6536139ee66046221 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Tue, 6 Jun 2023 13:28:50 +0200 Subject: [PATCH] fsSize() added optional drive parameter --- CHANGELOG.md | 1 + README.md | 143 ++++++++++++++++++++++--------------------- docs/filesystem.html | 6 +- docs/history.html | 5 ++ docs/index.html | 4 +- lib/filesystem.js | 19 ++++-- lib/index.d.ts | 2 +- 7 files changed, 99 insertions(+), 81 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc6f16e..5750398 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page. | 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.16 | 2023-05-30 | `usb()` fix parsing JSON (mac OS) | | 5.17.15 | 2023-05-29 | `powershell()` added NoProfile to speed up powershell (windows) | diff --git a/README.md b/README.md index 31ef5d6..eb49663 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,7 @@ si.cpu() (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.16.0: `fsSize()` added rw property - Version 5.15.0: `blockDevices()` added device @@ -433,77 +434,77 @@ Full function reference with examples can be found at [https://systeminformation #### 9. File System -| Function | Result object | Linux | BSD | Mac | Win | Sun | Comments | -| ------------------- | --------------------- | ----- | --- | --- | --- | --- | ------------------------------------------------------------------------ | -| si.diskLayout(cb) | [{...}] | X | | X | X | | physical disk layout (array) | -| | [0].device | X | | X | | | e.g. /dev/sda | -| | [0].type | X | | X | X | | HD, SSD, NVMe | -| | [0].name | X | | X | X | | disk name | -| | [0].vendor | X | | | X | | vendor/producer | -| | [0].size | X | | X | X | | size in bytes | -| | [0].bytesPerSector | | | | X | | bytes per sector | -| | [0].totalCylinders | | | | X | | total cylinders | -| | [0].totalHeads | | | | X | | total heads | -| | [0].totalSectors | | | | X | | total sectors | -| | [0].totalTracks | | | | X | | total tracks | -| | [0].tracksPerCylinder | | | | X | | tracks per cylinder | -| | [0].sectorsPerTrack | | | | X | | sectors per track | -| | [0].firmwareRevision | X | | X | X | | firmware revision | -| | [0].serialNum | X | | X | X | | serial number | -| | [0].interfaceType | X | | | X | | SATA, PCIe, ... | -| | [0].smartStatus | X | | X | X | | S.M.A.R.T Status (see Known Issues) | -| | [0].temperature | X | | | | | S.M.A.R.T temperature | -| | [0].smartData | X | | | X | | full S.M.A.R.T data from smartctl
requires at least smartmontools 7.0 | -| si.blockDevices(cb) | [{...}] | X | | X | X | | returns array of disks, partitions,
raids and roms | -| | [0].name | X | | X | X | | name | -| | [0].type | X | | X | X | | type | -| | [0].fstype | X | | X | X | | file system type (e.g. ext4) | -| | [0].mount | X | | X | X | | mount point | -| | [0].size | X | | X | X | | size in bytes | -| | [0].physical | X | | X | X | | physical type (HDD, SSD, CD/DVD) | -| | [0].uuid | X | | X | X | | UUID | -| | [0].label | X | | X | X | | label | -| | [0].model | X | | X | | | model | -| | [0].serial | X | | | X | | serial | -| | [0].removable | X | | X | X | | serial | -| | [0].protocol | X | | X | | | protocol (SATA, PCI-Express, ...) | -| | [0].group | X | | | | | Raid group member (e.g. md1) | -| | [0].device | X | | X | X | | physical device mapped to (e.g. /dev/sda) | -| si.disksIO(cb) | {...} | X | | X | | | current transfer stats | -| | rIO | X | | X | | | read IOs on all mounted drives | -| | wIO | X | | X | | | write IOs on all mounted drives | -| | tIO | X | | X | | | write IOs on all mounted drives | -| | rIO_sec | X | | X | | | read IO per sec (* see notes) | -| | wIO_sec | X | | X | | | write IO per sec (* see notes) | -| | tIO_sec | X | | X | | | total IO per sec (* see notes) | -| | rWaitTime | X | | | | | read IO request time (* see notes) | -| | wWaitTime | X | | | | | write IO request time (* see notes) | -| | tWaitTime | X | | | | | total IO request time (* see notes) | -| | rWaitPercent | X | | | | | read IO request time percent (* see notes) | -| | wWaitPercent | X | | | | | write IO request time percent (* see notes) | -| | tWaitPercent | X | | | | | total IO request time percent (* see notes) | -| | ms | X | | X | | | interval length (for per second values) | -| si.fsSize(cb) | [{...}] | X | X | X | X | | returns array of mounted file systems | -| | [0].fs | X | X | X | X | | name of file system | -| | [0].type | X | X | X | X | | type of file system | -| | [0].size | X | X | X | X | | sizes in bytes | -| | [0].used | X | X | X | X | | used in bytes | -| | [0].available | X | X | X | X | | used in bytes | -| | [0].use | X | X | X | X | | used in % | -| | [0].mount | X | X | X | X | | mount point | -| | [0].rw | X | X | X | X | | read and write (false if read only) | -| si.fsOpenFiles(cb) | {...} | X | X | X | | | count max/allocated file descriptors | -| | max | X | X | X | | | max file descriptors | -| | allocated | X | X | X | | | current open files count | -| | available | X | X | X | | | count available | -| si.fsStats(cb) | {...} | X | | X | | | current transfer stats | -| | rx | X | | X | | | bytes read since startup | -| | wx | X | | X | | | bytes written since startup | -| | tx | X | | X | | | total bytes read + written since startup | -| | rx_sec | X | | X | | | bytes read / second (* see notes) | -| | wx_sec | X | | X | | | bytes written / second (* see notes) | -| | tx_sec | X | | X | | | total bytes reads + written / second | -| | ms | X | | X | | | interval length (for per second values) | +| Function | Result object | Linux | BSD | Mac | Win | Sun | Comments | +| -------------------- | --------------------- | ----- | --- | --- | --- | --- | ------------------------------------------------------------------------ | +| si.diskLayout(cb) | [{...}] | X | | X | X | | physical disk layout (array) | +| | [0].device | X | | X | | | e.g. /dev/sda | +| | [0].type | X | | X | X | | HD, SSD, NVMe | +| | [0].name | X | | X | X | | disk name | +| | [0].vendor | X | | | X | | vendor/producer | +| | [0].size | X | | X | X | | size in bytes | +| | [0].bytesPerSector | | | | X | | bytes per sector | +| | [0].totalCylinders | | | | X | | total cylinders | +| | [0].totalHeads | | | | X | | total heads | +| | [0].totalSectors | | | | X | | total sectors | +| | [0].totalTracks | | | | X | | total tracks | +| | [0].tracksPerCylinder | | | | X | | tracks per cylinder | +| | [0].sectorsPerTrack | | | | X | | sectors per track | +| | [0].firmwareRevision | X | | X | X | | firmware revision | +| | [0].serialNum | X | | X | X | | serial number | +| | [0].interfaceType | X | | | X | | SATA, PCIe, ... | +| | [0].smartStatus | X | | X | X | | S.M.A.R.T Status (see Known Issues) | +| | [0].temperature | X | | | | | S.M.A.R.T temperature | +| | [0].smartData | X | | | X | | full S.M.A.R.T data from smartctl
requires at least smartmontools 7.0 | +| si.blockDevices(cb) | [{...}] | X | | X | X | | returns array of disks, partitions,
raids and roms | +| | [0].name | X | | X | X | | name | +| | [0].type | X | | X | X | | type | +| | [0].fstype | X | | X | X | | file system type (e.g. ext4) | +| | [0].mount | X | | X | X | | mount point | +| | [0].size | X | | X | X | | size in bytes | +| | [0].physical | X | | X | X | | physical type (HDD, SSD, CD/DVD) | +| | [0].uuid | X | | X | X | | UUID | +| | [0].label | X | | X | X | | label | +| | [0].model | X | | X | | | model | +| | [0].serial | X | | | X | | serial | +| | [0].removable | X | | X | X | | serial | +| | [0].protocol | X | | X | | | protocol (SATA, PCI-Express, ...) | +| | [0].group | X | | | | | Raid group member (e.g. md1) | +| | [0].device | X | | X | X | | physical device mapped to (e.g. /dev/sda) | +| si.disksIO(cb) | {...} | X | | X | | | current transfer stats | +| | rIO | X | | X | | | read IOs on all mounted drives | +| | wIO | X | | X | | | write IOs on all mounted drives | +| | tIO | X | | X | | | write IOs on all mounted drives | +| | rIO_sec | X | | X | | | read IO per sec (* see notes) | +| | wIO_sec | X | | X | | | write IO per sec (* see notes) | +| | tIO_sec | X | | X | | | total IO per sec (* see notes) | +| | rWaitTime | X | | | | | read IO request time (* see notes) | +| | wWaitTime | X | | | | | write IO request time (* see notes) | +| | tWaitTime | X | | | | | total IO request time (* see notes) | +| | rWaitPercent | X | | | | | read IO request time percent (* see notes) | +| | wWaitPercent | X | | | | | write IO request time percent (* see notes) | +| | tWaitPercent | X | | | | | total IO request time percent (* see notes) | +| | ms | X | | X | | | interval length (for per second values) | +| si.fsSize(drive, cb) | [{...}] | X | X | X | X | | returns array of mounted file systems
drive param is optional | +| | [0].fs | X | X | X | X | | name of file system | +| | [0].type | X | X | X | X | | type of file system | +| | [0].size | X | X | X | X | | sizes in bytes | +| | [0].used | X | X | X | X | | used in bytes | +| | [0].available | X | X | X | X | | used in bytes | +| | [0].use | X | X | X | X | | used in % | +| | [0].mount | X | X | X | X | | mount point | +| | [0].rw | X | X | X | X | | read and write (false if read only) | +| si.fsOpenFiles(cb) | {...} | X | X | X | | | count max/allocated file descriptors | +| | max | X | X | X | | | max file descriptors | +| | allocated | X | X | X | | | current open files count | +| | available | X | X | X | | | count available | +| si.fsStats(cb) | {...} | X | | X | | | current transfer stats | +| | rx | X | | X | | | bytes read since startup | +| | wx | X | | X | | | bytes written since startup | +| | tx | X | | X | | | total bytes read + written since startup | +| | rx_sec | X | | X | | | bytes read / second (* see notes) | +| | wx_sec | X | | X | | | bytes written / second (* see notes) | +| | tx_sec | X | | X | | | total bytes reads + written / second | +| | ms | X | | X | | | interval length (for per second values) | #### 10. USB diff --git a/docs/filesystem.html b/docs/filesystem.html index 812e879..494d1bb 100644 --- a/docs/filesystem.html +++ b/docs/filesystem.html @@ -663,14 +663,14 @@ setInterval(function() { - si.fsSize(cb) + si.fsSize(drive, cb) [{...}] X X X X - returns array of mounted file systems + returns array of mounted file systems
drive parameter is optional @@ -1011,4 +1011,4 @@ setInterval(function() { - \ No newline at end of file + diff --git a/docs/history.html b/docs/history.html index 251d145..47b5dba 100644 --- a/docs/history.html +++ b/docs/history.html @@ -57,6 +57,11 @@ + + 5.18.0 + 2023-06-06 + fssize() added optional drive parameter + 5.17.17 2023-06-03 diff --git a/docs/index.html b/docs/index.html index 688b97b..0451f61 100644 --- a/docs/index.html +++ b/docs/index.html @@ -170,7 +170,7 @@
systeminformation
 
-
New Version: 5.17.17
+
New Version: 5.18.0
@@ -212,7 +212,7 @@
Downloads last month
-
613
+
617
Dependents
diff --git a/lib/filesystem.js b/lib/filesystem.js index 3c395f4..279fa26 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -36,7 +36,12 @@ let _disk_io = {}; // -------------------------- // FS - mounted file systems -function fsSize(callback) { +function fsSize(drive, callback) { + + if (util.isFunction(drive)) { + callback = drive; + drive = ''; + } let macOsDisks = []; let osMounts = []; @@ -61,6 +66,7 @@ function fsSize(callback) { function filterLines(stdout) { let lines = stdout.toString().split('\n'); + lines.shift(); if (stdout.toString().toLowerCase().indexOf('filesystem')) { let removeLines = 0; for (let i = 0; i < lines.length; i++) { @@ -131,7 +137,7 @@ function fsSize(callback) { } } 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 => { return line.startsWith('/'); }).forEach((line) => { @@ -147,6 +153,11 @@ function fsSize(callback) { exec(cmd, { maxBuffer: 1024 * 1024 }, function (error, stdout) { let lines = filterLines(stdout); 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 (callback) { callback(data); @@ -172,8 +183,8 @@ function fsSize(callback) { } if (_windows) { try { - // util.wmic('logicaldisk get Caption,FileSystem,FreeSpace,Size').then((stdout) => { - util.powerShell('Get-CimInstance Win32_logicaldisk | select Access,Caption,FileSystem,FreeSpace,Size | fl').then((stdout, error) => { + const cmd = `Get-WmiObject Win32_logicaldisk | select Caption,FileSystem,FreeSpace,Size ${drive ? '| where -property Caption -eq ' + drive : ''} | fl`; + util.powerShell(cmd).then((stdout, error) => { if (!error) { let devices = stdout.toString().split(/\n\s*\n/); devices.forEach(function (device) { diff --git a/lib/index.d.ts b/lib/index.d.ts index 9dede7a..70424a6 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -967,7 +967,7 @@ export function memLayout(cb?: (data: Systeminformation.MemLayoutData[]) => any) export function battery(cb?: (data: Systeminformation.BatteryData) => any): Promise; export function graphics(cb?: (data: Systeminformation.GraphicsData) => any): Promise; -export function fsSize(cb?: (data: Systeminformation.FsSizeData[]) => any): Promise; +export function fsSize(drive?: string, 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;