Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add macOS smartmontools support #935

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ Full function reference with examples can be found at [https://systeminformation
| | [0].serialNum | X | | X | X | | serial number |
| | [0].interfaceType | X | | 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<br>requires at least smartmontools 7.0 |
| | [0].temperature | X | | X | | | S.M.A.R.T temperature |
| | [0].smartData | X | | X | X | | full S.M.A.R.T data from smartctl<br>requires at least smartmontools 7.0 |
| si.blockDevices(cb) | [{...}] | X | | X | X | | returns array of disks, partitions,<br>raids and roms |
| | [0].name | X | | X | X | | name |
| | [0].type | X | | X | X | | type |
Expand Down Expand Up @@ -960,9 +960,9 @@ In some cases we also discovered that `get-WmiObject` returned incorrect tempera
In some cases you need to install the Linux `sensors` package to be able to measure temperature
e.g. on DEBIAN based systems by running `sudo apt-get install lm-sensors`

#### Linux S.M.A.R.T. Status
#### Linux/macOS S.M.A.R.T. Status

To be able to detect S.M.A.R.T. status on Linux you need to install `smartmontools`. On DEBIAN based Linux distributions you can install it by running `sudo apt-get install smartmontools`
To be able to detect S.M.A.R.T. status on Linux or macOS you need to install `smartmontools`. On DEBIAN based Linux distributions you can install it by running `sudo apt-get install smartmontools`. On macOS you can install it via Homebrew by running `brew install smartmontools`.

#### Windows Encoding Issues
I now reimplemented all windows functions to avoid encoding problems (special chacarters). And as Windows 11 now dropped `wmic` support, I had to move completely to `powershell`. Be sure that powershell version 5+ is installed on your machine. On older Windows versions (7, 8) you might still see encoding problems due to the old powershell version.
Expand Down
55 changes: 55 additions & 0 deletions lib/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,7 @@ function diskLayout(callback) {
resolve(result);
}
if (_darwin) {
let cmdFullSmart = '';
exec('system_profiler SPSerialATADataType SPNVMeDataType SPUSBDataType', { maxBuffer: 1024 * 1024 }, function (error, stdout) {
if (!error) {
// split by type:
Expand Down Expand Up @@ -1257,6 +1258,7 @@ function diskLayout(callback) {
BSDName: BSDName
});
cmd = cmd + 'printf "\n' + BSDName + '|"; diskutil info /dev/' + BSDName + ' | grep SMART;';
cmdFullSmart += `${cmdFullSmart ? 'printf ",";' : ''}smartctl -a -j ${BSDName};`;
}
}
});
Expand Down Expand Up @@ -1305,6 +1307,7 @@ function diskLayout(callback) {
BSDName: BSDName
});
cmd = cmd + 'printf "\n' + BSDName + '|"; diskutil info /dev/' + BSDName + ' | grep SMART;';
cmdFullSmart += `${cmdFullSmart ? 'printf ",";' : ''}smartctl -a -j ${BSDName};`;
}
}
});
Expand Down Expand Up @@ -1350,12 +1353,64 @@ function diskLayout(callback) {
BSDName: BSDName
});
cmd = cmd + 'printf "\n' + BSDName + '|"; diskutil info /dev/' + BSDName + ' | grep SMART;';
cmdFullSmart += `${cmdFullSmart ? 'printf ",";' : ''}smartctl -a -j ${BSDName};`;
}
}
});
} catch (e) {
util.noop();
}
// check S.M.A.R.T. status
if (cmdFullSmart) {
exec(cmdFullSmart, { maxBuffer: 1024 * 1024 }, 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'));
if (disk.temperature && disk.temperature.current) {
result[i].temperature = disk.temperature.current;
}
result[i].smartData = disk;
}
}
});
commitResult(result);
} catch (e) {
if (cmd) {
cmd = cmd + 'printf "\n"';
exec(cmd, { maxBuffer: 1024 * 1024 }, 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);
}
}
});
}
if (cmd) {
cmd = cmd + 'printf "\n"';
exec(cmd, { maxBuffer: 1024 * 1024 }, function (error, stdout) {
Expand Down