added additional windows support (cpu, cpuCache, cpuCurrentspeed, mem, networkInterfaces, docker)

This commit is contained in:
Sebastian Hildebrandt 2017-06-16 14:27:21 +02:00
parent 87a153136c
commit 92e58b57b8
9 changed files with 425 additions and 311 deletions

View File

@ -95,6 +95,7 @@ Other changes
| Version | Date | Comment | | Version | Date | Comment |
| -------------- | -------------- | -------- | | -------------- | -------------- | -------- |
| 3.20.0 | 2017-06-16 | extend windows support (cpu, cpuCache, cpuCurrentspeed, mem, networkInterfaces, docker) |
| 3.19.0 | 2017-06-12 | OSX temperature now an optional dependency | | 3.19.0 | 2017-06-12 | OSX temperature now an optional dependency |
| 3.18.0 | 2017-05-27 | extended `cpu` info (vendor, family, model, stepping, revision, cache, speedmin/max) | | 3.18.0 | 2017-05-27 | extended `cpu` info (vendor, family, model, stepping, revision, cache, speedmin/max) |
| 3.17.3 | 2017-04-29 | minor fix (blockDevices data array, Windows) | | 3.17.3 | 2017-04-29 | minor fix (blockDevices data array, Windows) |

572
README.md
View File

@ -23,7 +23,7 @@ $ npm install systeminformation --save
All functions (except `version` and `time`) are implemented as asynchronous functions. Here a small example how to use them: All functions (except `version` and `time`) are implemented as asynchronous functions. Here a small example how to use them:
``` ```
var si = require('systeminformation'); const si = require('systeminformation');
// callback style // callback style
si.cpu(function(data) { si.cpu(function(data) {
@ -42,7 +42,8 @@ si.cpu()
### Latest Activity ### Latest Activity
- Version 3.19.0: OSX temperature now an optional dependency - Version 3.20.0: added additional windows support (cpu, cpuCache, cpuCurrentspeed, mem, networkInterfaces, docker)
- Version 3.19.0: OSX temperature now an optional dependency (see comments below in reference!)
- Version 3.18.0: extended `cpu` info (vendor, family, model, stepping, revision, cache, speedmin, speedmax) - Version 3.18.0: extended `cpu` info (vendor, family, model, stepping, revision, cache, speedmin, speedmax)
- Version 3.17.0: windows support for some very first functions (work in progress) - Version 3.17.0: windows support for some very first functions (work in progress)
- Version 3.16.0: `blockDevices`: added removable attribute - Version 3.16.0: `blockDevices`: added removable attribute
@ -84,264 +85,289 @@ I also created a little command line tool called [mmon][mmon-github-url] (micro
## Reference ## Reference
### Sections
This library is splitted in several sections:
1. General
2. System (HW)
3. Operating System
4. CPU
5. Memory
6. File System
7. Network
8. Processes
9. Users
10. Internet
11. Docker
12. GetAll
### Function Reference and OS Support ### Function Reference and OS Support
| Function | Linux | OSX | Win | Comments | #### 1. General
| --------------- | ----- | ---- | ------- | -------- |
| si.version() | X | X | X | library version (no callback/promise) | | Function | Result object | Linux | OSX | Win | Comments |
| si.time() | X | X | X | time information (no callback/promise) | | --------------- | ----- | ----- | ---- | ------- | -------- |
| - current | X | X | X | local time | | si.version() | : string | X | X | X | lib version (no callback/promise) |
| - uptime | X | X | X | uptime | | si.time() | {...} | X | X | X | (no callback/promise) |
| si.system(cb) | X | X | X | hardware information | | | current | X | X | X | local time |
| - manufacturer | X | X | X | e.g. 'MSI' | | | uptime | X | X | X | uptime |
| - model | X | X | X | model/product e.g. 'MS-7823' |
| - version | X | X | X | version e.g. '1.0' | #### 2. System (HW)
| - serial | X | X | X | serial number |
| - uuid | X | X | X | UUID | | Function | Result object | Linux | OSX | Win | Comments |
| si.osInfo(cb) | X | X | X | OS information | | --------------- | ----- | ----- | ---- | ------- | -------- |
| - platform | X | X | X | 'Linux', 'Darwin', 'Windows' | | si.system(cb) | {...} | X | X | X | hardware information |
| - distro | X | X | X | | | | manufacturer | X | X | X | e.g. 'MSI' |
| - release | X | X | X | | | | model | X | X | X | model/product e.g. 'MS-7823' |
| - codename | | X | | | | | version | X | X | X | version e.g. '1.0' |
| - kernel | X | X | X | kernel release - same as os.release() | | | serial | X | X | X | serial number |
| - arch | X | X | X | same as os.arch() | | | uuid | X | X | X | UUID |
| - hostname | X | X | X | same as os.hostname() |
| - logofile | X | X | X | e.g. 'apple', 'debian', 'fedora', ... | #### 3. CPU, Memory, Battery, Graphics
| si.versions(cb) | X | X | X | Version information (kernel, ssl, node, ...) |
| si.shell(cb) | X | X | | standard shell | | Function | Result object | Linux | OSX | Win | Comments |
| si.cpu(cb) | X | X | X | CPU information| | --------------- | ----- | ----- | ---- | ------- | -------- |
| - manufacturer | X | X | X | e.g. 'Intel(R)' | | si.cpu(cb) | {...} | X | X | X | CPU information|
| - brand | X | X | X | e.g. 'Core(TM)2 Duo' | | | manufacturer | X | X | X | e.g. 'Intel(R)' |
| - speed | X | X | X | in GHz e.g. '3.40' | | | brand | X | X | X | e.g. 'Core(TM)2 Duo' |
| - speedmin | X | X | X | in GHz e.g. '0.80' | | | speed | X | X | X | in GHz e.g. '3.40' |
| - speedmax | X | X | X | in GHz e.g. '3.90' | | | speedmin | X | X | X | in GHz e.g. '0.80' |
| - cores | X | X | X | # cores | | | speedmax | X | X | X | in GHz e.g. '3.90' |
| - vendor | X | X | | Vendow ID | | | cores | X | X | X | # cores |
| - family | X | X | | Processor Family | | | vendor | X | X | X | Vendow ID |
| - Model | X | X | | Processor Model | | | family | X | X | X | Processor Family |
| - stepping | X | X | | Processor Stepping | | | Model | X | X | X | Processor Model |
| - revision | X | X | | Revision | | | stepping | X | X | X | Processor Stepping |
| - cache | X | X | | cache in bytes (object) | | | revision | X | X | X | Revision |
| - cache.l1d | X | X | | L1D size | | | cache | X | X | X | cache in bytes (object) |
| - cache.l1i | X | X | | L1I size | | | cache.l1d | X | X | | L1D size |
| - cache.l2 | X | X | | L2 size | | | cache.l1i | X | X | | L1I size |
| - cache.l3 | X | X | | L3 size | | | cache.l2 | X | X | X | L2 size |
| si.cpuFlags(cb) | X | X | | CPU flags| | | cache.l3 | X | X | X | L3 size |
| si.cpuCache(cb) | X | X | | CPU cache sizes | | si.cpuFlags(cb) | : string | X | X | | CPU flags|
| - l1d | X | X | | L1D size | | si.cpuCache(cb) | {...} | X | X | X | CPU cache sizes |
| - l1i | X | X | | L1I size | | | l1d | X | X | | L1D size |
| - l2 | X | X | | L2 size | | | l1i | X | X | | L1I size |
| - l3 | X | X | | L3 size | | | l2 | X | X | X | L2 size |
| si.cpuCurrentspeed(cb) | X | X | | current CPU speed (in GHz)| | | l3 | X | X | X | L3 size |
| - avg | X | X | | avg CPU speed (all cores) | | si.cpuCurrentspeed(cb) | {...} | X | X | X | current CPU speed (in GHz)|
| - min | X | X | | min CPU speed (all cores) | | | avg | X | X | X | avg CPU speed (all cores) |
| - max | X | X | | max CPU speed (all cores) | | | min | X | X | X | min CPU speed (all cores) |
| si.cpuTemperature(cb) | X | X | X | CPU temperature (if sensors is installed) | | | max | X | X | X | max CPU speed (all cores) |
| - main | X | X | X | main temperature | | si.cpuTemperature(cb) | {...} | X | X* | X | CPU temperature (if supported) |
| - cores | X | X | X | array of temperatures | | | main | X | X | X | main temperature |
| - max | X | X | X | max temperature | | | cores | X | X | X | array of temperatures |
| si.mem(cb) | X | X | X | Memory information| | | max | X | X | X | max temperature |
| - total | X | X | X | total memory | | si.mem(cb) | {...} | X | X | X | Memory information|
| - free | X | X | X | not used | | | total | X | X | X | total memory |
| - used | X | X | X | used (incl. buffers/cache) | | | free | X | X | X | not used |
| - active | X | X | X | used actively (excl. buffers/cache) | | | used | X | X | X | used (incl. buffers/cache) |
| - buffcache | X | X | | used by buffers+cache | | | active | X | X | X | used actively (excl. buffers/cache) |
| - available | X | X | X | potentially available (total - active) | | | buffcache | X | X | | used by buffers+cache |
| - swaptotal | X | X | | | | | available | X | X | X | potentially available (total - active) |
| - swapused | X | X | | | | | swaptotal | X | X | | |
| - swapfree | X | X | | | | | swapused | X | X | | |
| si.battery(cb) | X | X | | battery information | | | swapfree | X | X | | |
| - hasbattery | X | X | | indicates presence of battery | | si.battery(cb) | {...} | X | X | | battery information |
| - ischarging | X | X | | indicates if battery is charging | | | hasbattery | X | X | | indicates presence of battery |
| - maxcapacity | X | X | | max capacity of battery | | | ischarging | X | X | | indicates if battery is charging |
| - currentcapacity | X | X | | current capacity of battery | | | maxcapacity | X | X | | max capacity of battery |
| - percent | X | X | | charging level in percent | | | currentcapacity | X | X | | current capacity of battery |
| si.graphics(cb) | X | X | | arrays of graphics controllers and displays | | | percent | X | X | | charging level in percent |
| - controllers[0].model | X | X | | graphics controller model | | si.graphics(cb) | {...} | X | X | | arrays of graphics controllers and displays |
| - controllers[0].vendor | X | X | | e.g. ATI | | | controllers[0].model | X | X | X | graphics controller model |
| - controllers[0].bus | X | X | | on which bus (e.g. PCIe) | | | controllers[0].vendor | X | X | X | e.g. ATI |
| - controllers[0].vram | X | X | | VRAM size (in MB) | | | controllers[0].bus | X | X | X| on which bus (e.g. PCIe) |
| - controllers[0].vramDynamic | X | X | | true if dynamicly allocated ram | | | controllers[0].vram | X | X | X | VRAM size (in MB) |
| - displays[0].model | X | X | | Monitor/Display Model | | | controllers[0].vramDynamic | X | X | | true if dynamicly allocated ram |
| - displays[0].main | X | X | | true if main monitor | | | displays[0].model | X | X | | Monitor/Display Model |
| - displays[0].builtin | X | X | | true if built in monitor | | | displays[0].main | X | X | | true if main monitor |
| - displays[0].connection | X | X | | e.g. DisplayPort or HDMI | | | displays[0].builtin | X | X | | true if built in monitor |
| - displays[0].resolutionx | X | X | | pixel horizontal | | | displays[0].connection | X | X | | e.g. DisplayPort or HDMI |
| - displays[0].resolutiony | X | X | | pixel vertical | | | displays[0].resolutionx | X | X | X | pixel horizontal |
| - displays[0].depth | X | X | | color depth in bits | | | displays[0].resolutiony | X | X | X | pixel vertical |
| - displays[0].sizex | X | X | | size in mm horizontal | | | displays[0].depth | X | X | X | color depth in bits |
| - displays[0].sizey | X | X | | size in mm vertical | | | displays[0].sizex | X | X | | size in mm horizontal |
| si.fsSize(cb) | X | X | X | returns array of mounted file systems | | | displays[0].sizey | X | X | | size in mm vertical |
| - [0].fs | X | X | X | name of file system |
| - [0].type | X | X | X | type of file system | #### 4. Operating System
| - [0].size | X | X | X | sizes in Bytes |
| - [0].used | X | X | X | used in Bytes | | Function | Result object | Linux | OSX | Win | Comments |
| - [0].use | X | X | X | used in % | | --------------- | ----- | ----- | ---- | ------- | -------- |
| - [0].mount | X | X | X | mount point | | si.osInfo(cb) | {...} | X | X | X | OS information |
| si.blockDevices(cb) | X | X | X | returns array of disks, partitions,<br>raids and roms | | | platform | X | X | X | 'Linux', 'Darwin', 'Windows' |
| - [0].name | X | X | X | name | | | distro | X | X | X | |
| - [0].type | X | X | X | type | | | release | X | X | X | |
| - [0].fstype | X | X | X | file system type (e.g. ext4) | | | codename | | X | | |
| - [0].mount | X | X | X | mount point | | | kernel | X | X | X | kernel release - same as os.release() |
| - [0].size | X | X | X | size in bytes | | | arch | X | X | X | same as os.arch() |
| - [0].physical | X | X | X | physical type (HDD, SSD, CD/DVD) | | | hostname | X | X | X | same as os.hostname() |
| - [0].uuid | X | X | X | UUID | | | logofile | X | X | X | e.g. 'apple', 'debian', 'fedora', ... |
| - [0].label | X | X | X | label | | si.versions(cb) | {...} | X | X | X | Version information (kernel, ssl, node, ...) |
| - [0].model | X | X | | model | | si.shell(cb) | : string | X | X | | standard shell |
| - [0].serial | X | | X | serial | | si.users(cb) | [{...}] | X | X | | array of users online |
| - [0].removable | X | X | X | serial | | | [0].user | X | X | | user name |
| - [0].protocol | X | X | | protocol (SATA, PCI-Express, ...) | | | [0].tty | X | X | | terminal |
| si.fsStats(cb) | X | X | | current transfer stats | | | [0].date | X | X | | login date |
| - rx | X | X | | bytes read since startup | | | [0].time | X | X | | login time |
| - wx | X | X | | bytes written since startup | | | [0].ip | X | X | | ip address (remote login) |
| - tx | X | X | | total bytes read + written since startup | | | [0].command | X | X | | last command or shell |
| - rx_sec | X | X | | bytes read / second (* see notes) |
| - wx_sec | X | X | | bytes written / second (* see notes) | #### 5. File System
| - tx_sec | X | X | | total bytes reads + written / second |
| - ms | X | X | | interval length (for per second values) | | Function | Result object | Linux | OSX | Win | Comments |
| si.disksIO(cb) | X | X | | current transfer stats | | --------------- | ----- | ----- | ---- | ------- | -------- |
| - rIO | X | X | | read IOs on all mounted drives | | si.fsSize(cb) | [{...}] | X | X | X | returns array of mounted file systems |
| - wIO | X | X | | write IOs on all mounted drives | | | [0].fs | X | X | X | name of file system |
| - tIO | X | X | | write IOs on all mounted drives | | | [0].type | X | X | X | type of file system |
| - rIO_sec | X | X | | read IO per sec (* see notes) | | | [0].size | X | X | X | sizes in Bytes |
| - wIO_sec | X | X | | write IO per sec (* see notes) | | | [0].used | X | X | X | used in Bytes |
| - tIO_sec | X | X | | total IO per sec (* see notes) | | | [0].use | X | X | X | used in % |
| - ms | X | X | | interval length (for per second values) | | | [0].mount | X | X | X | mount point |
| si.networkInterfaces(cb) | X | X | | array of network interfaces | | si.blockDevices(cb) | [{...}] | X | X | X | returns array of disks, partitions,<br>raids and roms |
| - [0].iface | X | X | | interface name | | | [0].name | X | X | X | name |
| - [0].ip4 | X | X | | ip4 address | | | [0].type | X | X | X | type |
| - [0].ip6 | X | X | | ip6 address | | | [0].fstype | X | X | X | file system type (e.g. ext4) |
| - [0].mac | X | X | | MAC address | | | [0].mount | X | X | X | mount point |
| - [0].internal | X | X | | true if internal interface | | | [0].size | X | X | X | size in bytes |
| si.networkInterfaceDefault(cb) | X | X | | get name of default network interface | | | [0].physical | X | X | X | physical type (HDD, SSD, CD/DVD) |
| si.networkStats(iface,cb) | X | X | | current network stats of given interface<br>iface parameter is optional<br>defaults to first external network interface| | | [0].uuid | X | X | X | UUID |
| - iface | X | X | | interface | | | [0].label | X | X | X | label |
| - operstate | X | X | | up / down | | | [0].model | X | X | | model |
| - rx | X | X | | received bytes overall | | | [0].serial | X | | X | serial |
| - tx | X | X | | transferred bytes overall| | | [0].removable | X | X | X | serial |
| - rx_sec | X | X | | received bytes / second (* see notes) | | | [0].protocol | X | X | | protocol (SATA, PCI-Express, ...) |
| - tx_sec | X | X | | transferred bytes per second (* see notes) | | si.fsStats(cb) | {...} | X | X | | current transfer stats |
| - ms | X | X | | interval length (for per second values) | | | rx | X | X | | bytes read since startup |
| si.networkConnections(cb) | X | X | | current network network connections<br>returns an array of all connections| | | wx | X | X | | bytes written since startup |
| - [0].protocol | X | X | | tcp or udp | | | tx | X | X | | total bytes read + written since startup |
| - [0].localaddress | X | X | | local address | | | rx_sec | X | X | | bytes read / second (* see notes) |
| - [0].localport | X | X | | local port | | | wx_sec | X | X | | bytes written / second (* see notes) |
| - [0].peeraddress | X | X | | peer address | | | tx_sec | X | X | | total bytes reads + written / second |
| - [0].peerport | X | X | | peer port | | | ms | X | X | | interval length (for per second values) |
| - [0].state | X | X | | like ESTABLISHED, TIME_WAIT, ... | | si.disksIO(cb) | {...} | X | X | | current transfer stats |
| si.currentLoad(cb) | X | X | | CPU-Load | | | rIO | X | X | | read IOs on all mounted drives |
| - avgload | X | X | | average load | | | wIO | X | X | | write IOs on all mounted drives |
| - currentload | X | X | | CPU-Load in % | | | tIO | X | X | | write IOs on all mounted drives |
| - currentload_user | X | X | | CPU-Load User in % | | | rIO_sec | X | X | | read IO per sec (* see notes) |
| - currentload_nice | X | X | | CPU-Load Nice in % | | | wIO_sec | X | X | | write IO per sec (* see notes) |
| - currentload_system | X | X | | CPU-Load System in % | | | tIO_sec | X | X | | total IO per sec (* see notes) |
| - currentload_irq | X | X | | CPU-Load System in % | | | ms | X | X | | interval length (for per second values) |
| - cpus[] | X | X | | current loads per CPU in % |
| si.fullLoad(cb) | X | X | | CPU-full load since bootup in % | #### 6. Network related functions
| si.services('mysql, apache2', cb) | X | X | | pass comma separated string of services |
| - [0].name | X | X | | name of service | | Function | Result object | Linux | OSX | Win | Comments |
| - [0].running | X | X | | true / false | | --------------- | ----- | ----- | ---- | ------- | -------- |
| - [0].pcpu | X | X | | process % CPU | | si.networkInterfaces(cb) | [{...}] | X | X | X | array of network interfaces |
| - [0].pmem | X | X | | process % MEM | | | [0].iface | X | X | X | interface name |
| si.processes(cb) | X | X | | # running processes | | | [0].ip4 | X | X | X | ip4 address |
| - all | X | X | | # of all processes | | | [0].ip6 | X | X | X | ip6 address |
| - running | X | X | | # of all processes running | | | [0].mac | X | X | X | MAC address |
| - blocked | X | X | | # of all processes blocked | | | [0].internal | X | X | X | true if internal interface |
| - sleeping | X | X | | # of all processes sleeping | | si.networkInterfaceDefault(cb) | : string | X | X | | get name of default network interface |
| - list[] | X | X | | list of all processes incl. details | | si.networkStats(iface,cb) | {...} | X | X | | current network stats of given interface<br>iface parameter is optional<br>defaults to first external network interface|
| - ...[0].pid | X | X | | process PID | | | iface | X | X | | interface |
| - ...[0].pcpu | X | X | | process % CPU usage | | | operstate | X | X | | up / down |
| - ...[0].pcpuu | X | | | process % CPU usage (user) | | | rx | X | X | | received bytes overall |
| - ...[0].pcpus | X | | | process % CPU usage (system) | | | tx | X | X | | transferred bytes overall|
| - ...[0].pmem | X | X | | process memory % | | | rx_sec | X | X | | received bytes / second (* see notes) |
| - ...[0].priority | X | X | | process priotity | | | tx_sec | X | X | | transferred bytes per second (* see notes) |
| - ...[0].mem_vsz | X | X | | process virtual memory size | | | ms | X | X | | interval length (for per second values) |
| - ...[0].mem_rss | X | X | | process mem resident set size | | si.networkConnections(cb) | [{...}] | X | X | | current network network connections<br>returns an array of all connections|
| - ...[0].nice | X | X | | process nice value | | | [0].protocol | X | X | | tcp or udp |
| - ...[0].started | X | X | | process start time | | | [0].localaddress | X | X | | local address |
| - ...[0].state | X | X | | process state (e.g. sleeping) | | | [0].localport | X | X | | local port |
| - ...[0].tty | X | X | | tty from which process was started | | | [0].peeraddress | X | X | | peer address |
| - ...[0].user | X | X | | user who started process | | | [0].peerport | X | X | | peer port |
| - ...[0].command | X | X | | process starting command | | | [0].state | X | X | | like ESTABLISHED, TIME_WAIT, ... |
| si.processLoad('apache2',cb) | X | X | | detailed information about given process | | si.inetChecksite(url, cb) | {...} | X | X | | response-time (ms) to fetch given URL |
| - proc | X | X | | process name | | | url | X | X | | given url |
| - pid | X | X | | PID | | | ok | X | X | | status code OK (2xx, 3xx) |
| - cpu | X | X | | process % CPU | | | status | X | X | | status code |
| - mem | X | X | | process % MEM | | | ms | X | X | | response time in ms |
| si.users(cb) | X | X | | array of users online | | si.inetLatency(host, cb) | | X | X | | response-time (ms) to external resource<br>host parameter is optional (default 8.8.8.8)|
| - [0].user | X | X | | user name |
| - [0].tty | X | X | | terminal | #### 7. Current Load, Processes & Services
| - [0].date | X | X | | login date |
| - [0].time | X | X | | login time | | Function | Result object | Linux | OSX | Win | Comments |
| - [0].ip | X | X | | ip address (remote login) | | --------------- | ----- | ----- | ---- | ------- | -------- |
| - [0].command | X | X | | last command or shell | | si.currentLoad(cb) | {...} | X | X | | CPU-Load |
| si.inetChecksite(url, cb) | X | X | | response-time (ms) to fetch given URL | | | avgload | X | X | | average load |
| - url | X | X | | given url | | | currentload | X | X | | CPU-Load in % |
| - ok | X | X | | status code OK (2xx, 3xx) | | | currentload_user | X | X | | CPU-Load User in % |
| - status | X | X | | status code | | | currentload_nice | X | X | | CPU-Load Nice in % |
| - ms | X | X | | response time in ms | | | currentload_system | X | X | | CPU-Load System in % |
| si.inetLatency(host, cb) | X | X | | response-time (ms) to external resource<br>host parameter is optional (default 8.8.8.8)| | | currentload_irq | X | X | | CPU-Load System in % |
| si.dockerContainers(all, cb) | X | X | | returns array of active/all docker containers | | | cpus[] | X | X | | current loads per CPU in % |
| - [0].id | X | X | | ID of container | | si.fullLoad(cb) | : integer | X | X | | CPU-full load since bootup in % |
| - [0].name | X | X | | name of container | | si.processes(cb) | {...} | X | X | | # running processes |
| - [0].image | X | X | | name of image | | | all | X | X | | # of all processes |
| - [0].imageID | X | X | | ID of image | | | running | X | X | | # of all processes running |
| - [0].command | X | X | | command | | | blocked | X | X | | # of all processes blocked |
| - [0].created | X | X | | creation time | | | sleeping | X | X | | # of all processes sleeping |
| - [0].state | X | X | | created, running, exited | | | list[] | X | X | | list of all processes incl. details |
| - [0].ports | X | X | | array of ports | | | ...[0].pid | X | X | | process PID |
| - [0].mounts | X | X | | array of mounts | | | ...[0].pcpu | X | X | | process % CPU usage |
| si.dockerContainerStats(id, cb) | X | X | | statistics for a specific container | | | ...[0].pcpuu | X | | | process % CPU usage (user) |
| - id | X | X | | Container ID | | | ...[0].pcpus | X | | | process % CPU usage (system) |
| - mem_usage | X | X | | memory usage in bytes | | | ...[0].pmem | X | X | | process memory % |
| - mem_limit | X | X | | memory limit (max mem) in bytes | | | ...[0].priority | X | X | | process priotity |
| - mem_percent | X | X | | memory usage in percent | | | ...[0].mem_vsz | X | X | | process virtual memory size |
| - cpu_percent | X | X | | cpu usage in percent | | | ...[0].mem_rss | X | X | | process mem resident set size |
| - pids | X | X | | number of processes | | | ...[0].nice | X | X | | process nice value |
| - netIO.rx | X | X | | received bytes via network | | | ...[0].started | X | X | | process start time |
| - netIO.wx | X | X | | sent bytes via network | | | ...[0].state | X | X | | process state (e.g. sleeping) |
| - blockIO.r | X | X | | bytes read from BlockIO | | | ...[0].tty | X | X | | tty from which process was started |
| - blockIO.w | X | X | | bytes written to BlockIO | | | ...[0].user | X | X | | user who started process |
| - cpu_stats | X | X | | detailed cpu stats | | | ...[0].command | X | X | | process starting command |
| - percpu_stats | X | X | | detailed per cpu stats | | si.processLoad('apache2',cb) | {...} | X | X | | detailed information about given process |
| - memory_stats | X | X | | detailed memory stats | | | proc | X | X | | process name |
| - networks | X | X | | detailed network stats per interface | | | pid | X | X | | PID |
| si.dockerContainerProcesses(id, cb) | X | X | | array of processes inside a container | | | cpu | X | X | | process % CPU |
| - [0].pid_host | X | X | | process ID (host) | | | mem | X | X | | process % MEM |
| - [0].ppid | X | X | | parent process ID | | si.services('mysql, apache2', cb) | [{...}] | X | X | | pass comma separated string of services |
| - [0].pgid | X | X | | process group ID | | | [0].name | X | X | | name of service |
| - [0].user | X | X | | effective user name | | | [0].running | X | X | | true / false |
| - [0].ruser | X | X | | real user name | | | [0].pcpu | X | X | | process % CPU |
| - [0].group | X | X | | effective group name | | | [0].pmem | X | X | | process % MEM |
| - [0].rgroup | X | X | | real group name |
| - [0].stat | X | X | | process state | #### 8. Docker
| - [0].time | X | X | | accumulated CPU time |
| - [0].elapsed | X | X | | elapsed running time | | Function | Result object | Linux | OSX | Win | Comments |
| - [0].nice | X | X | | nice value | | --------------- | ----- | ----- | ---- | ------- | -------- |
| - [0].rss | X | X | | resident set size | | si.dockerContainers(all, cb) | [{...}] | X | X | X | returns array of active/all docker containers |
| - [0].vsz | X | X | | virtual size in Kbytes | | | [0].id | X | X | X | ID of container |
| - [0].command | X | X | | command and arguments | | | [0].name | X | X | X | name of container |
| si.dockerAll(cb) | X | X | | list of all containers including their stats<br>and processes in one single array | | | [0].image | X | X | X | name of image |
| si.getStaticData(cb) | X | X | | all static data at once | | | [0].imageID | X | X | X | ID of image |
| si.getDynamicData(srv,iface,cb) | X | X | | all dynamic data at once | | | [0].command | X | X | X | command |
| si.getAllData(srv,iface,cb) | X | X | | all data at once | | | [0].created | X | X | X | creation time |
| | [0].state | X | X | X | created, running, exited |
| | [0].ports | X | X | X | array of ports |
| | [0].mounts | X | X | X | array of mounts |
| si.dockerContainerStats(id, cb) | {...} | X | X | X | statistics for a specific container |
| | id | X | X | X | Container ID |
| | mem_usage | X | X | X | memory usage in bytes |
| | mem_limit | X | X | X | memory limit (max mem) in bytes |
| | mem_percent | X | X | X | memory usage in percent |
| | cpu_percent | X | X | X | cpu usage in percent |
| | pids | X | X | X | number of processes |
| | netIO.rx | X | X | X | received bytes via network |
| | netIO.wx | X | X | X | sent bytes via network |
| | blockIO.r | X | X | X | bytes read from BlockIO |
| | blockIO.w | X | X | X | bytes written to BlockIO |
| | cpu_stats | X | X | X | detailed cpu stats |
| | percpu_stats | X | X | X | detailed per cpu stats |
| | memory_stats | X | X | X | detailed memory stats |
| | networks | X | X | X | detailed network stats per interface |
| si.dockerContainerProcesses(id, cb) | [{...}] | X | X | X | array of processes inside a container |
| | [0].pid_host | X | X | X | process ID (host) |
| | [0].ppid | X | X | X | parent process ID |
| | [0].pgid | X | X | X | process group ID |
| | [0].user | X | X | X | effective user name |
| | [0].ruser | X | X | X | real user name |
| | [0].group | X | X | X | effective group name |
| | [0].rgroup | X | X | X | real group name |
| | [0].stat | X | X | X | process state |
| | [0].time | X | X | X | accumulated CPU time |
| | [0].elapsed | X | X | X | elapsed running time |
| | [0].nice | X | X | X | nice value |
| | [0].rss | X | X | X | resident set size |
| | [0].vsz | X | X | X | virtual size in Kbytes |
| | [0].command | X | X | X | command and arguments |
| si.dockerAll(cb) | {...} | X | X | X | list of all containers including their stats<br>and processes in one single array |
#### 9. "Get All at once" - functions
| Function | Result object | Linux | OSX | Win | Comments |
| --------------- | ----- | ----- | ---- | ------- | -------- |
| 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) ### cb: Asynchronous Function Calls (callback)
@ -381,6 +407,34 @@ si.networkStats('eth1')
.catch(error => console.error(error)); .catch(error => console.error(error));
``` ```
### About Temperature
#### OSX
Due to some difficulties in NPM with `optionalDependencies` I unfortunately
was getting unexpected warnings on other platforms. So I decided to drop temperature
measurement for OSX - or more specific the automatic installation of the needed dependency.
But if you need to detect OSX temperature just run the following additional
installation command:
```bash
$ npm install osx-temperature-sensor --save
```
`systeminformation` will then detect this additional library and return the temperature when calling systeminformations standard function `cpuTemperature()`
#### Windows
`wmic` - which is used to determine the temperature sometimes needs to be run with admin
privileges. So if you do not get any temperature value, try to run it again with according
privileges. If you still do not get any values, your system might not support this feature.
In some cases we also discovered that `wmic` returned incorrect values.
#### Linux
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`
### *: Additional Notes ### *: Additional Notes
@ -418,7 +472,7 @@ Written by Sebastian Hildebrandt [sebhildebrandt](https://github.com/sebhildebra
OSX Temperature: Credits here are going to: OSX Temperature: Credits here are going to:
- Massimiliano Marcon [mmarcon](https://github.com/mmarcon) - for his work on [smc-code][smc-code-url] - Massimiliano Marcon [mmarcon](https://github.com/mmarcon) for his work on [smc-code][smc-code-url]
- Sébastien Lavoie [lavoiesl](https://github.com/lavoiesl) for his work on [osx-cpu-temp][osx-cpu-temp-url] code. - Sébastien Lavoie [lavoiesl](https://github.com/lavoiesl) for his work on [osx-cpu-temp][osx-cpu-temp-url] code.
## Copyright Information ## Copyright Information

View File

@ -56,10 +56,12 @@ function cpuBrandManufacturer(res) {
return res; return res;
} }
function getValue(lines, property) { function getValue(lines, property, separator) {
separator = separator || ':';
property = property.toLowerCase();
for (let i = 0; i < lines.length; i++) { for (let i = 0; i < lines.length; i++) {
if (lines[i].toLowerCase().startsWith(property)) { if (lines[i].toLowerCase().startsWith(property)) {
const parts = lines[i].split(':'); const parts = lines[i].split(separator);
if (parts.length > 1) { if (parts.length > 1) {
return parts[1].trim(); return parts[1].trim();
} }
@ -155,15 +157,36 @@ function getCpu() {
}) })
} }
if (_windows) { if (_windows) {
exec("wmic cpu get name", function (error, stdout) { exec("wmic cpu get name, description, revision, l2cachesize, l3cachesize, manufacturer, currentclockspeed, maxclockspeed /value", function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0); let lines = stdout.split('\r\n');
let line = (lines && lines[0]) ? lines[0] : ''; let name = getValue(lines, 'name', '=') || '';
result.brand = line.split('@')[0].trim(); result.brand = name.split('@')[0].trim();
result.speed = line.split('@')[1].trim(); result.speed = name.split('@')[1].trim();
result.speed = parseFloat(result.speed.replace(/GHz+/g, "")); result.speed = parseFloat(result.speed.replace(/GHz+/g, "").trim()).toFixed(2);
_cpu_speed = result.speed; _cpu_speed = result.speed;
result = cpuBrandManufacturer(result); result = cpuBrandManufacturer(result);
result.revision = getValue(lines, 'revision', '=');
result.cache.l2 = getValue(lines, 'l2cachesize', '=');
result.cache.l3 = getValue(lines, 'l3cachesize', '=');
if (result.cache.l2) { result.cache.l2 = parseInt(result.cache.l2) * 1024}
if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3) * 1024}
result.vendor = getValue(lines, 'manufacturer', '=');
result.speedmax = Math.round(parseFloat(getValue(lines, 'maxclockspeed', '=').replace(/,/g, '.')) / 10.0) / 100;
result.speedmax = result.speedmax ? parseFloat(result.speedmax).toFixed(2) : ''
let description = getValue(lines, 'description', '=').split(' ');
for (let i = 0; i < description.length; i++) {
if (description[i].toLowerCase().startsWith('family') && (i+1) < description.length && description[i+1]) {
result.family = description[i+1]
}
if (description[i].toLowerCase().startsWith('model') && (i+1) < description.length && description[i+1]) {
result.model = description[i+1]
}
if (description[i].toLowerCase().startsWith('stepping') && (i+1) < description.length && description[i+1]) {
result.stepping = description[i+1]
}
}
} }
resolve(result); resolve(result);
}) })
@ -209,9 +232,9 @@ function getCpuCurrentSpeedSync() {
} }
avgFreq = avgFreq / cpus.length; avgFreq = avgFreq / cpus.length;
return { return {
min: parseFloat((minFreq / 1000).toFixed(2)), min: parseFloat(((minFreq + 1) / 1000).toFixed(2)),
max: parseFloat((maxFreq / 1000).toFixed(2)), max: parseFloat(((maxFreq + 1) / 1000).toFixed(2)),
avg: parseFloat((avgFreq / 1000).toFixed(2)) avg: parseFloat(((avgFreq + 1) / 1000).toFixed(2))
} }
} else { } else {
return { return {
@ -333,9 +356,9 @@ function cpuTemperature(callback) {
if (result.cores.length) { if (result.cores.length) {
result.main = sum / result.cores.length; result.main = sum / result.cores.length;
} }
if (callback) { callback(result) }
resolve(result);
} }
if (callback) { callback(result) }
resolve(result);
}); });
} }
}); });
@ -397,11 +420,6 @@ function cpuCache(callback) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
process.nextTick(() => { process.nextTick(() => {
if (_windows) {
let error = new Error(NOT_SUPPORTED);
if (callback) { callback(NOT_SUPPORTED) }
reject(error);
}
let result = {}; let result = {};
if (_linux) { if (_linux) {
@ -452,6 +470,19 @@ function cpuCache(callback) {
resolve(result); resolve(result);
}); });
} }
if (_windows) {
exec("wmic cpu get l2cachesize, l3cachesize /value", function (error, stdout) {
if (!error) {
let lines = stdout.split('\r\n');
result.l2 = getValue(lines, 'l2cachesize', '=');
result.l3 = getValue(lines, 'l3cachesize', '=');
if (result.l2) { result.l2 = parseInt(result.l2) * 1024}
if (result.l3) { result.l3 = parseInt(result.l3) * 1024}
}
if (callback) { callback(result) }
resolve(result);
})
}
}); });
}); });
} }

View File

@ -51,12 +51,6 @@ function dockerContainers(all, callback) {
let result = []; let result = [];
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
process.nextTick(() => { process.nextTick(() => {
if (_windows) {
let error = new Error(NOT_SUPPORTED);
if (callback) { callback(NOT_SUPPORTED) }
reject(error);
}
if (!_docker_socket) { if (!_docker_socket) {
_docker_socket = new DockerSocket(); _docker_socket = new DockerSocket();
} }
@ -226,11 +220,6 @@ function dockerContainerStats(containerID, callback) {
}; };
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
process.nextTick(() => { process.nextTick(() => {
if (_windows) {
let error = new Error(NOT_SUPPORTED);
if (callback) { callback(NOT_SUPPORTED) }
reject(error);
}
if (containerID) { if (containerID) {
if (!_docker_socket) { if (!_docker_socket) {
@ -294,11 +283,6 @@ function dockerContainerProcesses(containerID, callback) {
let result = []; let result = [];
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
process.nextTick(() => { process.nextTick(() => {
if (_windows) {
let error = new Error(NOT_SUPPORTED);
if (callback) { callback(NOT_SUPPORTED) }
reject(error);
}
if (containerID) { if (containerID) {
if (!_docker_socket) { if (!_docker_socket) {
@ -368,11 +352,6 @@ exports.dockerContainerProcesses = dockerContainerProcesses;
function dockerAll(callback) { function dockerAll(callback) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
process.nextTick(() => { process.nextTick(() => {
if (_windows) {
let error = new Error(NOT_SUPPORTED);
if (callback) { callback(NOT_SUPPORTED) }
reject(error);
}
dockerContainers(true).then(result => { dockerContainers(true).then(result => {
if (result && Object.prototype.toString.call(result) === '[object Array]' && result.length > 0) { if (result && Object.prototype.toString.call(result) === '[object Array]' && result.length > 0) {
let l = result.length; let l = result.length;

View File

@ -1,13 +1,15 @@
'use strict'; 'use strict';
const net = require('net'); const net = require('net');
const isWin = require('os').type() === 'Windows_NT';
const socketPath = isWin ? '//./pipe/docker_engine' : '/var/run/docker.sock';
class DockerSocket { class DockerSocket {
listContainers(all, callback) { listContainers(all, callback) {
try { try {
let socket = net.createConnection({path: '/var/run/docker.sock'}); let socket = net.createConnection({path: socketPath});
let alldata = ''; let alldata = '';
socket.on("connect", () => { socket.on("connect", () => {
@ -38,7 +40,7 @@ class DockerSocket {
id = id || ''; id = id || '';
if (id) { if (id) {
try { try {
let socket = net.createConnection({path: '/var/run/docker.sock'}); let socket = net.createConnection({path: socketPath});
let alldata = ''; let alldata = '';
socket.on("connect", () => { socket.on("connect", () => {
@ -72,7 +74,7 @@ class DockerSocket {
id = id || ''; id = id || '';
if (id) { if (id) {
try { try {
let socket = net.createConnection({path: '/var/run/docker.sock'}); let socket = net.createConnection({path: socketPath});
let alldata = ''; let alldata = '';
socket.on("connect", () => { socket.on("connect", () => {

View File

@ -24,6 +24,20 @@ const _darwin = (_platform === 'Darwin');
const _windows = (_platform === 'Windows_NT'); const _windows = (_platform === 'Windows_NT');
const NOT_SUPPORTED = 'not supported'; const NOT_SUPPORTED = 'not supported';
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 graphics(callback) { function graphics(callback) {
function parseLinesDarwin(lines) { function parseLinesDarwin(lines) {
@ -252,13 +266,6 @@ function graphics(callback) {
// function starts here // function starts here
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
process.nextTick(() => { process.nextTick(() => {
if (_windows) {
let error = new Error(NOT_SUPPORTED);
if (callback) {
callback(NOT_SUPPORTED)
}
reject(error);
}
let result = { let result = {
controllers: [], controllers: [],
displays: [] displays: []
@ -304,6 +311,26 @@ function graphics(callback) {
}) })
}) })
} }
if (_windows) {
// 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) {
if (!error) {
let lines = stdout.split('\r\n');
result.controllers.push({});
result.displays.push({});
result.controllers[0].model = getValue(lines, 'name', '=');
result.controllers[0].vendor = getValue(lines, 'AdapterCompatibility', '=');
result.controllers[0].bus = getValue(lines, 'PNPDeviceID', '=').startsWith('PCI') ? 'PCI' : '';
result.controllers[0].vram = getValue(lines, 'AdapterRAM', '=');
result.displays[0].resolutionx = getValue(lines, 'CurrentHorizontalResolution', '=');
result.displays[0].resolutiony = getValue(lines, 'CurrentVerticalResolution', '=');
result.displays[0].depth = getValue(lines, 'CurrentBitsPerPixel', '=');
}
resolve(result);
})
}
}); });
}); });
} }

View File

@ -82,6 +82,7 @@
// -------------------------------- // --------------------------------
// //
// version date comment // version date comment
// 3.20.0 2017-06-16 extend windows support (cpu, cpuCache, cpuCurrentspeed, mem, networkInterfaces, docker)
// 3.19.0 2017-06-12 OSX temperature now an optional dependency // 3.19.0 2017-06-12 OSX temperature now an optional dependency
// 3.18.0 2017-05-27 extended `cpu` info (vendor, family, model, stepping, revision, cache, speedmin/max) // 3.18.0 2017-05-27 extended `cpu` info (vendor, family, model, stepping, revision, cache, speedmin/max)
// 3.17.3 2017-04-29 minor fix (blockDevices data array, Windows) // 3.17.3 2017-04-29 minor fix (blockDevices data array, Windows)

View File

@ -150,6 +150,28 @@ module.exports = function (callback) {
}); });
}); });
} }
if (_windows) {
let swaptotal = 0;
let swapused = 0;
exec("wmic pagefile get AllocatedBaseSize, CurrentUsage", 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+/);
swaptotal = swaptotal + parseInt(line[0]);
swapused = swapused + parseInt(line[1]);
}
});
}
result.swaptotal = swaptotal * 1024 * 1024;
result.swapused = swapused * 1024 * 1024;
result.swapfree = result.swaptotal - result.swapused;
if (callback) { callback(result) }
resolve(result);
});
}
}); });
}); });
}; };

View File

@ -51,8 +51,5 @@
], ],
"engines": { "engines": {
"node": ">=4.0.0" "node": ">=4.0.0"
},
"optionalDependencies": {
"osx-temperature-sensor": "^1.0.0"
} }
} }