cpu added flags, virtualization; uuid added hardware
This commit is contained in:
parent
d895c23881
commit
8d01889ac2
@ -200,6 +200,8 @@ I also created a nice little command line tool called [mmon][mmon-github-url] (m
|
||||
| | stepping | X | X | X | X | | processor stepping |
|
||||
| | revision | X | | X | X | | revision |
|
||||
| | voltage | | X | | | | voltage |
|
||||
| | flags | X | X | X | X | | CPU flags |
|
||||
| | virtualization | X | X | X | X | | virtualization supported |
|
||||
| | cache | X | X | X | X | | cache in bytes (object) |
|
||||
| | cache.l1d | X | X | X | X | | L1D (data) size |
|
||||
| | cache.l1i | X | X | X | X | | L1I (instruction) size |
|
||||
@ -324,6 +326,7 @@ I also created a nice little command line tool called [mmon][mmon-github-url] (m
|
||||
| | uefi | X | X | X | X | | OS started via UEFI |
|
||||
| si.uuid(cb) | {...} | X | X | X | X | X | object of several UUIDs |
|
||||
| | os | X | X | X | X | | os specific UUID |
|
||||
| | hardware | X | X | X | X | | hardware specific UUID |
|
||||
| si.versions(apps, cb) | {...} | X | X | X | X | X | version information (kernel, ssl, node, ...)<br />apps param is optional for detecting<br />only specific apps/libs<br />(string, comma separated) |
|
||||
| si.shell(cb) | : string | X | X | X | | | standard shell |
|
||||
| si.users(cb) | [{...}] | X | X | X | X | X | array of users online |
|
||||
|
||||
@ -255,6 +255,26 @@
|
||||
<td></td>
|
||||
<td>voltage</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>flags</td>
|
||||
<td>X</td>
|
||||
<td>X</td>
|
||||
<td>X</td>
|
||||
<td>X</td>
|
||||
<td></td>
|
||||
<td>CPU flags</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>virtualization</td>
|
||||
<td>X</td>
|
||||
<td>X</td>
|
||||
<td>X</td>
|
||||
<td>X</td>
|
||||
<td></td>
|
||||
<td>supports virtualization</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>cache</td>
|
||||
@ -329,8 +349,9 @@ si.cpu().then(data => console.log(data));</code></pre class="example">
|
||||
physicalCores: 8,
|
||||
processors: 1,
|
||||
socket: 'LGA1151',
|
||||
cache: { l1d: 262144, l1i: 262144, l2: 2, l3: 16 },
|
||||
flags: 'fpu vme de pse ...'
|
||||
flags: 'fpu vme de pse ...',
|
||||
virtualization: true,
|
||||
cache: { l1d: 262144, l1i: 262144, l2: 2, l3: 16 }
|
||||
}</pre>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
10
docs/os.html
10
docs/os.html
@ -259,6 +259,16 @@ si.osInfo().then(data => console.log(data));</code></pre class="example">
|
||||
<td></td>
|
||||
<td>os specific UUID</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>hardware</td>
|
||||
<td>X</td>
|
||||
<td>X</td>
|
||||
<td>X</td>
|
||||
<td>X</td>
|
||||
<td></td>
|
||||
<td>hardware specific UUID</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>si.shell(cb)</td>
|
||||
<td>: string</td>
|
||||
|
||||
1
lib/index.d.ts
vendored
1
lib/index.d.ts
vendored
@ -315,6 +315,7 @@ export namespace Systeminformation {
|
||||
|
||||
interface UuidData {
|
||||
os: string;
|
||||
hardware: string;
|
||||
}
|
||||
|
||||
interface VersionData {
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
const exec = require('child_process').exec;
|
||||
const execFile = require('child_process').execFile;
|
||||
const util = require('./util');
|
||||
|
||||
let _platform = process.platform;
|
||||
@ -125,23 +126,23 @@ function inetLatency(host, callback) {
|
||||
}
|
||||
|
||||
host = host || '8.8.8.8';
|
||||
const hostSanitized = util.isPrototypePolluted() ? '8.8.8.8' : util.sanitizeShellString(host);
|
||||
const hostSanitized = (util.isPrototypePolluted() ? '8.8.8.8' : util.sanitizeShellString(host)).trim();
|
||||
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
let cmd;
|
||||
let params;
|
||||
if (_linux || _freebsd || _openbsd || _netbsd || _darwin) {
|
||||
if (_linux) {
|
||||
cmd = 'ping -c 2 -w 3 ' + hostSanitized + ' | grep rtt';
|
||||
params = '-c 2 -w 3 ' + hostSanitized + ' | grep rtt';
|
||||
}
|
||||
if (_freebsd || _openbsd || _netbsd) {
|
||||
cmd = 'ping -c 2 -t 3 ' + hostSanitized + ' | grep round-trip';
|
||||
params = '-c 2 -t 3 ' + hostSanitized + ' | grep round-trip';
|
||||
}
|
||||
if (_darwin) {
|
||||
cmd = 'ping -c 2 -t 3 ' + hostSanitized + ' | grep avg';
|
||||
params = '-c 2 -t 3 ' + hostSanitized + ' | grep avg';
|
||||
}
|
||||
|
||||
exec(cmd, function (error, stdout) {
|
||||
execFile('ping', params.split(' '), function (error, stdout) {
|
||||
let result = null;
|
||||
if (!error) {
|
||||
const line = stdout.toString().split('=');
|
||||
@ -157,7 +158,8 @@ function inetLatency(host, callback) {
|
||||
});
|
||||
}
|
||||
if (_sunos) {
|
||||
exec('ping -s -a ' + hostSanitized + ' 56 2 | grep avg', { timeout: 3000 }, function (error, stdout) {
|
||||
const params = '-s -a ' + hostSanitized + ' 56 2 | grep avg';
|
||||
execFile('ping', params.split(' '), { timeout: 3000 }, function (error, stdout) {
|
||||
let result = null;
|
||||
if (!error) {
|
||||
const line = stdout.toString().split('=');
|
||||
@ -175,7 +177,8 @@ function inetLatency(host, callback) {
|
||||
if (_windows) {
|
||||
let result = null;
|
||||
try {
|
||||
exec('ping ' + hostSanitized + ' -n 1', util.execOptsWin, function (error, stdout) {
|
||||
const params = hostSanitized + ' -n 1';
|
||||
execFile('ping', params.split(' '), util.execOptsWin, function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\r\n');
|
||||
lines.shift();
|
||||
|
||||
@ -957,7 +957,8 @@ function uuid(callback) {
|
||||
process.nextTick(() => {
|
||||
|
||||
let result = {
|
||||
os: ''
|
||||
os: '',
|
||||
hardware: ''
|
||||
};
|
||||
let parts;
|
||||
|
||||
@ -984,10 +985,13 @@ function uuid(callback) {
|
||||
});
|
||||
}
|
||||
if (_linux) {
|
||||
exec('( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :', function (error, stdout) {
|
||||
if (!error) {
|
||||
result.os = stdout.toString().split('\n')[0].trim().toLowerCase();
|
||||
}
|
||||
const cmd = `echo -n "os: "; cat /var/lib/dbus/machine-id 2> /dev/null; echo;
|
||||
echo -n "os: "; cat /etc/machine-id 2> /dev/null; echo;
|
||||
echo -n "machine: "; cat /sys/class/dmi/id/product_uuid 2> /dev/null; echo;`;
|
||||
exec(cmd, function (error, stdout) {
|
||||
const lines = stdout.toString.split('\n');
|
||||
result.os = util.getValue(lines, 'os').toLowerCase();
|
||||
result.hardware = util.getValue(lines, 'hardware').toLowerCase();
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
@ -995,10 +999,14 @@ function uuid(callback) {
|
||||
});
|
||||
}
|
||||
if (_freebsd || _openbsd || _netbsd) {
|
||||
exec('kenv -q smbios.system.uuid', function (error, stdout) {
|
||||
if (!error) {
|
||||
result.os = stdout.toString().split('\n')[0].trim().toLowerCase();
|
||||
}
|
||||
const cmd = `echo -n "os: "; sysctl -n kern.hostid; echo;
|
||||
echo -n "hardware: "; sysctl -n kern.hostuuid; echo;`;
|
||||
exec(cmd, function (error, stdout) {
|
||||
const lines = stdout.toString.split('\n');
|
||||
result.os = util.getValue(lines, 'os').toLowerCase();
|
||||
result.hardware = util.getValue(lines, 'hardware').toLowerCase();
|
||||
if (result.os.indexOf('unknown') >= 0) { result.os = ''; }
|
||||
if (result.hardware.indexOf('unknown') >= 0) { result.hardware = ''; }
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
@ -1007,15 +1015,18 @@ function uuid(callback) {
|
||||
}
|
||||
if (_windows) {
|
||||
exec('%windir%\\System32\\reg query "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography" /v MachineGuid', util.execOptsWin, function (error, stdout) {
|
||||
if (!error) {
|
||||
parts = stdout.toString().split('\n\r')[0].split('REG_SZ');
|
||||
result.os = parts.length > 1 ? parts[1].replace(/\r+|\n+|\s+/ig, '').toLowerCase() : '';
|
||||
}
|
||||
util.wmic('csproduct get /value').then((stdout) => {
|
||||
// let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0)[0].trim().split(/\s\s+/);
|
||||
let lines = stdout.split('\r\n');
|
||||
result.hardware = util.getValue(lines, 'uuid', '=').toLowerCase();
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -18,6 +18,8 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const exec = require('child_process').exec;
|
||||
const execSync = require('child_process').execSync;
|
||||
const execFile = require('child_process').execFile;
|
||||
|
||||
|
||||
const util = require('./util');
|
||||
|
||||
@ -971,7 +973,8 @@ function processLoad(proc, callback) {
|
||||
}
|
||||
|
||||
if (_darwin || _linux) {
|
||||
exec('ps -axo pid,pcpu,pmem,comm | grep -i ' + procSanitized + ' | grep -v grep', { maxBuffer: 1024 * 20000 }, function (error, stdout) {
|
||||
const params = '-axo pid,pcpu,pmem,comm | grep -i ' + procSanitized + ' | grep -v grep';
|
||||
execFile('ps', params.split(' '), { maxBuffer: 1024 * 20000 }, function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
|
||||
|
||||
@ -77,7 +77,7 @@ function system(callback) {
|
||||
if (!result.sku || result.sku.toLowerCase().indexOf('o.e.m.') !== -1) result.sku = '-';
|
||||
|
||||
// detect virtual (1)
|
||||
if (result.model.toLowerCase() === 'virtualbox' || result.model.toLowerCase() === 'kvm' || result.model.toLowerCase() === 'virtual machine' || result.model.toLowerCase() === 'bochs' || result.model.toLowerCase().startsWith('vmware')) {
|
||||
if (result.model.toLowerCase() === 'virtualbox' || result.model.toLowerCase() === 'kvm' || result.model.toLowerCase() === 'virtual machine' || result.model.toLowerCase() === 'bochs' || result.model.toLowerCase().startsWith('vmware') || result.model.toLowerCase().startsWith('droplet')) {
|
||||
result.virtual = true;
|
||||
switch (result.model.toLowerCase()) {
|
||||
case 'virtualbox':
|
||||
@ -124,13 +124,12 @@ function system(callback) {
|
||||
if (fs.existsSync('/.dockerenv') || fs.existsSync('/.dockerinit')) {
|
||||
result.model = 'Docker Container';
|
||||
}
|
||||
if (result.manufacturer === '' && result.model === 'Computer' && result.version === '') { // still default values
|
||||
exec('dmesg | grep -iE "virtual|hypervisor" | grep -iE "vmware|qemu|kvm|xen"', function (error, stdout) {
|
||||
try {
|
||||
const stdout = execSync('dmesg | grep -iE "virtual|hypervisor" | grep -iE "vmware|qemu|kvm|xen"')
|
||||
// detect virtual machines
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
if (lines.length > 0) {
|
||||
result.model = 'Virtual machine';
|
||||
if (result.model === 'Computer') { result.model = 'Virtual machine'; }
|
||||
result.virtual = true;
|
||||
if (stdout.toString().toLowerCase().indexOf('vmware') && !result.virtualHost) {
|
||||
result.virtualHost = 'VMware';
|
||||
@ -145,7 +144,10 @@ function system(callback) {
|
||||
result.virtualHost = 'KVM';
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
util.noop();
|
||||
}
|
||||
|
||||
if (result.manufacturer === '' && result.model === 'Computer' && result.version === '') {
|
||||
// Check Raspberry Pi
|
||||
fs.readFile('/proc/cpuinfo', function (error, stdout) {
|
||||
@ -287,11 +289,6 @@ function system(callback) {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (_darwin) {
|
||||
exec('ioreg -c IOPlatformExpertDevice -d 2', function (error, stdout) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user