From 3e50507d925d095b7076e9d735c96db744b49899 Mon Sep 17 00:00:00 2001 From: mily20001 Date: Fri, 1 May 2020 20:07:32 +0200 Subject: [PATCH 1/5] add full smart data from smartctl --- README.md | 1 + lib/filesystem.js | 89 ++++++++++++++++++++++++++++------------------- lib/index.d.ts | 76 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index b7ad5e5..ebf5c0b 100644 --- a/README.md +++ b/README.md @@ -382,6 +382,7 @@ I also created a nice little command line tool called [mmon][mmon-github-url] ( | | [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].smartData | X | | | | | S.M.A.R.T data from smartctl - requires at least smartmontools 7.0 (see Known Issues) | | 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 | diff --git a/lib/filesystem.js b/lib/filesystem.js index 6790a39..be670ee 100755 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -739,6 +739,17 @@ function diskLayout(callback) { let cmd = ''; if (_linux) { + let cmdFullSmart = ''; + const commitResult = res => { + for (let i = 0; i < res.length; i++) { + delete res[i].BSDName; + } + if (callback) { + callback(res); + } + resolve(res); + }; + exec('export LC_ALL=C; lsblk -ablJO 2>/dev/null; unset LC_ALL', function (error, stdout) { if (!error) { try { @@ -789,52 +800,60 @@ function diskLayout(callback) { smartStatus: 'unknown', BSDName: BSDName }); - cmd = cmd + 'printf "\n' + BSDName + '|"; smartctl -H ' + BSDName + ' | grep overall;'; + cmd += `printf "\n${BSDName}|"; smartctl -H ${BSDName} | grep overall;`; + cmdFullSmart += `${cmdFullSmart ? 'printf ",";' : ''}smartctl -a -j ${BSDName};` }); } catch (e) { util.noop(); } } // check S.M.A.R.T. status - if (cmd) { - cmd = cmd + 'printf "\n"'; - exec(cmd, function (error, stdout) { - let lines = stdout.toString().split('\n'); - lines.forEach(line => { - if (line) { - let parts = line.split('|'); - if (parts.length === 2) { - let BSDName = parts[0]; - parts[1] = parts[1].trim(); - let parts2 = parts[1].split(':'); - if (parts2.length === 2) { - parts2[1] = parts2[1].trim(); - let status = parts2[1].toLowerCase(); - for (let i = 0; i < result.length; i++) { - if (result[i].BSDName === BSDName) { - result[i].smartStatus = (status === 'passed' ? 'Ok' : (status === 'failed!' ? 'Predicted Failure' : 'unknown')); - } + if (cmdFullSmart) { + exec(cmdFullSmart, function (error, stdout) { + try { + const data = JSON.parse(`[${stdout}]`); + data.forEach(disk => { + const diskBSDName = disk.smartctl.argv[disk.smartctl.argv.length - 1]; + + for (let i = 0; i < result.length; i++) { + if (result[i].BSDName === diskBSDName) { + result[i].smartStatus = (disk.smart_status.passed ? 'Ok' : (disk.smart_status.passed === false ? 'Predicted Failure' : 'unknown')); + result[i].smartData = disk; } } - } + }); + commitResult(result); + } catch (e) { + if (cmd) { + cmd = cmd + 'printf "\n"'; + exec(cmd, function (error, stdout) { + let lines = stdout.toString().split('\n'); + lines.forEach(line => { + if (line) { + let parts = line.split('|'); + if (parts.length === 2) { + let BSDName = parts[0]; + parts[1] = parts[1].trim(); + let parts2 = parts[1].split(':'); + if (parts2.length === 2) { + parts2[1] = parts2[1].trim(); + let status = parts2[1].toLowerCase(); + for (let i = 0; i < result.length; i++) { + if (result[i].BSDName === BSDName) { + result[i].smartStatus = (status === 'passed' ? 'Ok' : (status === 'failed!' ? 'Predicted Failure' : 'unknown')); + } + } + } + } + } + }); + commitResult(result); + }); + } else { + commitResult(result); } - }); - for (let i = 0; i < result.length; i++) { - delete result[i].BSDName; } - if (callback) { - callback(result); - } - resolve(result); }); - } else { - for (let i = 0; i < result.length; i++) { - delete result[i].BSDName; - } - if (callback) { - callback(result); - } - resolve(result); } }); } diff --git a/lib/index.d.ts b/lib/index.d.ts index 74169d2..6f66e5f 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -123,6 +123,81 @@ export namespace Systeminformation { voltageMax: number; } + interface SmartData { + smartctl: { + version: number[]; + platform_info: string; + build_info: string; + argv: string[]; + exit_status: number; + }; + json_format_version: number[]; + device: { + name: string; + info_name: string; + type: string; + protocol: string; + } + smart_status: { + passed: boolean; + } + ata_smart_attributes: { + revision: number; + table: { + id: number; + name: string; + value: number; + worst: number; + thresh: number; + when_failed: string; + flags: { + value: number; + string: string; + prefailure: boolean; + updated_online: boolean; + performance: boolean; + error_rate: boolean; + event_count: boolean; + auto_keep: boolean; + }; + raw: { value: number; string: string } + }[]; + }; + power_on_time: { + hours: number; + }; + power_cycle_count: number; + temperature: { + current: number; + }; + ata_smart_error_log: { + summary: { + revision: number; + count: number; + }; + }; + ata_smart_self_test_log: { + standard: { + revision: number; + table: { + type: { + value: number; + string: string; + }, + status: { + value: number; + string: string; + passed: boolean; + }, + lifetime_hours: number; + }[]; + count: number; + error_count_total: number; + error_count_outdated: number; + }; + } + } + interface DiskLayoutData { device: string; type: string; @@ -140,6 +215,7 @@ export namespace Systeminformation { serialNum: string; interfaceType: string; smartStatus: string; + smartData?: SmartData; } interface BatteryData { From 586065fd0c62fa4e38974a5571aac30e3ec9566d Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Tue, 12 May 2020 20:44:08 +0200 Subject: [PATCH 2/5] merged get full S.M.A.R.T data, updated docs --- CHANGELOG.md | 1 + README.md | 5 +++-- docs/contributors.html | 1 + docs/filesystem.html | 20 +++++++++++++++++++- docs/general.html | 2 +- docs/history.html | 5 +++++ docs/index.html | 2 +- docs/issues.html | 1 + 8 files changed, 32 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0b5201..3dfd565 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.26.0 | 2020-05-12 | `diskLayout()` added full smart data where supported | | 4.25.2 | 2020-05-12 | `getDynamicData()` added wifiNetworks() | | 4.25.1 | 2020-05-07 | `get()` minor bounds test fix, updated docs | | 4.25.0 | 2020-05-07 | `get()` added function to get partial system info | diff --git a/README.md b/README.md index 9ff3cdf..d53e28f 100644 --- a/README.md +++ b/README.md @@ -87,13 +87,13 @@ si.cpu() (last 7 major and minor version releases) +- Version 4.26.0: `diskLayout()` added full S.M.A.R.T data (linux) - Version 4.25.0: `get()` added function to get partial system info - Version 4.24.0: `networkInterfaces()` added subnet mask ip4 and ip6 - Version 4.23.0: `versions()` added param to specify which program/lib versions to detect - Version 4.22.0: `services()` added pids (windows) - Version 4.21.0: added npx copmpatibility - Version 4.20.0: `battery()` added designcapacity, voltage, unit -- Version 4.19.0: `osInfo()` added uefi (OS uses UEFI during startup) - ... You can find all changes here: [detailed changelog][changelog-url] @@ -382,7 +382,7 @@ I also created a nice little command line tool called [mmon][mmon-github-url] ( | | [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].smartData | X | | | | | S.M.A.R.T data from smartctl - requires at least smartmontools 7.0 (see Known Issues) | +| | [0].smartData | 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 | @@ -802,6 +802,7 @@ Written by Sebastian Hildebrandt [sebhildebrandt](https://github.com/sebhildebra - Nathan Patten [nrpatten](https://github.com/nrpatten) - Juan Campuzano [juancampuzano](https://github.com/juancampuzano) - Ricardo Polo [ricardopolo](https://github.com/ricardopolo) +- Miłosz Dźwigała [mily20001]https://github.com/mily20001 OSX Temperature: credits here are going to: diff --git a/docs/contributors.html b/docs/contributors.html index 2d5cd37..e4be83f 100644 --- a/docs/contributors.html +++ b/docs/contributors.html @@ -60,6 +60,7 @@
  • Nathan Patten nrpatten
  • Juan Campuzano juancampuzano
  • Ricardo Polo ricardopolo
  • +
  • Miłosz Dźwigała mily20001
  • OSX Temperature: credits here are going to: