From b2b9f7928ff9e8786b8fb75e29ff7ebb7c61e4ad Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Sun, 19 Feb 2017 08:53:58 +0100 Subject: [PATCH] very firet windows functions, extended processes list --- CHANGELOG.md | 1 + README.md | 444 ++++++++++++++++++++++++---------------------- lib/cpu.js | 56 ++++-- lib/filesystem.js | 105 +++++++---- lib/index.js | 1 + lib/memory.js | 5 - lib/osinfo.js | 155 +++++++++++----- lib/processes.js | 197 +++++++++++--------- lib/system.js | 19 +- package.json | 4 +- 10 files changed, 582 insertions(+), 405 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd8acd6..18fb591 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -94,6 +94,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.17.0 | 2017-02-19 | windows support for some first functions, extended process list (linux)| | 3.16.0 | 2017-01-19 | blockDevices: added removable attribute + fix | | 3.15.1 | 2017-01-17 | minor cpuTemperature fix (OSX) | | 3.15.0 | 2017-01-15 | added cpuTemperature also for OSX | diff --git a/README.md b/README.md index 90fe4e6..d9fe6a2 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Simple system and OS information library for [node.js][nodejs-url] ## Quick Start -Collection of 30+ functions to retrieve detailed hardware, system and OS information (linux and OSX only) +Collection of 30+ functions to retrieve detailed hardware, system and OS information (Linux, OSX and now partial Windows support) ### Installation @@ -42,6 +42,7 @@ si.cpu() ### Latest Activity +- Version 3.17.0: windows support for some very first functions (work in progress) - Version 3.16.0: `blockDevices`: added removable attribute - Version 3.15.0: added `cpuTemperature` also for OSX - Version 3.14.0: added `currentLoad` per cpu/core, cpu cache (L1, L2, L3) and cpu flags @@ -71,7 +72,8 @@ little library. This library is still work in progress. Version 3 comes with fur requires now node.js version 4.0 and above. Another big change is, that all functions now return promises. You can use them like before with callbacks OR with promises (see example in this documentation). I am sure, there is for sure room for improvement. I was only able to test it on several Debian, Raspbian, Ubuntu distributions as well as OS X (Mavericks, Yosemite, El Captain). -Since version 2 nearly all functionality is available on OS X/Darwin platforms. But be careful, this library will definitely NOT work on Windows platforms! +Since version 2 nearly all functionality is available on OS X/Darwin platforms. +Be careful, this library has only very limited Windows support! If you have comments, suggestions & reports, please feel free to contact me! @@ -99,219 +101,231 @@ This library is splitted in several sections: ### Function Reference and OS Support -| Function | Linux | OS X | Comments | -| -------------- | ------ | ------ | ------- | -| si.version() | X | X | library version (no callback/promise) | -| si.time() | X | X | time information (no callback/promise) | -| - current | X | X | local time | -| - uptime | X | X | uptime | -| si.system(cb) | X | X | hardware information | -| - manufacturer | X | X | e.g. 'MSI' | -| - model | X | X | model/product e.g. 'MS-7823' | -| - version | X | X | version e.g. '1.0' | -| - serial | X | X | serial number | -| - uuid | X | X | UUID | -| si.osInfo(cb) | X | X | OS information | -| - platform | X | X | 'Linux' or 'Darwin' | -| - distro | X | X | | -| - release | X | X | | -| - codename | | X | | -| - kernel | X | X | kernel release - same as os.release() | -| - arch | X | X | same as os.arch() | -| - hostname | X | X | same as os.hostname() | -| - logofile | X | X | e.g. 'apple', 'debian', 'fedora', ... | -| si.versions(cb) | X | X | Version information (kernel, ssl, node, ...) | -| si.shell(cb) | X | X | standard shell | -| si.cpu(cb) | X | X | CPU information| -| - manufacturer | X | X | e.g. 'Intel(R)' | -| - brand | X | X | e.g. 'Core(TM)2 Duo' | -| - speed | X | X | in GHz e.g. '3.40' | -| - cores | X | X | # cores | -| si.cpuFlags(cb) | X | X | CPU flags| -| si.cpuCache(cb) | X | X | CPU cache sizes | -| - l1d | X | X | L1D size | -| - l1i | X | X | L1I size | -| - l2 | X | X | L2 size | -| - l3 | X | X | L3 size | -| si.cpuCurrentspeed(cb) | X | X | current CPU speed (in GHz)| -| - avg | X | X | avg CPU speed (all cores) | -| - min | X | X | min CPU speed (all cores) | -| - max | X | X | max CPU speed (all cores) | -| si.cpuTemperature(cb) | X | X | CPU temperature (if sensors is installed) | -| - main | X | X | main temperature | -| - cores | X | X | array of temperatures | -| - max | X | X | max temperature | -| si.mem(cb) | X | X | Memory information| -| - total | X | X | total memory | -| - free | X | X | not used | -| - used | X | X | used (incl. buffers/cache) | -| - active | X | X | used actively (excl. buffers/cache) | -| - buffcache | X | X | used by buffers+cache | -| - available | X | X | potentially available (total - active) | -| - swaptotal | X | X | | -| - swapused | X | X | | -| - swapfree | X | X | | -| si.battery(cb) | X | X | battery information | -| - hasbattery | X | X | indicates presence of battery | -| - ischarging | X | X | indicates if battery is charging | -| - maxcapacity | X | X | max capacity of battery | -| - currentcapacity | X | X | current capacity of battery | -| - percent | X | X | charging level in percent | -| si.graphics(cb) | X | X | arrays of graphics controllers and displays | -| - controllers[0].model | X | X | graphics controller model | -| - controllers[0].vendor | X | X | e.g. ATI | -| - controllers[0].bus | X | X | on which bus (e.g. PCIe) | -| - controllers[0].vram | X | X | VRAM size (in MB) | -| - controllers[0].vramDynamic | X | X | true if dynamicly allocated ram | -| - displays[0].model | X | X | Monitor/Display Model | -| - displays[0].main | X | X | true if main monitor | -| - displays[0].builtin | X | X | true if built in monitor | -| - displays[0].connection | X | X | e.g. DisplayPort or HDMI | -| - displays[0].resolutionx | X | X | pixel horizontal | -| - displays[0].resolutiony | X | X | pixel vertical | -| - displays[0].depth | X | X | color depth in bits | -| - displays[0].sizex | X | X | size in mm horizontal | -| - displays[0].sizey | X | X | size in mm vertical | -| si.fsSize(cb) | X | X | returns array of mounted file systems | -| - [0].fs | X | X | name of file system | -| - [0].type | X | X | type of file system | -| - [0].size | X | X | sizes in Bytes | -| - [0].used | X | X | used in Bytes | -| - [0].use | X | X | used in % | -| - [0].mount | X | X | mount point | -| si.blockDevices(cb) | X | X | returns array of disks, partitions,
raids and roms | -| - [0].name | X | X | name | -| - [0].type | X | X | type | -| - [0].fstype | X | X | file system type (e.g. ext4) | -| - [0].mount | X | X | mount point | -| - [0].size | X | X | size in bytes | -| - [0].physical | X | X | physical type (HDD, SSD, CD/DVD) | -| - [0].uuid | X | X | UUID | -| - [0].label | X | X | label | -| - [0].model | X | X | model | -| - [0].serial | X | | serial | -| - [0].removable | X | X | serial | -| - [0].protocol | X | X | protocol (SATA, PCI-Express, ...) | -| 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) | -| 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) | -| - ms | X | X | interval length (for per second values) | -| si.networkInterfaces(cb) | X | X | array of network interfaces | -| - [0].iface | X | X | interface name | -| - [0].ip4 | X | X | ip4 address | -| - [0].ip6 | X | X | ip6 address | -| - [0].mac | X | X | MAC address | -| - [0].internal | X | X | true if internal interface | -| si.networkInterfaceDefault(cb) | X | X | get name of default network interface | -| si.networkStats(iface,cb) | X | X | current network stats of given interface
iface parameter is optional
defaults to first external network interface| -| - iface | X | X | interface | -| - operstate | X | X | up / down | -| - rx | X | X | received bytes overall | -| - tx | X | X | transferred bytes overall| -| - rx_sec | X | X | received bytes / second (* see notes) | -| - tx_sec | X | X | transferred bytes per second (* see notes) | -| - ms | X | X | interval length (for per second values) | -| si.networkConnections(cb) | X | X | current network network connections
returns an array of all connections| -| - [0].protocol | X | X | tcp or udp | -| - [0].localaddress | X | X | local address | -| - [0].localport | X | X | local port | -| - [0].peeraddress | X | X | peer address | -| - [0].peerport | X | X | peer port | -| - [0].state | X | X | like ESTABLISHED, TIME_WAIT, ... | -| si.currentLoad(cb) | X | X | CPU-Load | -| - avgload | X | X | average load | -| - currentload | X | X | CPU-Load in % | -| - currentload_user | X | X | CPU-Load User in % | -| - currentload_nice | X | X | CPU-Load Nice in % | -| - currentload_system | X | X | CPU-Load System in % | -| - currentload_irq | X | X | CPU-Load System in % | -| - cpus[] | X | X | current loads per CPU in % | -| si.fullLoad(cb) | X | X | CPU-full load since bootup in % | -| si.services('mysql, apache2', cb) | X | X | pass comma separated string of services | -| - [0].name | X | X | name of service | -| - [0].running | X | X | true / false | -| - [0].pcpu | X | X | process % CPU | -| - [0].pmem | X | X | process % MEM | -| si.processes(cb) | X | X | # running processes | -| - all | X | X | # of all processes | -| - running | X | X | # of all processes running | -| - blocked | X | X | # of all processes blocked | -| - sleeping | X | X | # of all processes sleeping | -| - list | X | X | # list of all processes incl. details | -| si.processLoad('apache2',cb) | X | X | detailed information about given process | -| - proc | X | X | process name | -| - pid | X | X | PID | -| - cpu | X | X | process % CPU | -| - mem | X | X | process % MEM | -| si.users(cb) | X | X | array of users online | -| - [0].user | X | X | user name | -| - [0].tty | X | X | terminal | -| - [0].date | X | X | login date | -| - [0].time | X | X | login time | -| - [0].ip | X | X | ip address (remote login) | -| - [0].command | X | X | last command or shell | -| si.inetChecksite(url, cb) | X | X | response-time (ms) to fetch given URL | -| - url | X | X | given url | -| - ok | X | X | status code OK (2xx, 3xx) | -| - status | X | X | status code | -| - ms | X | X | response time in ms | -| si.inetLatency(host, cb) | X | X | response-time (ms) to external resource
host parameter is optional (default 8.8.8.8)| -| si.dockerContainers(all, cb) | X | X | returns array of active/all docker containers | -| - [0].id | X | X | ID of container | -| - [0].name | X | X | name of container | -| - [0].image | X | X | name of image | -| - [0].imageID | X | X | ID of image | -| - [0].command | X | X | command | -| - [0].created | X | X | creation time | -| - [0].state | X | X | created, running, exited | -| - [0].ports | X | X | array of ports | -| - [0].mounts | X | X | array of mounts | -| si.dockerContainerStats(id, cb) | X | X | statistics for a specific container | -| - id | X | X | Container ID | -| - mem_usage | X | X | memory usage in bytes | -| - mem_limit | X | X | memory limit (max mem) in bytes | -| - mem_percent | X | X | memory usage in percent | -| - cpu_percent | X | X | cpu usage in percent | -| - pids | X | X | number of processes | -| - netIO.rx | X | X | received bytes via network | -| - netIO.wx | X | X | sent bytes via network | -| - blockIO.r | X | X | bytes read from BlockIO | -| - blockIO.w | X | X | bytes written to BlockIO | -| - cpu_stats | X | X | detailed cpu stats | -| - percpu_stats | X | X | detailed per cpu stats | -| - memory_stats | X | X | detailed memory stats | -| - networks | X | X | detailed network stats per interface | -| si.dockerContainerProcesses(id, cb) | X | X | array of processes inside a container | -| - [0].pid_host | X | X | process ID (host) | -| - [0].ppid | X | X | parent process ID | -| - [0].pgid | X | X | process group ID | -| - [0].user | X | X | effective user name | -| - [0].ruser | X | X | real user name | -| - [0].group | X | X | effective group name | -| - [0].rgroup | X | X | real group name | -| - [0].stat | X | X | process state | -| - [0].time | X | X | accumulated CPU time | -| - [0].elapsed | X | X | elapsed running time | -| - [0].nice | X | X | nice value | -| - [0].rss | X | X | resident set size | -| - [0].vsz | X | X | virtual size in Kbytes | -| - [0].command | X | X | command and arguments | -| si.dockerAll(cb) | X | X | list of all containers including their stats
and processes in one single array | -| si.getStaticData(cb) | X | X | all static data at once | -| si.getDynamicData(srv,iface,cb) | X | X | all dynamic data at once | -| si.getAllData(srv,iface,cb) | X | X | all data at once | +| Function | Linux | OSX | Win | Comments | +| --------------- | ----- | ---- | ------- | -------- | +| si.version() | X | X | X | library version (no callback/promise) | +| si.time() | X | X | X | time information (no callback/promise) | +| - current | X | X | X | local time | +| - uptime | X | X | X | uptime | +| si.system(cb) | X | X | X | hardware information | +| - manufacturer | X | X | X | e.g. 'MSI' | +| - model | X | X | X | model/product e.g. 'MS-7823' | +| - version | X | X | X | version e.g. '1.0' | +| - serial | X | X | X | serial number | +| - uuid | X | X | X | UUID | +| si.osInfo(cb) | X | X | X | OS information | +| - platform | X | X | X | 'Linux', 'Darwin', 'Windows' | +| - distro | X | X | X | | +| - release | X | X | X | | +| - codename | | X | | | +| - kernel | X | X | X | kernel release - same as os.release() | +| - arch | X | X | X | same as os.arch() | +| - hostname | X | X | X | same as os.hostname() | +| - logofile | X | X | X | e.g. 'apple', 'debian', 'fedora', ... | +| si.versions(cb) | X | X | X | Version information (kernel, ssl, node, ...) | +| si.shell(cb) | X | X | | standard shell | +| si.cpu(cb) | X | X | X | CPU information| +| - manufacturer | X | X | X | e.g. 'Intel(R)' | +| - brand | X | X | X | e.g. 'Core(TM)2 Duo' | +| - speed | X | X | X | in GHz e.g. '3.40' | +| - cores | X | X | X | # cores | +| si.cpuFlags(cb) | X | X | | CPU flags| +| si.cpuCache(cb) | X | X | | CPU cache sizes | +| - l1d | X | X | | L1D size | +| - l1i | X | X | | L1I size | +| - l2 | X | X | | L2 size | +| - l3 | X | X | | L3 size | +| si.cpuCurrentspeed(cb) | X | X | | current CPU speed (in GHz)| +| - avg | X | X | | avg CPU speed (all cores) | +| - min | X | X | | min CPU speed (all cores) | +| - max | X | X | | max CPU speed (all cores) | +| si.cpuTemperature(cb) | X | X | X | CPU temperature (if sensors is installed) | +| - main | X | X | X | main temperature | +| - cores | X | X | X | array of temperatures | +| - 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 | +| - used | X | X | X | used (incl. buffers/cache) | +| - active | X | X | X | used actively (excl. buffers/cache) | +| - buffcache | X | X | | used by buffers+cache | +| - available | X | X | X | potentially available (total - active) | +| - swaptotal | X | X | | | +| - swapused | X | X | | | +| - swapfree | X | X | | | +| si.battery(cb) | X | X | | battery information | +| - hasbattery | X | X | | indicates presence of battery | +| - ischarging | X | X | | indicates if battery is charging | +| - maxcapacity | X | X | | max capacity of battery | +| - currentcapacity | X | X | | current capacity of battery | +| - percent | X | X | | charging level in percent | +| si.graphics(cb) | X | X | | arrays of graphics controllers and displays | +| - controllers[0].model | X | X | | graphics controller model | +| - controllers[0].vendor | X | X | | e.g. ATI | +| - controllers[0].bus | X | X | | on which bus (e.g. PCIe) | +| - controllers[0].vram | X | X | | VRAM size (in MB) | +| - controllers[0].vramDynamic | X | X | | true if dynamicly allocated ram | +| - displays[0].model | X | X | | Monitor/Display Model | +| - displays[0].main | X | X | | true if main monitor | +| - displays[0].builtin | X | X | | true if built in monitor | +| - displays[0].connection | X | X | | e.g. DisplayPort or HDMI | +| - displays[0].resolutionx | X | X | | pixel horizontal | +| - displays[0].resolutiony | X | X | | pixel vertical | +| - displays[0].depth | X | X | | color depth in bits | +| - displays[0].sizex | X | X | | size in mm horizontal | +| - displays[0].sizey | X | X | | size in mm vertical | +| si.fsSize(cb) | X | X | X | returns array of mounted file systems | +| - [0].fs | X | X | X | name of file system | +| - [0].type | X | X | X | type of file system | +| - [0].size | X | X | X | sizes in Bytes | +| - [0].used | X | X | X | used in Bytes | +| - [0].use | X | X | X | used in % | +| - [0].mount | X | X | X | mount point | +| 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, ...) | +| 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) | +| 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) | +| - ms | X | X | | interval length (for per second values) | +| si.networkInterfaces(cb) | X | X | | array of network interfaces | +| - [0].iface | X | X | | interface name | +| - [0].ip4 | X | X | | ip4 address | +| - [0].ip6 | X | X | | ip6 address | +| - [0].mac | X | X | | MAC address | +| - [0].internal | X | X | | true if internal interface | +| si.networkInterfaceDefault(cb) | X | X | | get name of default network interface | +| si.networkStats(iface,cb) | X | X | | current network stats of given interface
iface parameter is optional
defaults to first external network interface| +| - iface | X | X | | interface | +| - operstate | X | X | | up / down | +| - rx | X | X | | received bytes overall | +| - tx | X | X | | transferred bytes overall| +| - rx_sec | X | X | | received bytes / second (* see notes) | +| - tx_sec | X | X | | transferred bytes per second (* see notes) | +| - ms | X | X | | interval length (for per second values) | +| si.networkConnections(cb) | X | X | | current network network connections
returns an array of all connections| +| - [0].protocol | X | X | | tcp or udp | +| - [0].localaddress | X | X | | local address | +| - [0].localport | X | X | | local port | +| - [0].peeraddress | X | X | | peer address | +| - [0].peerport | X | X | | peer port | +| - [0].state | X | X | | like ESTABLISHED, TIME_WAIT, ... | +| si.currentLoad(cb) | X | X | | CPU-Load | +| - avgload | X | X | | average load | +| - currentload | X | X | | CPU-Load in % | +| - currentload_user | X | X | | CPU-Load User in % | +| - currentload_nice | X | X | | CPU-Load Nice in % | +| - currentload_system | X | X | | CPU-Load System in % | +| - currentload_irq | X | X | | CPU-Load System in % | +| - cpus[] | X | X | | current loads per CPU in % | +| si.fullLoad(cb) | X | X | | CPU-full load since bootup in % | +| si.services('mysql, apache2', cb) | X | X | | pass comma separated string of services | +| - [0].name | X | X | | name of service | +| - [0].running | X | X | | true / false | +| - [0].pcpu | X | X | | process % CPU | +| - [0].pmem | X | X | | process % MEM | +| si.processes(cb) | X | X | | # running processes | +| - all | X | X | | # of all processes | +| - running | X | X | | # of all processes running | +| - blocked | X | X | | # of all processes blocked | +| - sleeping | X | X | | # of all processes sleeping | +| - list[] | X | X | | list of all processes incl. details | +| - ...[0].pid | X | X | | process PID | +| - ...[0].pcpu | X | X | | process % CPU usage | +| - ...[0].pcpuu | X | X | | process % CPU usage (user) | +| - ...[0].pcpus | X | X | | process % CPU usage (system) | +| - ...[0].pmem | X | X | | process memory % | +| - ...[0].priority | X | X | | process priotity | +| - ...[0].mem_vsz | X | X | | process virtual memory size | +| - ...[0].mem_rss | X | X | | process mem resident set size | +| - ...[0].nice | X | X | | process nice value | +| - ...[0].started | X | X | | process start time | +| - ...[0].state | X | X | | process state (e.g. sleeping) | +| - ...[0].tty | X | X | | tty from which process was started | +| si.processLoad('apache2',cb) | X | X | | detailed information about given process | +| - proc | X | X | | process name | +| - pid | X | X | | PID | +| - cpu | X | X | | process % CPU | +| - mem | X | X | | process % MEM | +| si.users(cb) | X | X | | array of users online | +| - [0].user | X | X | | user name | +| - [0].tty | X | X | | terminal | +| - [0].date | X | X | | login date | +| - [0].time | X | X | | login time | +| - [0].ip | X | X | | ip address (remote login) | +| - [0].command | X | X | | last command or shell | +| si.inetChecksite(url, cb) | X | X | | response-time (ms) to fetch given URL | +| - url | X | X | | given url | +| - ok | X | X | | status code OK (2xx, 3xx) | +| - status | X | X | | status code | +| - ms | X | X | | response time in ms | +| si.inetLatency(host, cb) | X | X | | response-time (ms) to external resource
host parameter is optional (default 8.8.8.8)| +| si.dockerContainers(all, cb) | X | X | | returns array of active/all docker containers | +| - [0].id | X | X | | ID of container | +| - [0].name | X | X | | name of container | +| - [0].image | X | X | | name of image | +| - [0].imageID | X | X | | ID of image | +| - [0].command | X | X | | command | +| - [0].created | X | X | | creation time | +| - [0].state | X | X | | created, running, exited | +| - [0].ports | X | X | | array of ports | +| - [0].mounts | X | X | | array of mounts | +| si.dockerContainerStats(id, cb) | X | X | | statistics for a specific container | +| - id | X | X | | Container ID | +| - mem_usage | X | X | | memory usage in bytes | +| - mem_limit | X | X | | memory limit (max mem) in bytes | +| - mem_percent | X | X | | memory usage in percent | +| - cpu_percent | X | X | | cpu usage in percent | +| - pids | X | X | | number of processes | +| - netIO.rx | X | X | | received bytes via network | +| - netIO.wx | X | X | | sent bytes via network | +| - blockIO.r | X | X | | bytes read from BlockIO | +| - blockIO.w | X | X | | bytes written to BlockIO | +| - cpu_stats | X | X | | detailed cpu stats | +| - percpu_stats | X | X | | detailed per cpu stats | +| - memory_stats | X | X | | detailed memory stats | +| - networks | X | X | | detailed network stats per interface | +| si.dockerContainerProcesses(id, cb) | X | X | | array of processes inside a container | +| - [0].pid_host | X | X | | process ID (host) | +| - [0].ppid | X | X | | parent process ID | +| - [0].pgid | X | X | | process group ID | +| - [0].user | X | X | | effective user name | +| - [0].ruser | X | X | | real user name | +| - [0].group | X | X | | effective group name | +| - [0].rgroup | X | X | | real group name | +| - [0].stat | X | X | | process state | +| - [0].time | X | X | | accumulated CPU time | +| - [0].elapsed | X | X | | elapsed running time | +| - [0].nice | X | X | | nice value | +| - [0].rss | X | X | | resident set size | +| - [0].vsz | X | X | | virtual size in Kbytes | +| - [0].command | X | X | | command and arguments | +| si.dockerAll(cb) | X | X | | list of all containers including their stats
and processes in one single array | +| si.getStaticData(cb) | X | X | | all static data at once | +| si.getDynamicData(srv,iface,cb) | X | X | | all dynamic data at once | +| si.getAllData(srv,iface,cb) | X | X | | all data at once | ### cb: Asynchronous Function Calls (callback) diff --git a/lib/cpu.js b/lib/cpu.js index ad507df..7124edf 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -61,14 +61,8 @@ function cpuBrandManufacturer(res) { function getCpu() { - return new Promise((resolve, reject) => { + return new Promise((resolve) => { process.nextTick(() => { - if (_windows) { - let error = new Error(NOT_SUPPORTED); - if (callback) { callback(NOT_SUPPORTED) } - reject(error); - } - let result = { manufacturer: 'unknown', brand: 'unknown', @@ -105,6 +99,20 @@ function getCpu() { resolve(result); }) } + if (_windows) { + exec("wmic cpu get name", function (error, stdout) { + if (!error) { + let lines = stdout.split('\r\n').filter(line => line.trim() != '').filter((line, idx) => idx > 0); + let line = (lines && lines[0]) ? lines[0] : ''; + result.brand = line.split('@')[0].trim(); + result.speed = line.split('@')[1].trim(); + result.speed = parseFloat(result.speed.replace(/GHz+/g, "")); + _cpu_speed = result.speed; + } + result = cpuBrandManufacturer(result); + resolve(result); + }) + } }); }); } @@ -116,12 +124,6 @@ function cpu(callback) { return new Promise((resolve, reject) => { process.nextTick(() => { - if (_windows) { - let error = new Error(NOT_SUPPORTED); - if (callback) { callback(NOT_SUPPORTED) } - reject(error); - } - getCpu().then(result => { if (callback) { callback(result) } resolve(result); @@ -188,12 +190,6 @@ function cpuTemperature(callback) { return new Promise((resolve, reject) => { process.nextTick(() => { - if (_windows) { - let error = new Error(NOT_SUPPORTED); - if (callback) { callback(NOT_SUPPORTED) } - reject(error); - } - let result = { main: -1.0, cores: [], @@ -280,6 +276,28 @@ function cpuTemperature(callback) { if (callback) { callback(result) } resolve(result); } + if (_windows) { + exec("wmic /namespace:\\\\root\\wmi PATH MSAcpi_ThermalZoneTemperature get CriticalTripPoint,CurrentTemperature /value", function (error, stdout) { + if (!error) { + let sum = 0; + let lines = stdout.trim().split(/\s\s+/); + lines.forEach(function (line) { + if (line.match('CriticalTripPoint') && !result.max) + result.max = (parseInt(line.split('CriticalTripPoint=')[1]) - 2732) / 10; + else if (line.match('CurrentTemperature')) { + let value = (parseInt(line.split('CurrentTemperature=')[1]) - 2732) / 10; + sum = sum + value; + result.cores.push(value); + } + }); + if (result.cores.length) { + result.main = sum / result.cores.length; + } + if (callback) { callback(result) } + resolve(result); + } + }); + } }); }); } diff --git a/lib/filesystem.js b/lib/filesystem.js index 2626945..08e7ec4 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -34,39 +34,55 @@ function fsSize(callback) { return new Promise((resolve, reject) => { process.nextTick(() => { - if (_windows) { - let error = new Error(NOT_SUPPORTED); - if (callback) { - callback(NOT_SUPPORTED) - } - reject(error); + if (_linux || _darwin) { + let cmd = (_darwin ? "df -lkP | grep ^/" : "df -lkPT | grep ^/"); + exec(cmd, function (error, stdout) { + let data = []; + if (!error) { + let lines = stdout.toString().split('\n'); + //lines.splice(0, 1); + lines.forEach(function (line) { + if (line != '') { + line = line.replace(/ +/g, " ").split(' '); + data.push({ + 'fs': line[0], + 'type': (_linux ? line[1] : 'HFS'), + 'size': parseInt((_linux ? line[2] : line[1])) * 1024, + 'used': parseInt((_linux ? line[3] : line[2])) * 1024, + 'use': parseFloat((100.0 * (_linux ? line[3] : line[2]) / (_linux ? line[2] : line[1])).toFixed(2)), + 'mount': line[line.length - 1] + }) + } + }); + } + if (callback) { + callback(data) + } + resolve(data); + }); } - - let cmd = (_darwin ? "df -lkP | grep ^/" : "df -lkPT | grep ^/"); - exec(cmd, function (error, stdout) { - let data = []; - if (!error) { - let lines = stdout.toString().split('\n'); - //lines.splice(0, 1); + if (_windows) { + exec('wmic logicaldisk get Caption,FileSystem,FreeSpace,Size', function (error, stdout) { + let lines = stdout.split('\r\n').filter(line => line.trim() != '').filter((line, idx) => idx > 0); lines.forEach(function (line) { if (line != '') { - line = line.replace(/ +/g, " ").split(' '); + line = line.trim().split(/\s\s+/); data.push({ 'fs': line[0], - 'type': (_linux ? line[1] : 'HFS'), - 'size': parseInt((_linux ? line[2] : line[1])) * 1024, - 'used': parseInt((_linux ? line[3] : line[2])) * 1024, - 'use': parseFloat((100.0 * (_linux ? line[3] : line[2]) / (_linux ? line[2] : line[1])).toFixed(2)), - 'mount': line[line.length - 1] + 'type': line[1], + 'size': line[3], + 'used': parseInt(line[3]) - parseInt(line[2]), + 'use': parseFloat((100.0 * (parseInt(line[3]) - parseInt(line[2]))) / parseInt(line[3])), + 'mount': line[0] }) } }); - } - if (callback) { - callback(data) - } - resolve(data); - }); + if (callback) { + callback(data) + } + resolve(data); + }); + } }); }); } @@ -179,14 +195,6 @@ function blockDevices(callback) { return new Promise((resolve, reject) => { process.nextTick(() => { - if (_windows) { - let error = new Error(NOT_SUPPORTED); - if (callback) { - callback(NOT_SUPPORTED) - } - reject(error); - } - if (_linux) { // see https://wiki.ubuntuusers.de/lsblk/ // exec("lsblk -bo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,TRAN,SERIAL,LABEL,MODEL,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,SCHED,RQ-SIZE,RA,WSAME", function (error, stdout) { @@ -227,6 +235,37 @@ function blockDevices(callback) { resolve(data); }); } + if (_windows) { + exec('wmic logicaldisk get Caption,Description,DeviceID,DriveType,FileSystem,FreeSpace,Name,Size,VolumeName,VolumeSerialNumber /format:csv', 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.replace('\r', '').split(','); + data.push({ + name: line[7], + identifier: line[1], + type: 'disk', + fstype: line[5].toLowerCase(), + mount: line[1], + size: line[8], + physical: line[4] == '5' ? 'CD/DVD' : 'HDD', + uuid: line[10], + label: line[9], + model: '', + serial: line[10], + removable: line[4] == '2', + protocol: '' + }); + } + }); + } + if (callback) { + callback(data) + } + resolve(data); + }); + } }); }); } diff --git a/lib/index.js b/lib/index.js index 4841b86..8318ed8 100644 --- a/lib/index.js +++ b/lib/index.js @@ -82,6 +82,7 @@ // -------------------------------- // // version date comment +// 3.17.0 2017-02-19 windows support for some first functions // 3.16.0 2017-01-19 blockDevices: added removable attribute + fix // 3.15.1 2017-01-17 minor cpuTemperature fix (OSX) // 3.15.0 2017-01-15 added cpuTemperature also for OSX diff --git a/lib/memory.js b/lib/memory.js index 1f5a4e7..b586839 100644 --- a/lib/memory.js +++ b/lib/memory.js @@ -78,11 +78,6 @@ module.exports = function (callback) { return new Promise((resolve, reject) => { process.nextTick(() => { - if (_windows) { - let error = new Error(NOT_SUPPORTED); - if (callback) { callback(NOT_SUPPORTED) } - reject(error); - } let result = { total: os.totalmem(), diff --git a/lib/osinfo.js b/lib/osinfo.js index 548e78d..5d3d80a 100644 --- a/lib/osinfo.js +++ b/lib/osinfo.js @@ -42,34 +42,90 @@ exports.time = time; function getLogoFile(distro) { distro = distro.toLowerCase(); let result = 'linux'; - if (_windows) { result = 'windows' } - else if (distro.indexOf('mac os') != -1) { result = 'apple' } - else if (distro.indexOf('arch') != -1) { result = 'arch' } - else if (distro.indexOf('centos') != -1) { result = 'centos' } - else if (distro.indexOf('coreos') != -1) { result = 'coreos' } - else if (distro.indexOf('debian') != -1) { result = 'debian' } - else if (distro.indexOf('elementary') != -1) { result = 'elementary' } - else if (distro.indexOf('fedora') != -1) { result = 'fedora' } - else if (distro.indexOf('gentoo') != -1) { result = 'gentoo' } - else if (distro.indexOf('mageia') != -1) { result = 'mageia' } - else if (distro.indexOf('mandriva') != -1) { result = 'mandriva' } - else if (distro.indexOf('manjaro') != -1) { result = 'manjaro' } - else if (distro.indexOf('mint') != -1) { result = 'mint' } - else if (distro.indexOf('openbsd') != -1) { result = 'openbsd' } - else if (distro.indexOf('opensuse') != -1) { result = 'opensuse' } - else if (distro.indexOf('pclinuxos') != -1) { result = 'pclinuxos' } - else if (distro.indexOf('puppy') != -1) { result = 'puppy' } - else if (distro.indexOf('raspbian') != -1) { result = 'raspbian' } - else if (distro.indexOf('reactos') != -1) { result = 'reactos' } - else if (distro.indexOf('redhat') != -1) { result = 'redhat' } - else if (distro.indexOf('slackware') != -1) { result = 'slackware' } - else if (distro.indexOf('sugar') != -1) { result = 'sugar' } - else if (distro.indexOf('steam') != -1) { result = 'steam' } - else if (distro.indexOf('suse') != -1) { result = 'suse' } - else if (distro.indexOf('mate') != -1) { result = 'ubuntu-mate' } - else if (distro.indexOf('lubuntu') != -1) { result = 'lubuntu' } - else if (distro.indexOf('xubuntu') != -1) { result = 'xubuntu' } - else if (distro.indexOf('ubuntu') != -1) { result = 'ubuntu' } + if (_windows) { + result = 'windows' + } + else if (distro.indexOf('mac os') != -1) { + result = 'apple' + } + else if (distro.indexOf('arch') != -1) { + result = 'arch' + } + else if (distro.indexOf('centos') != -1) { + result = 'centos' + } + else if (distro.indexOf('coreos') != -1) { + result = 'coreos' + } + else if (distro.indexOf('debian') != -1) { + result = 'debian' + } + else if (distro.indexOf('elementary') != -1) { + result = 'elementary' + } + else if (distro.indexOf('fedora') != -1) { + result = 'fedora' + } + else if (distro.indexOf('gentoo') != -1) { + result = 'gentoo' + } + else if (distro.indexOf('mageia') != -1) { + result = 'mageia' + } + else if (distro.indexOf('mandriva') != -1) { + result = 'mandriva' + } + else if (distro.indexOf('manjaro') != -1) { + result = 'manjaro' + } + else if (distro.indexOf('mint') != -1) { + result = 'mint' + } + else if (distro.indexOf('openbsd') != -1) { + result = 'openbsd' + } + else if (distro.indexOf('opensuse') != -1) { + result = 'opensuse' + } + else if (distro.indexOf('pclinuxos') != -1) { + result = 'pclinuxos' + } + else if (distro.indexOf('puppy') != -1) { + result = 'puppy' + } + else if (distro.indexOf('raspbian') != -1) { + result = 'raspbian' + } + else if (distro.indexOf('reactos') != -1) { + result = 'reactos' + } + else if (distro.indexOf('redhat') != -1) { + result = 'redhat' + } + else if (distro.indexOf('slackware') != -1) { + result = 'slackware' + } + else if (distro.indexOf('sugar') != -1) { + result = 'sugar' + } + else if (distro.indexOf('steam') != -1) { + result = 'steam' + } + else if (distro.indexOf('suse') != -1) { + result = 'suse' + } + else if (distro.indexOf('mate') != -1) { + result = 'ubuntu-mate' + } + else if (distro.indexOf('lubuntu') != -1) { + result = 'lubuntu' + } + else if (distro.indexOf('xubuntu') != -1) { + result = 'xubuntu' + } + else if (distro.indexOf('ubuntu') != -1) { + result = 'ubuntu' + } return result; } @@ -78,17 +134,11 @@ function getLogoFile(distro) { function osInfo(callback) { - return new Promise((resolve, reject) => { + return new Promise((resolve) => { process.nextTick(() => { - if (_windows) { - let error = new Error(NOT_SUPPORTED); - if (callback) { callback(NOT_SUPPORTED) } - reject(error); - } - let result = { - platform: _platform, + platform: (_platform == 'Windows_NT' ? 'Windows' : _platform), distro: 'unknown', release: 'unknown', codename: '', @@ -122,7 +172,9 @@ function osInfo(callback) { result.release = (release.DISTRIB_RELEASE || release.VERSION_ID || 'unknown').replace(/"/g, ''); result.codename = (release.DISTRIB_CODENAME || '').replace(/"/g, ''); //} - if (callback) { callback(result) } + if (callback) { + callback(result) + } resolve(result); }) } @@ -136,10 +188,23 @@ function osInfo(callback) { } if (line.indexOf('ProductVersion') != -1) result.release = line.split(':')[1].trim(); }); - if (callback) { callback(result) } + if (callback) { + callback(result) + } resolve(result); }) } + if (_windows) { + result.logofile = getLogoFile(); + result.release = result.kernel; + exec("wmic os get Caption", function (error, stdout) { + result.distro = result.codename = stdout.slice(stdout.indexOf('\r\n') + 2).trim(); + if (callback) { + callback(result) + } + resolve(result); + }); + } }); }); } @@ -166,10 +231,12 @@ function versions(callback) { if (!error) { lines = stdout.toString().split('\n'); if (lines.length >= 2) { - result.pm2 = lines[lines.length-2]; + result.pm2 = lines[lines.length - 2]; } } - if (callback) { callback(result) } + if (callback) { + callback(result) + } resolve(result); }); }); @@ -184,7 +251,9 @@ function shell(callback) { process.nextTick(() => { if (_windows) { let error = new Error(NOT_SUPPORTED); - if (callback) { callback(NOT_SUPPORTED) } + if (callback) { + callback(NOT_SUPPORTED) + } reject(error); } @@ -193,7 +262,9 @@ function shell(callback) { if (!error) { result = stdout.toString().split('\n')[0]; } - if (callback) { callback(result) } + if (callback) { + callback(result) + } resolve(result); }); }); diff --git a/lib/processes.js b/lib/processes.js index 83222e4..e7490b2 100644 --- a/lib/processes.js +++ b/lib/processes.js @@ -27,7 +27,8 @@ const NOT_SUPPORTED = 'not supported'; let _process_cpu = { all: 0, list: {}, - ms: 0 + ms: 0, + result: {} }; // -------------------------- @@ -158,21 +159,25 @@ function processes(callback) { let priority = parseInt(line.substring(parsedhead[3].from, parsedhead[3].to)); let vsz = parseInt(line.substring(parsedhead[4].from, parsedhead[4].to)); let rss = parseInt(line.substring(parsedhead[5].from, parsedhead[5].to)); - let started = line.substring(parsedhead[6].from, parsedhead[6].to).trim(); - let state = line.substring(parsedhead[7].from, parsedhead[7].to).trim(); + let nice = parseInt(line.substring(parsedhead[6].from, parsedhead[6].to)); + let started = line.substring(parsedhead[7].from, parsedhead[7].to).trim(); + let state = line.substring(parsedhead[8].from, parsedhead[8].to).trim(); state = (state[0] == 'R' ? 'running' : (state[0] == 'S' ? 'sleeping' : (state[0] == 'T' ? 'stopped' : (state[0] == 'W' ? 'paging' : (state[0] == 'X' ? 'dead' : (state[0] == 'Z' ? 'zombie' : ((state[0] == 'D' || state[0] == 'U') ? 'blocked' : 'unknown'))))))); - let tty = line.substring(parsedhead[8].from, parsedhead[8].to).trim(); + let tty = line.substring(parsedhead[9].from, parsedhead[9].to).trim(); if (tty == '?' || tty == '??') tty = ''; - let user = line.substring(parsedhead[9].from, parsedhead[9].to).trim(); - let command = line.substring(parsedhead[10].from, parsedhead[10].to).trim().replace(/\[/g, "").replace(/]/g, ""); + let user = line.substring(parsedhead[10].from, parsedhead[10].to).trim(); + let command = line.substring(parsedhead[11].from, parsedhead[11].to).trim().replace(/\[/g, "").replace(/]/g, ""); return ({ pid: pid, pcpu: pcpu, + pcpuu: 0, + pcpus: 0, pmem: pmem, priority: priority, mem_vsz: vsz, mem_rss: rss, + nice: nice, started: started, state: state, tty: tty, @@ -212,32 +217,45 @@ function processes(callback) { } function parseProcPidStat(line, all) { - let parts = line.replace(/ +/g, " ").split(' '); - if (parts.length >= 17) { - let pid = parseInt(parts[0]); - let utime = parseInt(parts[13]); - let stime = parseInt(parts[14]); - let cutime = parseInt(parts[15]); - let cstime = parseInt(parts[16]); + let statparts = line.replace(/ +/g, " ").split(')'); + if (statparts.length >= 2) { + let parts = statparts[1].split(' '); + if (parts.length >= 16) { + let pid = parseInt(statparts[0].split(' ')[0]); + let utime = parseInt(parts[12]); + let stime = parseInt(parts[13]); + let cutime = parseInt(parts[14]); + let cstime = parseInt(parts[15]); - // calc - let pcpuu = 0; - let pcpus = 0; - if (_process_cpu.all > 0 && _process_cpu.list[pid]) { - pcpuu = (utime + cutime - _process_cpu.list[pid].utime - _process_cpu.list[pid].cutime) / (all - _process_cpu.all) * 100; // user - pcpus = (stime + cstime - _process_cpu.list[pid].stime - _process_cpu.list[pid].cstime) / (all - _process_cpu.all) * 100; // system + // calc + let pcpuu = 0; + let pcpus = 0; + if (_process_cpu.all > 0 && _process_cpu.list[pid]) { + pcpuu = (utime + cutime - _process_cpu.list[pid].utime - _process_cpu.list[pid].cutime) / (all - _process_cpu.all) * 100; // user + pcpus = (stime + cstime - _process_cpu.list[pid].stime - _process_cpu.list[pid].cstime) / (all - _process_cpu.all) * 100; // system + } else { + pcpuu = (utime + cutime) / (all) * 100; // user + pcpus = (stime + cstime) / (all) * 100; // system + } + return { + pid: pid, + utime: utime, + stime: stime, + cutime: cutime, + cstime: cstime, + pcpuu: pcpuu, + pcpus: pcpus + } } else { - pcpuu = (utime + cutime) / (all) * 100; // user - pcpus = (stime + cstime) / (all) * 100; // system - } - return { - pid: pid, - utime: utime, - stime: stime, - cutime: cutime, - cstime: cstime, - pcpuu: pcpuu, - pcpus: pcpus + return { + pid: 0, + utime: 0, + stime: 0, + cutime: 0, + cstime: 0, + pcpuu: 0, + pcpus: 0 + } } } else { return { @@ -268,73 +286,82 @@ function processes(callback) { }; let cmd = ""; - if (_linux) cmd = "ps axo pid:10,pcpu:6,pmem:6,pri:5,vsz:10,rss:10,start:20,state:20,tty:20,user:20,command"; - if (_darwin) cmd = "ps acxo pid,pcpu,pmem,pri,vsz,rss,start,state,tty,user,command -r"; - exec(cmd, function (error, stdout) { - if (!error) { - result.list = parseProcesses(stdout.toString().split('\n')); - result.all = result.list.length; - result.running = result.list.filter(function (e) { - return e.state == 'running' - }).length; - result.blocked = result.list.filter(function (e) { - return e.state == 'blocked' - }).length; - result.sleeping = result.list.filter(function (e) { - return e.state == 'sleeping' - }).length; - if (_linux) { - // calc process_cpu - ps is not accurate in linux! - cmd = "cat /proc/stat | grep 'cpu '"; - for (let i = 0; i < result.list.length; i++) { - cmd += (';cat /proc/' + result.list[i].pid + '/stat') - } - exec(cmd, function (error, stdout) { - let curr_processes = stdout.toString().split('\n'); + if ((_process_cpu.ms && Date.now() - _process_cpu.ms >= 500) || _process_cpu.ms == 0) { + if (_linux) cmd = "ps axo pid:10,pcpu:6,pmem:6,pri:5,vsz:10,rss:10,ni:5,start:20,state:20,tty:20,user:20,command"; + if (_darwin) cmd = "ps acxo pid,pcpu,pmem,pri,vsz,rss,nice,start,state,tty,user,command -r"; + exec(cmd, function (error, stdout) { + if (!error) { + result.list = parseProcesses(stdout.toString().split('\n')); + result.all = result.list.length; + result.running = result.list.filter(function (e) { + return e.state == 'running' + }).length; + result.blocked = result.list.filter(function (e) { + return e.state == 'blocked' + }).length; + result.sleeping = result.list.filter(function (e) { + return e.state == 'sleeping' + }).length; - // first line (all - /proc/stat) - let all = parseProcStat(curr_processes.shift()); + if (_linux) { + // calc process_cpu - ps is not accurate in linux! + cmd = "cat /proc/stat | grep 'cpu '"; + for (let i = 0; i < result.list.length; i++) { + cmd += (';cat /proc/' + result.list[i].pid + '/stat') + } + exec(cmd, function (error, stdout) { + let curr_processes = stdout.toString().split('\n'); - // process - let list_new = {}; - let resultProcess = {}; - for (let i = 0; i < curr_processes.length; i++) { - resultProcess = parseProcPidStat(curr_processes[i], all); + // first line (all - /proc/stat) + let all = parseProcStat(curr_processes.shift()); - if (resultProcess.pid) { + // process + let list_new = {}; + let resultProcess = {}; + for (let i = 0; i < curr_processes.length; i++) { + resultProcess = parseProcPidStat(curr_processes[i], all); - // store pcpu in outer array - let listPos = result.list.map(function (e) { return e.pid; }).indexOf(resultProcess.pid); - if (listPos >= 0) { - result.list[listPos].pcpu = resultProcess.pcpuu + resultProcess.pcpus - } + if (resultProcess.pid) { - // save new values - list_new[resultProcess.pid] = { - pcpuu: resultProcess.pcpuu, - pcpus: resultProcess.pcpus, - utime: resultProcess.utime, - stime: resultProcess.stime, - cutime: resultProcess.cutime, - cstime: resultProcess.cstime + // store pcpu in outer array + let listPos = result.list.map(function (e) { return e.pid; }).indexOf(resultProcess.pid); + if (listPos >= 0) { + result.list[listPos].pcpu = resultProcess.pcpuu + resultProcess.pcpus; + result.list[listPos].pcpuu = resultProcess.pcpuu; + result.list[listPos].pcpus = resultProcess.pcpus; + } + + // save new values + list_new[resultProcess.pid] = { + pcpuu: resultProcess.pcpuu, + pcpus: resultProcess.pcpus, + utime: resultProcess.utime, + stime: resultProcess.stime, + cutime: resultProcess.cutime, + cstime: resultProcess.cstime + } } } - } - // store old values - _process_cpu.all = all; - _process_cpu.list = list_new; - _process_cpu.ms = Date.now() - _process_cpu.ms; + // store old values + _process_cpu.all = all; + _process_cpu.list = list_new; + _process_cpu.ms = Date.now() - _process_cpu.ms; + _process_cpu.result = result; + if (callback) { callback(result) } + resolve(result); + }) + } else { if (callback) { callback(result) } resolve(result); - }) - } else { - if (callback) { callback(result) } - resolve(result); + } } - } - }); + }); + } else { + if (callback) { callback(_process_cpu.result) } + resolve(_process_cpu.result); + } }); }); } diff --git a/lib/system.js b/lib/system.js index ad077c3..43a2e2b 100644 --- a/lib/system.js +++ b/lib/system.js @@ -28,11 +28,6 @@ module.exports = function (callback) { return new Promise((resolve, reject) => { process.nextTick(() => { - if (_windows) { - let error = new Error(NOT_SUPPORTED); - if (callback) { callback(NOT_SUPPORTED) } - reject(error); - } let result = { manufacturer: '', @@ -148,6 +143,20 @@ module.exports = function (callback) { resolve(result); }) } + if (_windows) { + exec("wmic csproduct get", function (error, stdout) { + if (!error) { + let lines = stdout.split('\r\n').filter(line => line.trim() != '').filter((line, idx) => idx > 0)[0].trim().split(/\s\s+/); + result.manufacturer = lines[5]; + result.model = lines[3]; + result.version = lines[6]; + result.serial = lines[2]; + result.uuid = lines[4]; + } + if (callback) { callback(result) } + resolve(result); + }) + } }); }); }; diff --git a/package.json b/package.json index 063a2ac..c18df6b 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "os", "linux", "osx", + "windows", "cpu", "cpuload", "memory", @@ -45,7 +46,8 @@ }, "os": [ "darwin", - "linux" + "linux", + "win32" ], "engines": { "node": ">=4.0.0"