systeminformation
Advanced tools
Comparing version 3.24.0 to 3.25.0
@@ -101,2 +101,3 @@ # Changelog | ||
| -------------- | -------------- | -------- | | ||
| 3.25.0 | 2017-08-07 | improved windows support `networkStats()`, `cpuCache()`, bug fix `getStaticData()` | | ||
| 3.24.0 | 2017-08-05 | extended windows support `networkStats()`, `networkConnections()` | | ||
@@ -103,0 +104,0 @@ | 3.23.7 | 2017-07-11 | bug fix `diskLayout()` | |
@@ -170,2 +170,4 @@ 'use strict'; | ||
result.revision = getValue(lines, 'revision', '='); | ||
result.cache.l1d = 0; | ||
result.cache.l1i = 0; | ||
result.cache.l2 = getValue(lines, 'l2cachesize', '='); | ||
@@ -192,3 +194,21 @@ result.cache.l3 = getValue(lines, 'l3cachesize', '='); | ||
} | ||
resolve(result); | ||
exec("wmic path Win32_CacheMemory get CacheType,InstalledSize,Purpose", function (error, stdout) { | ||
if (!error) { | ||
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0); | ||
lines.forEach(function (line) { | ||
if (line !== '') { | ||
line = line.trim().split(/\s\s+/); | ||
// L1 Instructions | ||
if (line[2] === 'L1 Cache' && line[0] === '3') { | ||
result.cache.l1i = parseInt(line[1], 10) | ||
} | ||
// L1 Data | ||
if (line[2] === 'L1 Cache' && line[0] === '4') { | ||
result.cache.l1d = parseInt(line[1], 10) | ||
} | ||
} | ||
}); | ||
} | ||
resolve(result); | ||
}) | ||
}) | ||
@@ -379,9 +399,8 @@ } | ||
process.nextTick(() => { | ||
let result = ''; | ||
if (_windows) { | ||
let error = new Error(NOT_SUPPORTED); | ||
if (callback) { callback(NOT_SUPPORTED) } | ||
reject(error); | ||
if (callback) { callback(result) } | ||
resolve(result); | ||
} | ||
let result = ''; | ||
if (_linux) { | ||
@@ -480,2 +499,4 @@ exec("lscpu", function (error, stdout) { | ||
let lines = stdout.split('\r\n'); | ||
result.l1d = 0; | ||
result.l1i = 0; | ||
result.l2 = getValue(lines, 'l2cachesize', '='); | ||
@@ -486,4 +507,22 @@ result.l3 = getValue(lines, 'l3cachesize', '='); | ||
} | ||
if (callback) { callback(result) } | ||
resolve(result); | ||
exec("wmic path Win32_CacheMemory get CacheType,InstalledSize,Purpose", function (error, stdout) { | ||
if (!error) { | ||
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0); | ||
lines.forEach(function (line) { | ||
if (line !== '') { | ||
line = line.trim().split(/\s\s+/); | ||
// L1 Instructions | ||
if (line[2] === 'L1 Cache' && line[0] === '3') { | ||
result.l1i = parseInt(line[1], 10) | ||
} | ||
// L1 Data | ||
if (line[2] === 'L1 Cache' && line[0] === '4') { | ||
result.l1d = parseInt(line[1], 10) | ||
} | ||
} | ||
}); | ||
} | ||
if (callback) { callback(result) } | ||
resolve(result); | ||
}) | ||
}) | ||
@@ -490,0 +529,0 @@ } |
'use strict'; | ||
// ================================================================================== | ||
// dockerSockets.js | ||
// ---------------------------------------------------------------------------------- | ||
// Description: System Information - library | ||
// for Node.js | ||
// Copyright: (c) 2014 - 2017 | ||
// Author: Sebastian Hildebrandt | ||
// ---------------------------------------------------------------------------------- | ||
// License: MIT | ||
// ================================================================================== | ||
// 13. DockerSockets | ||
// ---------------------------------------------------------------------------------- | ||
@@ -3,0 +15,0 @@ const net = require('net'); |
@@ -26,2 +26,5 @@ 'use strict'; | ||
const NOT_SUPPORTED = 'not supported'; | ||
let _resolutionx = 0; | ||
let _resolutiony = 0; | ||
let _pixeldepth = 0; | ||
@@ -42,2 +45,10 @@ function getValue(lines, property, separator) { | ||
function toInt(value) { | ||
let result = parseInt(value,10); | ||
if (isNaN(result)) { | ||
result = 0; | ||
} | ||
return result | ||
} | ||
function graphics(callback) { | ||
@@ -318,3 +329,3 @@ | ||
// https://blogs.technet.microsoft.com/heyscriptingguy/2013/10/03/use-powershell-to-discover-multi-monitor-information/ | ||
exec("wmic path win32_VideoController get AdapterCompatibility, AdapterDACType, name, PNPDeviceID, CurrentVerticalResolution, CurrentHorizontalResolution, CurrentNumberOfColors, AdapterRAM, CurrentBitsPerPixel, CurrentRefreshRate, MinRefreshRate, MaxRefreshRate /value", function (error, stdout) { | ||
exec("wmic path win32_VideoController get AdapterCompatibility, AdapterDACType, name, PNPDeviceID, CurrentVerticalResolution, CurrentHorizontalResolution, CurrentNumberOfColors, AdapterRAM, CurrentBitsPerPixel, CurrentRefreshRate, MinRefreshRate, MaxRefreshRate, VideoMemoryType /value", function (error, stdout) { | ||
if (!error) { | ||
@@ -327,2 +338,13 @@ let csections = stdout.split(/\n\s*\n/); | ||
result.displays = parseLinesWindowsDisplays(dsections); | ||
if (result.controllers.length === 1 && result.displays.length === 1) { | ||
if (_resolutionx && !result.displays[0].resolutionx) { | ||
result.displays[0].resolutionx = _resolutionx | ||
} | ||
if (_resolutiony && !result.displays[0].resolutiony) { | ||
result.displays[0].resolutiony = _resolutiony | ||
} | ||
if (_pixeldepth) { | ||
result.displays[0].pixeldepth = _pixeldepth | ||
} | ||
} | ||
} | ||
@@ -337,3 +359,2 @@ if (callback) { | ||
} | ||
}); | ||
@@ -353,4 +374,8 @@ }); | ||
bus: getValue(lines, 'PNPDeviceID', '=').startsWith('PCI') ? 'PCI' : '', | ||
vram: getValue(lines, 'AdapterRAM', '=') | ||
vram: getValue(lines, 'AdapterRAM', '='), | ||
vramDynamic: (getValue(lines, 'VideoMemoryType', '=') === '2') | ||
}); | ||
_resolutionx = toInt(getValue(lines, 'CurrentHorizontalResolution', '=')); | ||
_resolutiony = toInt(getValue(lines, 'CurrentVerticalResolution', '=')); | ||
_pixeldepth = toInt(getValue(lines, 'CurrentBitsPerPixel', '=')); | ||
} | ||
@@ -370,4 +395,4 @@ } | ||
model: getValue(lines, 'MonitorManufacturer', '='), | ||
resolutionx: getValue(lines, 'ScreenWidth', '='), | ||
resolutiony: getValue(lines, 'ScreenHeight', '=') | ||
resolutionx: toInt(getValue(lines, 'ScreenWidth', '=')), | ||
resolutiony: toInt(getValue(lines, 'ScreenHeight', '=')), | ||
}); | ||
@@ -374,0 +399,0 @@ } |
@@ -31,2 +31,16 @@ 'use strict'; | ||
function getValue(lines, property, separator) { | ||
separator = separator || ':'; | ||
property = property.toLowerCase(); | ||
for (let i = 0; i < lines.length; i++) { | ||
if (lines[i].toLowerCase().startsWith(property)) { | ||
const parts = lines[i].split(separator); | ||
if (parts.length > 1) { | ||
return parts[1].trim(); | ||
} | ||
} | ||
} | ||
return ''; | ||
} | ||
function getDefaultNetworkInterface() { | ||
@@ -36,2 +50,3 @@ | ||
let ifacename = ''; | ||
let scopeid = 9999; | ||
if (_linux || _darwin) { | ||
@@ -43,12 +58,20 @@ let cmd = (_linux ? "route 2>/dev/null | grep default | awk '{print $8}'" : "route get 0.0.0.0 2>/dev/null | grep interface: | awk '{print $2}'"); | ||
if (!ifacename) { // fallback - "first" external interface | ||
const sortObject = o => Object.keys(o).sort().reduce((r, k) => (r[k] = o[k], r), {}); | ||
if (!ifacename) { // fallback - "first" external interface (sorted by scopeid) | ||
let ifaces = sortObject(os.networkInterfaces()); | ||
const compare = function(a,b) { | ||
if (a.scopeid < b.scopeid) | ||
return -1; | ||
if (a.scopeid > b.scopeid) | ||
return 1; | ||
return 0; | ||
} | ||
let ifaces = os.networkInterfaces(); | ||
for (let dev in ifaces) { | ||
if (ifaces.hasOwnProperty(dev)) { | ||
ifaces[dev].forEach(function (details) { | ||
if (details && details.internal === false) { | ||
ifacename = ifacename || dev; | ||
if (details && details.internal === false && details.scopeid && details.scopeid < scopeid) { | ||
ifacename = dev; | ||
scopeid = details.scopeid; | ||
} | ||
@@ -70,8 +93,2 @@ }) | ||
process.nextTick(() => { | ||
if (_windows) { | ||
let error = new Error(NOT_SUPPORTED); | ||
if (callback) { callback(NOT_SUPPORTED) } | ||
reject(error); | ||
} | ||
let result = getDefaultNetworkInterface(); | ||
@@ -164,2 +181,42 @@ if (callback) { callback(result) } | ||
function parseLinesWindowsNics(sections){ | ||
let nics = []; | ||
for (let i in sections) { | ||
if (sections.hasOwnProperty(i)) { | ||
if (sections[i].trim() !== "") { | ||
let lines = sections[i].trim().split('\r\n'); | ||
let netEnabled = getValue(lines, 'NetEnabled', '='); | ||
if (netEnabled) { | ||
nics.push({ | ||
mac: getValue(lines, 'MACAddress', '=').toLowerCase(), | ||
name: getValue(lines, 'Name', '=').replace(/[()\[\] ]+/g, "").toLowerCase(), | ||
netEnabled: netEnabled === 'TRUE' | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
return nics; | ||
} | ||
function parseLinesWindowsPerfData(sections){ | ||
let perfData = []; | ||
for (let i in sections) { | ||
if (sections.hasOwnProperty(i)) { | ||
if (sections[i].trim() !== "") { | ||
let lines = sections[i].trim().split('\r\n'); | ||
perfData.push({ | ||
name: getValue(lines, 'Name', '=').replace(/[()\[\] ]+/g, "").toLowerCase(), | ||
rx: parseInt(getValue(lines, 'BytesReceivedPersec', '='),10), | ||
tx: parseInt(getValue(lines, 'BytesSentPersec', '='),10) | ||
}); | ||
} | ||
} | ||
} | ||
return perfData; | ||
} | ||
// fallback - if only callback is given | ||
@@ -176,5 +233,2 @@ if (util.isFunction(iface) && !callback) { | ||
iface = iface || _default_iface; // (_darwin ? 'en0' : 'eth0'); | ||
if (_windows) { | ||
iface = 'all' | ||
} | ||
@@ -248,17 +302,56 @@ let result = { | ||
if (_windows) { | ||
cmd = "netstat -e"; | ||
// NICs | ||
let perfData = []; | ||
let nics = []; | ||
cmd = "wmic nic get MACAddress, name, NetEnabled /value"; | ||
exec(cmd, function (error, stdout) { | ||
const lines = stdout.split('\r\n'); | ||
for (let i = 0; i < lines.length; i++) { | ||
if (lines[i].toLowerCase().startsWith('bytes')) { | ||
const parts = lines[i].substr(5).trim().replace(/ +/g, " ").split(' '); | ||
if (parts.length > 1) { | ||
rx = parseInt(parts[0]); | ||
tx = parseInt(parts[1]); | ||
result = calcNetworkSpeed(iface, rx, tx, operstate); | ||
if (!error) { | ||
const nsections = stdout.split(/\n\s*\n/); | ||
nics = parseLinesWindowsNics(nsections); | ||
// Performance Data | ||
cmd = "wmic path Win32_PerfRawData_Tcpip_NetworkInterface Get name,BytesReceivedPersec,BytesSentPersec,BytesTotalPersec /value"; | ||
exec(cmd, function (error, stdout) { | ||
if (!error) { | ||
const psections = stdout.split(/\n\s*\n/); | ||
perfData = parseLinesWindowsPerfData(psections); | ||
} | ||
} | ||
// Network Interfaces | ||
networkInterfaces().then(interfaces => { | ||
// get mac from 'interfaces' by interfacename | ||
let mac = ''; | ||
interfaces.forEach(detail => { | ||
if (detail.iface === iface) { | ||
mac = detail.mac; | ||
} | ||
}) | ||
// get name from 'nics' (by macadress) | ||
let name = ''; | ||
nics.forEach(detail => { | ||
if (detail.mac === mac) { | ||
name = detail.name; | ||
operstate = (detail.netEnabled ? 'up' : 'down') | ||
} | ||
}) | ||
// get bytes sent, received from perfData by name | ||
rx = 0; | ||
tx = 0; | ||
perfData.forEach(detail => { | ||
if (detail.name === name) { | ||
rx = detail.rx; | ||
tx = detail.tx; | ||
} | ||
}); | ||
if (rx && tx) { | ||
result = calcNetworkSpeed(iface, parseInt(rx), parseInt(tx), operstate); | ||
} | ||
if (callback) { callback(result) } | ||
resolve(result); | ||
}) | ||
}) | ||
} | ||
if (callback) { callback(result) } | ||
resolve(result); | ||
}); | ||
@@ -265,0 +358,0 @@ } |
{ | ||
"name": "systeminformation", | ||
"version": "3.24.0", | ||
"version": "3.25.0", | ||
"description": "Simple system and OS information library", | ||
@@ -31,2 +31,3 @@ "license": "MIT", | ||
"network connections", | ||
"network stats", | ||
"processes", | ||
@@ -33,0 +34,0 @@ "users", |
@@ -44,2 +44,3 @@ # systeminformation | ||
### Latest Activity | ||
- Version 3.25.0: improved windows support `networkStats()`, `cpuCache()`, bug fix `getStaticData()` | ||
- Version 3.24.0: extended windows support `networkStats()`, `networkConnections()` | ||
@@ -132,4 +133,4 @@ - Version 3.23.0: added `memLayout`, `diskLayout`, extended windows support (`inetChecksite`) | ||
| | cache | X | X | X | cache in bytes (object) | | ||
| | cache.l1d | X | X | | L1D size | | ||
| | cache.l1i | X | X | | L1I size | | ||
| | cache.l1d | X | X | | L1D (data) size | | ||
| | cache.l1i | X | X | | L1I (instruction) size | | ||
| | cache.l2 | X | X | X | L2 size | | ||
@@ -151,5 +152,5 @@ | | cache.l3 | X | X | X | L3 size | | ||
| | max | X | X | X | max temperature | | ||
| si.mem(cb) | {...} | X | X | X | Memory information| | ||
| | total | X | X | X | total memory | | ||
| | free | X | X | X | not used | | ||
| si.mem(cb) | {...} | X | X | X | Memory information (in bytes)| | ||
| | total | X | X | X | total memory in bytes | | ||
| | free | X | X | X | not used in bytes | | ||
| | used | X | X | X | used (incl. buffers/cache) | | ||
@@ -200,4 +201,4 @@ | | active | X | X | X | used actively (excl. buffers/cache) | | ||
| | controllers[0].vram | X | X | X | VRAM size (in MB) | | ||
| | controllers[0].vramDynamic | X | X | | true if dynamicly allocated ram | | ||
| | displays[0].model | X | X | | Monitor/Display Model | | ||
| | controllers[0].vramDynamic | X | X | X | true if dynamicly allocated ram | | ||
| | displays[0].model | X | X | X | Monitor/Display Model | | ||
| | displays[0].main | X | X | | true if main monitor | | ||
@@ -208,3 +209,3 @@ | | displays[0].builtin | X | X | | true if built in monitor | | ||
| | displays[0].resolutiony | X | X | X | pixel vertical | | ||
| | displays[0].depth | X | X | X | color depth in bits | | ||
| | displays[0].pixeldepth | X | X | X | color depth in bits | | ||
| | displays[0].sizex | X | X | | size in mm horizontal | | ||
@@ -288,5 +289,5 @@ | | displays[0].sizey | X | X | | size in mm vertical | | ||
| si.networkInterfaceDefault(cb) | : string | X | X | X | get name of default network interface | | ||
| si.networkStats(iface,cb) | {...} | X | X | X | current network stats of given interface<br>iface parameter is optional<br>defaults to first external network interface<br>Windows: no iface, only overall stats!| | ||
| | iface | X | X | | interface (Windows: only overall stats)| | ||
| | operstate | X | X | | up / down | | ||
| si.networkStats(iface,cb) | {...} | X | X | X | current network stats of given interface<br>iface parameter is optional<br>defaults to first external network interface| | ||
| | iface | X | X | X | interface | | ||
| | operstate | X | X | X | up / down | | ||
| | rx | X | X | X | received bytes overall | | ||
@@ -293,0 +294,0 @@ | | tx | X | X | X | transferred bytes overall| |
219074
4599
571