first partial FreeBSD support

This commit is contained in:
Sebastian Hildebrandt 2018-02-10 19:19:53 +01:00
parent 42b7f6c42e
commit c22cdad6da
17 changed files with 827 additions and 545 deletions

View File

@ -17,6 +17,7 @@
New Functions New Functions
- FreeBSD support: for some basic functions (new in version 3.34 ff)
- `diskLayout`: returns hard disk layout (new in version 3.23) - `diskLayout`: returns hard disk layout (new in version 3.23)
- `memLayout`: returns memory chip layout (new in version 3.23) - `memLayout`: returns memory chip layout (new in version 3.23)
- Windows support: for some basic functions (new in version 3.17 ff) - Windows support: for some basic functions (new in version 3.17 ff)
@ -99,6 +100,7 @@ Other changes
| Version | Date | Comment | | Version | Date | Comment |
| -------------- | -------------- | -------- | | -------------- | -------------- | -------- |
| 3.34.0 | 2018-02-10 | first partial FreeBSD support |
| 3.33.15 | 2018-01-21 | optimized OSX battery | | 3.33.15 | 2018-01-21 | optimized OSX battery |
| 3.33.14 | 2018-01-17 | bugfix `diskLayout()` (Windows) | | 3.33.14 | 2018-01-17 | bugfix `diskLayout()` (Windows) |
| 3.33.13 | 2018-01-12 | bugfix `memLayout()` (Windows) | | 3.33.13 | 2018-01-12 | bugfix `memLayout()` (Windows) |

624
README.md
View File

@ -11,7 +11,7 @@ Simple system and OS information library for [node.js][nodejs-url]
## Quick Start ## Quick Start
Lightweight collection of 35+ functions to retrieve detailed hardware, system and OS information (Linux, OSX and partial Windows support) - no npm dependencies. Lightweight collection of 35+ functions to retrieve detailed hardware, system and OS information (Linux, OSX, partial Windows and FreeBSD support) - no npm dependencies.
### Installation ### Installation
@ -53,13 +53,13 @@ async function cpu() {
### Latest Activity ### Latest Activity
(last 7 major and minor version releases) (last 7 major and minor version releases)
- Version 3.34.0: first partial FreeBSD support
- Version 3.33.0: added bios `bios()` and main board `baseboard()` information - Version 3.33.0: added bios `bios()` and main board `baseboard()` information
- Version 3.32.0: extended `memLayout()` - added manufacturer - Version 3.32.0: extended `memLayout()` - added manufacturer
- Version 3.31.0: extended windows support `cpuFlags()` (partially) - Version 3.31.0: extended windows support `cpuFlags()` (partially)
- Version 3.30.0: extended `versions()` (added `yarn`, `gulp`, `grunt`, `tsc`, `git`) - Version 3.30.0: extended `versions()` (added `yarn`, `gulp`, `grunt`, `tsc`, `git`)
- Version 3.29.0: extended windows support `services()` - Version 3.29.0: extended windows support `services()`
- Version 3.28.0: extended windows support `processes()` - Version 3.28.0: extended windows support `processes()`
- Version 3.27.0: added raw data to `currentLoad()`, fixed `networkInterfaces()` MAC problem node 8.x
- ... - ...
You can find all changes here: [detailed changelog][changelog-url] You can find all changes here: [detailed changelog][changelog-url]
@ -70,8 +70,8 @@ You can find all changes here: [detailed changelog][changelog-url]
little library. This library is still work in progress. Version 3 comes with further improvements. First it little library. This library is still work in progress. Version 3 comes with further improvements. First it
requires now node.js version 4.0 and above. Another big change is, that all functions now return promises. You can use them 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. 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) and some Windows machines. I was only able to test it on several Debian, Raspbian, Ubuntu distributions as well as OS X (Mavericks, Yosemite, El Captain) and some Windows and FreeBSD machines.
Since version 2 nearly all functionality is available for OS X/Darwin platforms. In Version 3 I started to add (limited!) windows support. Since version 2 nearly all functionality is available for OS X/Darwin platforms. In Version 3 I started to add windows and (partial) FreeBSD support - see docs.
If you have comments, suggestions & reports, please feel free to contact me! If you have comments, suggestions & reports, please feel free to contact me!
@ -84,333 +84,334 @@ I also created a nice little command line tool called [mmon][mmon-github-url] (
#### 1. General #### 1. General
| Function | Result object | Linux | OSX | Win | Comments | | Function | Result object | Linux | FreeBSD | OSX | Win | Comments |
| --------------- | ----- | ----- | ---- | ------- | -------- | | --------------- | ------------- | ----- | ------- | --- | --- | -------- |
| si.version() | : string | X | X | X | lib version (no callback/promise) | | si.version() | : string | X | X | X | X | lib version (no callback/promise) |
| si.time() | {...} | X | X | X | (no callback/promise) | | si.time() | {...} | X | X | X | X | (no callback/promise) |
| | current | X | X | X | local time | | | current | X | X | X | X | local time |
| | uptime | X | X | X | uptime | | | uptime | X | X | X | X | uptime |
| | timezone | X | X | X | e.g. GMT+0200 | | | timezone | X | X | X | X | e.g. GMT+0200 |
| | timezoneName | X | X | X | e.g. CEST | | | timezoneName | X | X | X | X | e.g. CEST |
#### 2. System (HW) #### 2. System (HW)
| Function | Result object | Linux | OSX | Win | Comments | | Function | Result object | Linux | FreeBSD | OSX | Win | Comments |
| --------------- | ----- | ----- | ---- | ------- | -------- | | --------------- | ------------- | ----- | ------- | --- | --- | -------- |
| si.system(cb) | {...} | X | X | X | hardware information | | si.system(cb) | {...} | X | X | X | X | hardware information |
| | manufacturer | X | X | X | e.g. 'MSI' | | | manufacturer | X | X | X | X | e.g. 'MSI' |
| | model | X | X | X | model/product e.g. 'MS-7823' | | | model | X | X | X | X | model/product e.g. 'MS-7823' |
| | version | X | X | X | version e.g. '1.0' | | | version | X | X | X | X | version e.g. '1.0' |
| | serial | X | X | X | serial number | | | serial | X | X | X | X | serial number |
| | uuid | X | X | X | UUID | | | uuid | X | X | X | X | UUID |
| | sku | X | | X | SKU number | | | sku | X | X | | X | SKU number |
| si.bios(cb) | {...} | X | X | X | hardware information | | si.bios(cb) | {...} | X | X | X | X | hardware information |
| | vendor | X | X | X | e.g. 'AMI' | | | vendor | X | X | X | X | e.g. 'AMI' |
| | version | X | | X | version | | | version | X | X | | X | version |
| | releaseDate | X | | X | release date | | | releaseDate | X | X | | X | release date |
| | revision | X | | X | revision | | | revision | X | X | | X | revision |
| si.baseboard(cb) | {...} | X | X | X | hardware information | | si.baseboard(cb) | {...} | X | X | X | X | hardware information |
| | manufacturer | X | X | X | e.g. 'ASUS' | | | manufacturer | X | X | X | X | e.g. 'ASUS' |
| | model | X | X | X | model / product name | | | model | X | X | X | X | model / product name |
| | version | X | X | X | version | | | version | X | X | X | X | version |
| | serial | X | X | X | serial number | | | serial | X | X | X | X | serial number |
| | assetTag | X | X | X | asset tag | | | assetTag | X | X | X | X | asset tag |
#### 3. CPU, Memory, Disks, Battery, Graphics #### 3. CPU, Memory, Disks, Battery, Graphics
| Function | Result object | Linux | OSX | Win | Comments | | Function | Result object | Linux | FreeBSD | OSX | Win | Comments |
| --------------- | ----- | ----- | ---- | ------- | -------- | | --------------- | ------------- | ----- | ------- | --- | --- | -------- |
| si.cpu(cb) | {...} | X | X | X | CPU information| | si.cpu(cb) | {...} | X | X | X | X | CPU information|
| | manufacturer | X | X | X | e.g. 'Intel(R)' | | | manufacturer | X | X | X | X | e.g. 'Intel(R)' |
| | brand | X | X | X | e.g. 'Core(TM)2 Duo' | | | brand | X | X | X | X | e.g. 'Core(TM)2 Duo' |
| | speed | X | X | X | in GHz e.g. '3.40' | | | speed | X | X | X | X | in GHz e.g. '3.40' |
| | speedmin | X | X | X | in GHz e.g. '0.80' | | | speedmin | X | | X | X | in GHz e.g. '0.80' |
| | speedmax | X | X | X | in GHz e.g. '3.90' | | | speedmax | X | X | X | X | in GHz e.g. '3.90' |
| | cores | X | X | X | # cores | | | cores | X | X | X | X | # cores |
| | vendor | X | X | X | vendor ID | | | vendor | X | X | X | X | vendor ID |
| | family | X | X | X | processor family | | | family | X | X | X | X | processor family |
| | Model | X | X | X | processor model | | | Model | X | X | X | X | processor model |
| | stepping | X | X | X | processor stepping | | | stepping | X | X | X | X | processor stepping |
| | revision | X | X | X | revision | | | revision | X | | X | X | revision |
| | cache | X | X | X | cache in bytes (object) | | | voltage | | X | | | voltage |
| | cache.l1d | X | X | X | L1D (data) size | | | cache | X | X | X | X | cache in bytes (object) |
| | cache.l1i | X | X | X | L1I (instruction) size | | | cache.l1d | X | X | X | X | L1D (data) size |
| | cache.l2 | X | X | X | L2 size | | | cache.l1i | X | X | X | X | L1I (instruction) size |
| | cache.l3 | X | X | X | L3 size | | | cache.l2 | X | X | X | X | L2 size |
| si.cpuFlags(cb) | : string | X | X | X | CPU flags| | | cache.l3 | X | X | X | X | L3 size |
| si.cpuCache(cb) | {...} | X | X | X | CPU cache sizes | | si.cpuFlags(cb) | : string | X | X | X | X | CPU flags|
| | l1d | X | X | X | L1D size | | si.cpuCache(cb) | {...} | X | X | X | X | CPU cache sizes |
| | l1i | X | X | X | L1I size | | | l1d | X | X | X | X | L1D size |
| | l2 | X | X | X | L2 size | | | l1i | X | X | X | X | L1I size |
| | l3 | X | X | X | L3 size | | | l2 | X | X | X | X | L2 size |
| si.cpuCurrentspeed(cb) | {...} | X | X | X | current CPU speed (in GHz)| | | l3 | X | X | X | X | L3 size |
| | avg | X | X | X | avg CPU speed (all cores) | | si.cpuCurrentspeed(cb) | {...} | X | X | X | X | current CPU speed (in GHz)|
| | min | X | X | X | min CPU speed (all cores) | | | avg | X | X | X | X | avg CPU speed (all cores) |
| | max | X | X | X | max CPU speed (all cores) | | | min | X | X | X | X | min CPU speed (all cores) |
| si.cpuTemperature(cb) | {...} | X | X* | X | CPU temperature (if supported) | | | max | X | X | X | X | max CPU speed (all cores) |
| | main | X | X | X | main temperature (avg) | | si.cpuTemperature(cb) | {...} | X | X | X* | X | CPU temperature (if supported) |
| | cores | X | X | X | array of temperatures | | | main | X | X | X | X | main temperature (avg) |
| | max | X | X | X | max temperature | | | cores | X | X | X | X | array of temperatures |
| si.mem(cb) | {...} | X | X | X | Memory information (in bytes)| | | max | X | X | X | X | max temperature |
| | total | X | X | X | total memory in bytes | | si.mem(cb) | {...} | X | X | X | X | Memory information (in bytes)|
| | free | X | X | X | not used in bytes | | | total | X | X | X | X | total memory in bytes |
| | used | X | X | X | used (incl. buffers/cache) | | | free | X | X | X | X | not used in bytes |
| | active | X | X | X | used actively (excl. buffers/cache) | | | used | X | X | X | X | used (incl. buffers/cache) |
| | buffcache | X | X | | used by buffers+cache | | | active | X | X | X | X | used actively (excl. buffers/cache) |
| | available | X | X | X | potentially available (total - active) | | | buffcache | X | X | X | | used by buffers+cache |
| | swaptotal | X | X | X | | | | available | X | X | X | X | potentially available (total - active) |
| | swapused | X | X | X | | | | swaptotal | X | X | X | X | |
| | swapfree | X | X | X | | | | swapused | X | X | X | X | |
| si.memLayout(cb) | {...} | X | X | X | Memory Layout | | | swapfree | X | X | X | X | |
| | size | X | X | X | size in bytes | | si.memLayout(cb) | {...} | X | X | X | X | Memory Layout |
| | bank | X | | X | memory bank | | | size | X | X | X | X | size in bytes |
| | type | X | X | X | memory type | | | bank | X | X | | X | memory bank |
| | clockSpeed | X | X | X | clock speed | | | type | X | X | X | X | memory type |
| | formFactor | X | | X | form factor | | | clockSpeed | X | X | X | X | clock speed |
| | manufacturer | X | X | X | manufacturer | | | formFactor | X | X | | X | form factor |
| | partNum | X | X | X | part number | | | manufacturer | X | X | X | X | manufacturer |
| | serialNum | X | X | X | serial number | | | partNum | X | X | X | X | part number |
| | voltageConfigured | X | | X | voltage conf. | | | serialNum | X | X | X | X | serial number |
| | voltageMin | X | | X | voltage min | | | voltageConfigured | X | X | | X | voltage conf. |
| | voltageMax | X | | X | voltage max | | | voltageMin | X | X | | X | voltage min |
| si.diskLayout(cb) | {...} | X | X | X | physical disk layout (HD) | | | voltageMax | X | X | | X | voltage max |
| | type | X | X | X | HD, SSD | | si.diskLayout(cb) | {...} | X | | X | X | physical disk layout (HD) |
| | name | X | X | X | disk name | | | type | X | | X | X | HD, SSD |
| | vendor | X | | X | vendor/producer | | | name | X | | X | X | disk name |
| | firmwareRevision | X | X | X | firmware revision | | | vendor | X | | | X | vendor/producer |
| | serialNum | X | X | X | serial number | | | firmwareRevision | X | | X | X | firmware revision |
| | interfaceType | | | X | | | | serialNum | X | | X | X | serial number |
| | size | X | X | X | size in bytes | | | interfaceType | | | | X | |
| | totalCylinders | | | X | total cylinders | | | size | X | | X | X | size in bytes |
| | totalHeads | | | X | total heads | | | totalCylinders | | | | X | total cylinders |
| | totalTracks | | | X | total tracks | | | totalHeads | | | | X | total heads |
| | tracksPerCylinder | | | X | tracks per cylinder | | | totalTracks | | | | X | total tracks |
| | sectorsPerTrack | | | X | sectors per track | | | tracksPerCylinder | | | | X | tracks per cylinder |
| | totalSectors | | | X | total sectors | | | sectorsPerTrack | | | | X | sectors per track |
| | bytesPerSector | | | X | bytes per sector | | | totalSectors | | | | X | total sectors |
| si.battery(cb) | {...} | X | X | X | battery information | | | bytesPerSector | | | | X | bytes per sector |
| | hasbattery | X | X | X | indicates presence of battery | | si.battery(cb) | {...} | X | X | X | X | battery information |
| | cyclecount | X | X | | numbers of recharges | | | hasbattery | X | X | X | X | indicates presence of battery |
| | ischarging | X | X | X | indicates if battery is charging | | | cyclecount | X | | X | | numbers of recharges |
| | maxcapacity | X | X | X | max capacity of battery | | | ischarging | X | X | X | X | indicates if battery is charging |
| | currentcapacity | X | X | X | current capacity of battery | | | maxcapacity | X | | X | X | max capacity of battery |
| | percent | X | X | X | charging level in percent | | | currentcapacity | X | | X | X | current capacity of battery |
| si.graphics(cb) | {...} | X | X | X | arrays of graphics controllers and displays | | | percent | X | X | X | X | charging level in percent |
| | controllers[]| X | X | X | graphics controllers array | | si.graphics(cb) | {...} | X | | X | X | arrays of graphics controllers and displays |
| | ...[0].model | X | X | X | graphics controller model | | | controllers[]| X | | X | X | graphics controllers array |
| | ...[0].vendor | X | X | X | e.g. ATI | | | ...[0].model | X | | X | X | graphics controller model |
| | ...[0].bus | X | X | X| on which bus (e.g. PCIe) | | | ...[0].vendor | X | | X | X | e.g. ATI |
| | ...[0].vram | X | X | X | VRAM size (in MB) | | | ...[0].bus | X | | X | X| on which bus (e.g. PCIe) |
| | ...[0].vramDynamic | X | X | X | true if dynamicly allocated ram | | | ...[0].vram | X | | X | X | VRAM size (in MB) |
| | displays[] | X | X | X | monitor/display Array | | | ...[0].vramDynamic | X | | X | X | true if dynamicly allocated ram |
| | ...[0].model | X | X | X | monitor/display Model | | | displays[] | X | | X | X | monitor/display Array |
| | ...[0].main | X | X | | true if main monitor | | | ...[0].model | X | | X | X | monitor/display Model |
| | ...[0].builtin | X | X | | true if built in monitor | | | ...[0].main | X | | X | | true if main monitor |
| | ...[0].connection | X | X | | e.g. DisplayPort or HDMI | | | ...[0].builtin | X | | X | | true if built in monitor |
| | ...[0].resolutionx | X | X | X | pixel horizontal | | | ...[0].connection | X | | X | | e.g. DisplayPort or HDMI |
| | ...[0].resolutiony | X | X | X | pixel vertical | | | ...[0].resolutionx | X | | X | X | pixel horizontal |
| | ...[0].pixeldepth | X | X | X | color depth in bits | | | ...[0].resolutiony | X | | X | X | pixel vertical |
| | ...[0].sizex | X | X | | size in mm horizontal | | | ...[0].pixeldepth | X | | X | X | color depth in bits |
| | ...[0].sizey | X | X | | size in mm vertical | | | ...[0].sizex | X | | X | | size in mm horizontal |
| | ...[0].sizey | X | | X | | size in mm vertical |
#### 4. Operating System #### 4. Operating System
| Function | Result object | Linux | OSX | Win | Comments | | Function | Result object | Linux | FreeBSD | OSX | Win | Comments |
| --------------- | ----- | ----- | ---- | ------- | -------- | | --------------- | ------------- | ----- | ------- | --- | --- | -------- |
| si.osInfo(cb) | {...} | X | X | X | OS information | | si.osInfo(cb) | {...} | X | X | X | X | OS information |
| | platform | X | X | X | 'Linux', 'Darwin', 'Windows' | | | platform | X | X | X | X | 'Linux', 'Darwin', 'Windows' |
| | distro | X | X | X | | | | distro | X | X | X | X | |
| | release | X | X | X | | | | release | X | X | X | X | |
| | codename | | X | | | | | codename | | | X | | |
| | kernel | X | X | X | kernel release - same as os.release() | | | kernel | X | X | X | X | kernel release - same as os.release() |
| | arch | X | X | X | same as os.arch() | | | arch | X | X | X | X | same as os.arch() |
| | hostname | X | X | X | same as os.hostname() | | | hostname | X | X | X | X | same as os.hostname() |
| | logofile | X | X | X | e.g. 'apple', 'debian', 'fedora', ... | | | logofile | X | X | X | X | e.g. 'apple', 'debian', 'fedora', ... |
| si.versions(cb) | {...} | X | X | X | version information (kernel, ssl, node, ...) | | si.versions(cb) | {...} | X | X | X | X | version information (kernel, ssl, node, ...) |
| si.shell(cb) | : string | X | X | | standard shell | | si.shell(cb) | : string | X | X | X | | standard shell |
| si.users(cb) | [{...}] | X | X | X | array of users online | | si.users(cb) | [{...}] | X | X | X | X | array of users online |
| | [0].user | X | X | X | user name | | | [0].user | X | X | X | X | user name |
| | [0].tty | X | X | X | terminal | | | [0].tty | X | X | X | X | terminal |
| | [0].date | X | X | X | login date | | | [0].date | X | X | X | X | login date |
| | [0].time | X | X | X | login time | | | [0].time | X | X | X | X | login time |
| | [0].ip | X | X | | ip address (remote login) | | | [0].ip | X | X | X | | ip address (remote login) |
| | [0].command | X | X | | last command or shell | | | [0].command | X | X | X | | last command or shell |
#### 5. File System #### 5. File System
| Function | Result object | Linux | OSX | Win | Comments | | Function | Result object | Linux | FreeBSD | OSX | Win | Comments |
| --------------- | ----- | ----- | ---- | ------- | -------- | | --------------- | ------------- | ----- | ------- | --- | --- | -------- |
| si.fsSize(cb) | [{...}] | X | X | X | returns array of mounted file systems | | si.fsSize(cb) | [{...}] | X | X | X | X | returns array of mounted file systems |
| | [0].fs | X | X | X | name of file system | | | [0].fs | X | X | X | X | name of file system |
| | [0].type | X | X | X | type of file system | | | [0].type | X | X | X | X | type of file system |
| | [0].size | X | X | X | sizes in bytes | | | [0].size | X | X | X | X | sizes in bytes |
| | [0].used | X | X | X | used in bytes | | | [0].used | X | X | X | X | used in bytes |
| | [0].use | X | X | X | used in % | | | [0].use | X | X | X | X | used in % |
| | [0].mount | X | X | X | mount point | | | [0].mount | X | X | X | X | mount point |
| si.blockDevices(cb) | [{...}] | X | X | X | returns array of disks, partitions,<br>raids and roms | | si.blockDevices(cb) | [{...}] | X | | X | X | returns array of disks, partitions,<br>raids and roms |
| | [0].name | X | X | X | name | | | [0].name | X | | X | X | name |
| | [0].type | X | X | X | type | | | [0].type | X | | X | X | type |
| | [0].fstype | X | X | X | file system type (e.g. ext4) | | | [0].fstype | X | | X | X | file system type (e.g. ext4) |
| | [0].mount | X | X | X | mount point | | | [0].mount | X | | X | X | mount point |
| | [0].size | X | X | X | size in bytes | | | [0].size | X | | X | X | size in bytes |
| | [0].physical | X | X | X | physical type (HDD, SSD, CD/DVD) | | | [0].physical | X | | X | X | physical type (HDD, SSD, CD/DVD) |
| | [0].uuid | X | X | X | UUID | | | [0].uuid | X | | X | X | UUID |
| | [0].label | X | X | X | label | | | [0].label | X | | X | X | label |
| | [0].model | X | X | | model | | | [0].model | X | | X | | model |
| | [0].serial | X | | X | serial | | | [0].serial | X | | | X | serial |
| | [0].removable | X | X | X | serial | | | [0].removable | X | | X | X | serial |
| | [0].protocol | X | X | | protocol (SATA, PCI-Express, ...) | | | [0].protocol | X | | X | | protocol (SATA, PCI-Express, ...) |
| si.fsStats(cb) | {...} | X | X | | current transfer stats | | si.fsStats(cb) | {...} | X | | X | | current transfer stats |
| | rx | X | X | | bytes read since startup | | | rx | X | | X | | bytes read since startup |
| | wx | X | X | | bytes written since startup | | | wx | X | | X | | bytes written since startup |
| | tx | X | X | | total bytes read + written since startup | | | tx | X | | X | | total bytes read + written since startup |
| | rx_sec | X | X | | bytes read / second (* see notes) | | | rx_sec | X | | X | | bytes read / second (* see notes) |
| | wx_sec | X | X | | bytes written / second (* see notes) | | | wx_sec | X | | X | | bytes written / second (* see notes) |
| | tx_sec | X | X | | total bytes reads + written / second | | | tx_sec | X | | X | | total bytes reads + written / second |
| | ms | X | X | | interval length (for per second values) | | | ms | X | | X | | interval length (for per second values) |
| si.disksIO(cb) | {...} | X | X | | current transfer stats | | si.disksIO(cb) | {...} | X | | X | | current transfer stats |
| | rIO | X | X | | read IOs on all mounted drives | | | rIO | X | | X | | read IOs on all mounted drives |
| | wIO | X | X | | write IOs on all mounted drives | | | wIO | X | | X | | write IOs on all mounted drives |
| | tIO | 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) | | | rIO_sec | X | | X | | read IO per sec (* see notes) |
| | wIO_sec | X | X | | write 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) | | | tIO_sec | X | | X | | total IO per sec (* see notes) |
| | ms | X | X | | interval length (for per second values) | | | ms | X | | X | | interval length (for per second values) |
#### 6. Network related functions #### 6. Network related functions
| Function | Result object | Linux | OSX | Win | Comments | | Function | Result object | Linux | FreeBSD | OSX | Win | Comments |
| --------------- | ----- | ----- | ---- | ------- | -------- | | --------------- | ------------- | ----- | ------- | --- | --- | -------- |
| si.networkInterfaces(cb) | [{...}] | X | X | X | array of network interfaces | | si.networkInterfaces(cb) | [{...}] | X | X | X | X | array of network interfaces |
| | [0].iface | X | X | X | interface name | | | [0].iface | X | X | X | X | interface name |
| | [0].ip4 | X | X | X | ip4 address | | | [0].ip4 | X | X | X | X | ip4 address |
| | [0].ip6 | X | X | X | ip6 address | | | [0].ip6 | X | X | X | X | ip6 address |
| | [0].mac | X | X | X | MAC address | | | [0].mac | X | X | X | X | MAC address |
| | [0].internal | X | X | X | true if internal interface | | | [0].internal | X | X | X | X | true if internal interface |
| si.networkInterfaceDefault(cb) | : string | X | X | X | get name of default network interface | | si.networkInterfaceDefault(cb) | : string | X | 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| | 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 | | | iface | X | | X | X | interface |
| | operstate | X | X | X | up / down | | | operstate | X | | X | X | up / down |
| | rx | X | X | X | received bytes overall | | | rx | X | | X | X | received bytes overall |
| | tx | X | X | X | transferred bytes overall | | | tx | X | | X | X | transferred bytes overall |
| | rx_sec | X | X | X | received bytes / second (* see notes) | | | rx_sec | X | | X | X | received bytes / second (* see notes) |
| | tx_sec | X | X | X | transferred bytes per second (* see notes) | | | tx_sec | X | | X | X | transferred bytes per second (* see notes) |
| | ms | X | X | X | interval length (for per second values) | | | ms | X | | X | X | interval length (for per second values) |
| si.networkConnections(cb) | [{...}] | X | X | X | current network network connections<br>returns an array of all connections| | si.networkConnections(cb) | [{...}] | X | | X | X | current network network connections<br>returns an array of all connections|
| | [0].protocol | X | X | X | tcp or udp | | | [0].protocol | X | | X | X | tcp or udp |
| | [0].localaddress | X | X | X | local address | | | [0].localaddress | X | | X | X | local address |
| | [0].localport | X | X | X | local port | | | [0].localport | X | | X | X | local port |
| | [0].peeraddress | X | X | X | peer address | | | [0].peeraddress | X | | X | X | peer address |
| | [0].peerport | X | X | X | peer port | | | [0].peerport | X | | X | X | peer port |
| | [0].state | X | X | X | like ESTABLISHED, TIME_WAIT, ... | | | [0].state | X | | X | X | like ESTABLISHED, TIME_WAIT, ... |
| si.inetChecksite(url, cb) | {...} | X | X | X | response-time (ms) to fetch given URL | | si.inetChecksite(url, cb) | {...} | X | X | X | X | response-time (ms) to fetch given URL |
| | url | X | X | X | given url | | | url | X | X | X | X | given url |
| | ok | X | X | X | status code OK (2xx, 3xx) | | | ok | X | X | X | X | status code OK (2xx, 3xx) |
| | status | X | X | X | status code | | | status | X | X | X | X | status code |
| | ms | X | X | X | response time in ms | | | ms | X | X | X | X | response time in ms |
| si.inetLatency(host, cb) | : number | X | X | X | response-time (ms) to external resource<br>host parameter is optional (default 8.8.8.8)| | si.inetLatency(host, cb) | : number | X | X | X | X | response-time (ms) to external resource<br>host parameter is optional (default 8.8.8.8)|
#### 7. Current Load, Processes & Services #### 7. Current Load, Processes & Services
| Function | Result object | Linux | OSX | Win | Comments | | Function | Result object | Linux | FreeBSD | OSX | Win | Comments |
| --------------- | ----- | ----- | ---- | ------- | -------- | | --------------- | ------------- | ----- | ------- | --- | --- | -------- |
| si.currentLoad(cb) | {...} | X | X | X | CPU-Load | | si.currentLoad(cb) | {...} | X | | X | X | CPU-Load |
| | avgload | X | X | X | average load | | | avgload | X | | X | X | average load |
| | currentload | X | X | X | CPU load in % | | | currentload | X | | X | X | CPU load in % |
| | currentload_user | X | X | X | CPU load user in % | | | currentload_user | X | | X | X | CPU load user in % |
| | currentload_system | X | X | X | CPU load system in % | | | currentload_system | X | | X | X | CPU load system in % |
| | currentload_nice | X | X | X | CPU load nice in % | | | currentload_nice | X | | X | X | CPU load nice in % |
| | currentload_idle | X | X | X | CPU load idle in % | | | currentload_idle | X | | X | X | CPU load idle in % |
| | currentload_irq | X | X | X | CPU load system in % | | | currentload_irq | X | | X | X | CPU load system in % |
| | raw_currentload... | X | X | X | CPU load raw values (ticks) | | | raw_currentload... | X | | X | X | CPU load raw values (ticks) |
| | cpus[] | X | X | X | current loads per CPU in % + raw ticks | | | cpus[] | X | | X | X | current loads per CPU in % + raw ticks |
| si.fullLoad(cb) | : integer | X | X | X | CPU full load since bootup in % | | si.fullLoad(cb) | : integer | X | | X | X | CPU full load since bootup in % |
| si.processes(cb) | {...} | X | X | X | # running processes | | si.processes(cb) | {...} | X | X | X | X | # running processes |
| | all | X | X | X | # of all processes | | | all | X | X | X | X | # of all processes |
| | running | X | X | X | # of all processes running | | | running | X | X | X | X | # of all processes running |
| | blocked | X | X | X | # of all processes blocked | | | blocked | X | X | X | X | # of all processes blocked |
| | sleeping | X | X | X | # of all processes sleeping | | | sleeping | X | X | X | X | # of all processes sleeping |
| | unknown | | | X | # of all processes unknown status | | | unknown | | | | X | # of all processes unknown status |
| | list[] | X | X | X | list of all processes incl. details | | | list[] | X | X | X | X | list of all processes incl. details |
| | ...[0].pid | X | X | X | process PID | | | ...[0].pid | X | X | X | X | process PID |
| | ...[0].name | X | X | X | process name | | | ...[0].name | X | X | X | X | process name |
| | ...[0].pcpu | X | X | X | process % CPU usage | | | ...[0].pcpu | X | X | X | X | process % CPU usage |
| | ...[0].pcpuu | X | | X | process % CPU usage (user) | | | ...[0].pcpuu | X | X | | X | process % CPU usage (user) |
| | ...[0].pcpus | X | | X | process % CPU usage (system) | | | ...[0].pcpus | X | X | | X | process % CPU usage (system) |
| | ...[0].pmem | X | X | X | process memory % | | | ...[0].pmem | X | X | X | X | process memory % |
| | ...[0].priority | X | X | X | process priotity | | | ...[0].priority | X | X | X | X | process priotity |
| | ...[0].mem_vsz | X | X | X | process virtual memory size | | | ...[0].mem_vsz | X | X | X | X | process virtual memory size |
| | ...[0].mem_rss | X | X | X | process mem resident set size | | | ...[0].mem_rss | X | X | X | X | process mem resident set size |
| | ...[0].nice | X | X | | process nice value | | | ...[0].nice | X | X | X | | process nice value |
| | ...[0].started | X | X | X | process start time | | | ...[0].started | X | X | X | X | process start time |
| | ...[0].state | X | X | X | process state (e.g. sleeping) | | | ...[0].state | X | X | X | X | process state (e.g. sleeping) |
| | ...[0].tty | X | X | | tty from which process was started | | | ...[0].tty | X | X | X | | tty from which process was started |
| | ...[0].user | X | X | | user who started process | | | ...[0].user | X | X | X | | user who started process |
| | ...[0].command | X | X | X | process starting command | | | ...[0].command | X | X | X | X | process starting command |
| si.processLoad('apache2',cb) | {...} | X | X | | detailed information about given process | | si.processLoad('apache2',cb) | {...} | X | | X | | detailed information about given process |
| | proc | X | X | | process name | | | proc | X | | X | | process name |
| | pid | X | X | | PID | | | pid | X | | X | | PID |
| | cpu | X | X | | process % CPU | | | cpu | X | | X | | process % CPU |
| | mem | X | X | | process % MEM | | | mem | X | | X | | process % MEM |
| si.services('mysql, apache2', cb) | [{...}] | X | X | X | pass comma separated string of services | | si.services('mysql, apache2', cb) | [{...}] | X | X | X | X | pass comma separated string of services |
| | [0].name | X | X | X | name of service | | | [0].name | X | X | X | X | name of service |
| | [0].running | X | X | X | true / false | | | [0].running | X | X | X | X | true / false |
| | [0].pcpu | X | X | | process % CPU | | | [0].pcpu | X | X | X | | process % CPU |
| | [0].pmem | X | X | | process % MEM | | | [0].pmem | X | X | X | | process % MEM |
#### 8. Docker #### 8. Docker
| Function | Result object | Linux | OSX | Win | Comments | | Function | Result object | Linux | FreeBSD | OSX | Win | Comments |
| --------------- | ----- | ----- | ---- | ------- | -------- | | --------------- | ------------- | ----- | ------- | --- | --- | -------- |
| si.dockerContainers(all, cb) | [{...}] | X | X | X | returns array of active/all docker containers | | si.dockerContainers(all, cb) | [{...}] | X | X | X | X | returns array of active/all docker containers |
| | [0].id | X | X | X | ID of container | | | [0].id | X | X | X | X | ID of container |
| | [0].name | X | X | X | name of container | | | [0].name | X | X | X | X | name of container |
| | [0].image | X | X | X | name of image | | | [0].image | X | X | X | X | name of image |
| | [0].imageID | X | X | X | ID of image | | | [0].imageID | X | X | X | X | ID of image |
| | [0].command | X | X | X | command | | | [0].command | X | X | X | X | command |
| | [0].created | X | X | X | creation time | | | [0].created | X | X | X | X | creation time |
| | [0].state | X | X | X | created, running, exited | | | [0].state | X | X | X | X | created, running, exited |
| | [0].ports | X | X | X | array of ports | | | [0].ports | X | X | X | X | array of ports |
| | [0].mounts | X | X | X | array of mounts | | | [0].mounts | X | X | X | X | array of mounts |
| si.dockerContainerStats(id, cb) | {...} | X | X | X | statistics for a specific container | | si.dockerContainerStats(id, cb) | {...} | X | X | X | X | statistics for a specific container |
| | id | X | X | X | Container ID | | | id | X | X | X | X | Container ID |
| | mem_usage | X | X | X | memory usage in bytes | | | mem_usage | X | X | X | X | memory usage in bytes |
| | mem_limit | X | X | X | memory limit (max mem) in bytes | | | mem_limit | X | X | X | X | memory limit (max mem) in bytes |
| | mem_percent | X | X | X | memory usage in percent | | | mem_percent | X | X | X | X | memory usage in percent |
| | cpu_percent | X | X | X | cpu usage in percent | | | cpu_percent | X | X | X | X | cpu usage in percent |
| | pids | X | X | X | number of processes | | | pids | X | X | X | X | number of processes |
| | netIO.rx | X | X | X | received bytes via network | | | netIO.rx | X | X | X | X | received bytes via network |
| | netIO.wx | X | X | X | sent bytes via network | | | netIO.wx | X | X | X | X | sent bytes via network |
| | blockIO.r | X | X | X | bytes read from BlockIO | | | blockIO.r | X | X | X | X | bytes read from BlockIO |
| | blockIO.w | X | X | X | bytes written to BlockIO | | | blockIO.w | X | X | X | X | bytes written to BlockIO |
| | cpu_stats | X | X | X | detailed cpu stats | | | cpu_stats | X | X | X | X | detailed cpu stats |
| | percpu_stats | X | X | X | detailed per cpu stats | | | percpu_stats | X | X | X | X | detailed per cpu stats |
| | memory_stats | X | X | X | detailed memory stats | | | memory_stats | X | X | X | X | detailed memory stats |
| | networks | X | X | X | detailed network stats per interface | | | networks | X | X | X | X | detailed network stats per interface |
| si.dockerContainerProcesses(id, cb) | [{...}] | X | X | X | array of processes inside a container | | si.dockerContainerProcesses(id, cb) | [{...}] | X | X | X | X | array of processes inside a container |
| | [0].pid_host | X | X | X | process ID (host) | | | [0].pid_host | X | X | X | X | process ID (host) |
| | [0].ppid | X | X | X | parent process ID | | | [0].ppid | X | X | X | X | parent process ID |
| | [0].pgid | X | X | X | process group ID | | | [0].pgid | X | X | X | X | process group ID |
| | [0].user | X | X | X | effective user name | | | [0].user | X | X | X | X | effective user name |
| | [0].ruser | X | X | X | real user name | | | [0].ruser | X | X | X | X | real user name |
| | [0].group | X | X | X | effective group name | | | [0].group | X | X | X | X | effective group name |
| | [0].rgroup | X | X | X | real group name | | | [0].rgroup | X | X | X | X | real group name |
| | [0].stat | X | X | X | process state | | | [0].stat | X | X | X | X | process state |
| | [0].time | X | X | X | accumulated CPU time | | | [0].time | X | X | X | X | accumulated CPU time |
| | [0].elapsed | X | X | X | elapsed running time | | | [0].elapsed | X | X | X | X | elapsed running time |
| | [0].nice | X | X | X | nice value | | | [0].nice | X | X | X | X | nice value |
| | [0].rss | X | X | X | resident set size | | | [0].rss | X | X | X | X | resident set size |
| | [0].vsz | X | X | X | virtual size in Kbytes | | | [0].vsz | X | X | X | X | virtual size in Kbytes |
| | [0].command | X | X | X | command and arguments | | | [0].command | X | 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 | | si.dockerAll(cb) | {...} | X | X | X | X | list of all containers including their stats<br>and processes in one single array |
#### 9. "Get All at once" - functions #### 9. "Get All at once" - functions
| Function | Result object | Linux | OSX | Win | Comments | | Function | Result object | Linux | FreeBSD | OSX | Win | Comments |
| --------------- | ----- | ----- | ---- | ------- | -------- | | --------------- | ------------- | ----- | ------- | --- | --- | -------- |
| si.getStaticData(cb) | {...} | X | X | X | all static data at once | | si.getStaticData(cb) | {...} | X | X | X | X | all static data at once |
| si.getDynamicData(srv,iface,cb) | {...} | X | X | X | all dynamic data at once | | si.getDynamicData(srv,iface,cb) | {...} | X | X | X | X | all dynamic data at once |
| si.getAllData(srv,iface,cb) | {...} | X | X | X | all data at once | | si.getAllData(srv,iface,cb) | {...} | X | X | X | X | all data at once |
### cb: Asynchronous Function Calls (callback) ### cb: Asynchronous Function Calls (callback)
@ -566,10 +567,13 @@ OSX Temperature: credits here are going to:
## Copyright Information ## Copyright Information
Linux is a registered trademark of Linus Torvalds, OS X is a registered trademark of Apple Inc., Linux is a registered trademark of Linus Torvalds, Apple, Mac OS, OS X is a registered trademark of Apple Inc.,
Windows is a registered trademark of Microsoft Corporation. Node.js is a trademark of Joyent Inc., Windows is a registered trademark of Microsoft Corporation. Node.js is a trademark of Joyent Inc.,
Intel is a trademark of Intel Corporation, AMD is a trademark of Advanced Micro Devices Inc., Raspberry Pi is a trademark of the Raspberry Pi Foundation, Intel is a trademark of Intel Corporation, AMD is a trademark of Advanced Micro Devices Inc.,
Debian is a trademark of the Debian Project, Ubuntu is a trademark of Canonical Ltd., Docker is a trademark of Docker, Inc. Raspberry Pi is a trademark of the Raspberry Pi Foundation, Debian is a trademark of the Debian Project,
Ubuntu is a trademark of Canonical Ltd., FreeBSD is a registered trademark of The FreeBSD Foundation,
Docker is a trademark of Docker, Inc.
All other trademarks are the property of their respective owners. All other trademarks are the property of their respective owners.
## License [![MIT license][license-img]][license-url] ## License [![MIT license][license-img]][license-url]

View File

@ -12,16 +12,17 @@
// 6. Battery // 6. Battery
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
const os = require('os');
const exec = require('child_process').exec; const exec = require('child_process').exec;
const fs = require('fs'); const fs = require('fs');
const util = require('./util'); const util = require('./util');
let _platform = os.type(); let _platform = process.platform;
const _linux = (_platform === 'Linux'); const _linux = (_platform === 'linux');
const _darwin = (_platform === 'Darwin'); const _darwin = (_platform === 'darwin');
const _windows = (_platform === 'Windows_NT'); const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
module.exports = function (callback) { module.exports = function (callback) {
@ -79,30 +80,41 @@ module.exports = function (callback) {
resolve(result); resolve(result);
} }
} }
if (_freebsd || _openbsd) {
exec('sysctl hw.acpi.battery hw.acpi.acline', function (error, stdout) {
let lines = stdout.toString().split('\n');
const batteries = parseInt('0' + util.getValue(lines,'hw.acpi.battery.units'), 10);
const percent = parseInt('0' + util.getValue(lines,'hw.acpi.battery.life'), 10);
result.hasbattery = (batteries > 0);
result.cyclecount = -1;
result.ischarging = util.getValue(lines,'hw.acpi.acline') !== '1';
result.maxcapacity = -1;
result.currentcapacity = -1;
result.percent = batteries ? percent : -1;
if (callback) { callback(result); }
resolve(result);
});
}
if (_darwin) { if (_darwin) {
exec("ioreg -n AppleSmartBattery -r | grep '\"CycleCount\"';ioreg -n AppleSmartBattery -r | grep '\"IsCharging\"';ioreg -n AppleSmartBattery -r | grep '\"MaxCapacity\"';ioreg -n AppleSmartBattery -r | grep '\"CurrentCapacity\"';pmset -g batt | grep %", function (error, stdout) { exec('ioreg -n AppleSmartBattery -r | egrep "CycleCount|IsCharging|MaxCapacity|CurrentCapacity";pmset -g batt | grep %', function (error, stdout) {
if (!error) { let lines = stdout.toString().replace(/ +/g, '').replace(/"+/g, '').replace(/-/g, '').split('\n');
let lines = stdout.toString().replace(/ +/g, '').replace(/"+/g, '').split('\n'); result.cyclecount = parseInt('0' + util.getValue(lines,'cyclecount', '='), 10);
lines.forEach(function (line) { result.ischarging = util.getValue(lines,'ischarging', '=').toLowerCase === 'yes';
if (line.indexOf('=') !== -1) { result.maxcapacity = parseInt('0' + util.getValue(lines,'maxcapacity', '='), 10);
if (line.toLowerCase().indexOf('cyclecount') !== -1) result.cyclecount = parseFloat(line.split('=')[1].trim()); result.currentcapacity = parseInt('0' + util.getValue(lines,'currentcapacity', '='), 10);
if (line.toLowerCase().indexOf('ischarging') !== -1) result.ischarging = (line.split('=')[1].trim().toLowerCase() === 'yes'); let percent = -1;
if (line.toLowerCase().indexOf('maxcapacity') !== -1) result.maxcapacity = parseFloat(line.split('=')[1].trim()); const line = util.getValue(lines,'internalbattery', '=');
if (line.toLowerCase().indexOf('internalbattery') !== -1) { let parts = line.split(';');
let parts = line.split(';'); if (parts && parts[0]) {
if (parts && parts[0]) { let parts2 = parts[0].split('\t');
let parts2 = parts[0].split('\t'); if (parts2 && parts2[1]) {
if (parts2 && parts2[1]) { percent = parseFloat(parts2[1].trim().replace('%', ''));
result.percent = parseFloat(parts2[1].trim().replace('%', '')); }
}
}
}
}
});
} }
if (result.maxcapacity && result.currentcapacity) { if (result.maxcapacity && result.currentcapacity) {
result.hasbattery = true; result.hasbattery = true;
result.percent = 100.0 * result.currentcapacity / result.maxcapacity; result.percent = percent !== -1 ? percent : 100.0 * result.currentcapacity / result.maxcapacity;
} }
if (callback) { callback(result); } if (callback) { callback(result); }
resolve(result); resolve(result);

View File

@ -23,7 +23,7 @@ const _linux = (_platform === 'linux');
const _darwin = (_platform === 'darwin'); const _darwin = (_platform === 'darwin');
const _windows = (_platform === 'win32'); const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd'); const _freebsd = (_platform === 'freebsd');
const _sunos = (_platform === 'sunos'); const _openbsd = (_platform === 'openbsd');
let _cpu_speed = '0.00'; let _cpu_speed = '0.00';
let _current_cpu = { let _current_cpu = {
@ -162,6 +162,7 @@ function getCpu() {
model: '', model: '',
stepping: '', stepping: '',
revision: '', revision: '',
voltage: '',
speed: '0.00', speed: '0.00',
speedmin: '', speedmin: '',
speedmax: '', speedmax: '',
@ -193,42 +194,105 @@ function getCpu() {
}); });
} }
if (_linux) { if (_linux) {
let modelline = '';
let lines = [];
if (os.cpus()[0] && os.cpus()[0].model) modelline = os.cpus()[0].model;
exec('export LC_ALL=C; lscpu; unset LC_ALL', function (error, stdout) { exec('export LC_ALL=C; lscpu; unset LC_ALL', function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.toString().split('\n'); lines = stdout.toString().split('\n');
const modelline = util.getValue(lines, 'model name'); }
result.brand = modelline.split('@')[0].trim(); modelline = util.getValue(lines, 'model name') || modelline;
result.speed = modelline.split('@')[1] ? parseFloat(modelline.split('@')[1].trim()).toFixed(2) : '0.00'; result.brand = modelline.split('@')[0].trim();
if (result.speed === '0.00' && result.brand.indexOf('AMD') > -1) { result.speed = modelline.split('@')[1] ? parseFloat(modelline.split('@')[1].trim()).toFixed(2) : '0.00';
result.speed = getAMDSpeed(result.brand); if (result.speed === '0.00' && result.brand.indexOf('AMD') > -1) {
} result.speed = getAMDSpeed(result.brand);
if (result.speed === '0.00') { }
let current = getCpuCurrentSpeedSync(); if (result.speed === '0.00') {
if (current !== '0.00') result.speed = current.avg.toFixed(2); let current = getCpuCurrentSpeedSync();
} if (current !== '0.00') result.speed = current.avg.toFixed(2);
_cpu_speed = result.speed; }
result.speedmin = Math.round(parseFloat(util.getValue(lines, 'cpu min mhz').replace(/,/g, '.')) / 10.0) / 100; _cpu_speed = result.speed;
result.speedmin = result.speedmin ? parseFloat(result.speedmin).toFixed(2) : ''; result.speedmin = Math.round(parseFloat(util.getValue(lines, 'cpu min mhz').replace(/,/g, '.')) / 10.0) / 100;
result.speedmax = Math.round(parseFloat(util.getValue(lines, 'cpu max mhz').replace(/,/g, '.')) / 10.0) / 100; result.speedmin = result.speedmin ? parseFloat(result.speedmin).toFixed(2) : '';
result.speedmax = result.speedmax ? parseFloat(result.speedmax).toFixed(2) : ''; result.speedmax = Math.round(parseFloat(util.getValue(lines, 'cpu max mhz').replace(/,/g, '.')) / 10.0) / 100;
result.speedmax = result.speedmax ? parseFloat(result.speedmax).toFixed(2) : '';
result = cpuBrandManufacturer(result); result = cpuBrandManufacturer(result);
result.vendor = util.getValue(lines, 'vendor id'); result.vendor = util.getValue(lines, 'vendor id');
// if (!result.vendor) { result.vendor = util.getValue(lines, 'anbieterkennung'); } // if (!result.vendor) { result.vendor = util.getValue(lines, 'anbieterkennung'); }
result.family = util.getValue(lines, 'cpu family'); result.family = util.getValue(lines, 'cpu family');
// if (!result.family) { result.family = util.getValue(lines, 'prozessorfamilie'); } // if (!result.family) { result.family = util.getValue(lines, 'prozessorfamilie'); }
result.model = util.getValue(lines, 'model:'); result.model = util.getValue(lines, 'model:');
// if (!result.model) { result.model = util.getValue(lines, 'modell:'); } // if (!result.model) { result.model = util.getValue(lines, 'modell:'); }
result.stepping = util.getValue(lines, 'stepping'); result.stepping = util.getValue(lines, 'stepping');
result.revision = util.getValue(lines, 'cpu revision'); result.revision = util.getValue(lines, 'cpu revision');
result.cache.l1d = util.getValue(lines, 'l1d cache'); result.cache.l1d = util.getValue(lines, 'l1d cache');
if (result.cache.l1d) { result.cache.l1d = parseInt(result.cache.l1d) * (result.cache.l1d.indexOf('K') !== -1 ? 1024 : 1); } if (result.cache.l1d) { result.cache.l1d = parseInt(result.cache.l1d) * (result.cache.l1d.indexOf('K') !== -1 ? 1024 : 1); }
result.cache.l1i = util.getValue(lines, 'l1i cache'); result.cache.l1i = util.getValue(lines, 'l1i cache');
if (result.cache.l1i) { result.cache.l1i = parseInt(result.cache.l1i) * (result.cache.l1i.indexOf('K') !== -1 ? 1024 : 1); } if (result.cache.l1i) { result.cache.l1i = parseInt(result.cache.l1i) * (result.cache.l1i.indexOf('K') !== -1 ? 1024 : 1); }
result.cache.l2 = util.getValue(lines, 'l2 cache'); result.cache.l2 = util.getValue(lines, 'l2 cache');
if (result.cache.l2) { result.cache.l2 = parseInt(result.cache.l2) * (result.cache.l2.indexOf('K') !== -1 ? 1024 : 1); } if (result.cache.l2) { result.cache.l2 = parseInt(result.cache.l2) * (result.cache.l2.indexOf('K') !== -1 ? 1024 : 1); }
result.cache.l3 = util.getValue(lines, 'l3 cache'); result.cache.l3 = util.getValue(lines, 'l3 cache');
if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3) * (result.cache.l3.indexOf('K') !== -1 ? 1024 : 1); } if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3) * (result.cache.l3.indexOf('K') !== -1 ? 1024 : 1); }
resolve(result);
});
}
if (_freebsd || _openbsd) {
let modelline = '';
let lines = [];
if (os.cpus()[0] && os.cpus()[0].model) modelline = os.cpus()[0].model;
exec('export LC_ALL=C; dmidecode -t 4; dmidecode -t 7 ; unset LC_ALL', function (error, stdout) {
let cache = [];
if (!error) {
const data = stdout.toString().split('# dmidecode');
const processor = data.length > 0 ? data[1] : '';
cache = data.length > 1 ? data[2].split('Cache Information') : [];
lines = processor.split('\n');
}
result.brand = modelline.split('@')[0].trim();
result.speed = modelline.split('@')[1] ? parseFloat(modelline.split('@')[1].trim()).toFixed(2) : '0.00';
if (result.speed === '0.00' && result.brand.indexOf('AMD') > -1) {
result.speed = getAMDSpeed(result.brand);
}
if (result.speed === '0.00') {
let current = getCpuCurrentSpeedSync();
if (current !== '0.00') result.speed = current.avg.toFixed(2);
}
_cpu_speed = result.speed;
result.speedmin = '';
result.speedmax = Math.round(parseFloat(util.getValue(lines, 'max speed').replace(/Mhz/g, '')) / 10.0) / 100;
result.speedmax = result.speedmax ? parseFloat(result.speedmax).toFixed(2) : '';
result = cpuBrandManufacturer(result);
result.vendor = util.getValue(lines, 'manufacturer');
let sig = util.getValue(lines, 'signature');
sig = sig.split(',');
for (var i = 0; i < sig.length; i++) {
sig[i] = sig[i].trim();
}
result.family = util.getValue(sig, 'Family', ' ', true);
result.model = util.getValue(sig, 'Model', ' ', true);
result.stepping = util.getValue(sig, 'Stepping', ' ', true);
result.revision = '';
const voltage = parseFloat(util.getValue(lines, 'voltage'));
result.voltage = isNaN(voltage) ? '' : voltage.toFixed(2);
for (let i = 0; i < cache.length; i++) {
lines = cache[i].split('\n');
let cacheType = util.getValue(lines,'Socket Designation').toLowerCase().replace(' ', '-').split('-');
cacheType = cacheType.length ? cacheType[0] : '';
const sizeParts = util.getValue(lines,'Installed Size').split(' ');
let size = parseInt(sizeParts[0], 10);
const unit = sizeParts.length > 1 ? sizeParts[1] : 'kb';
size = size * (unit === 'kb' ? 1024 : (unit === 'mb' ? 1024 * 1024 : (unit === 'gb' ? 1024 * 1024 * 1024 : 1)));
if (cacheType) {
if (cacheType === 'l1') {
result.cache[cacheType + 'd'] = size / 2;
result.cache[cacheType + 'i'] = size / 2;
} else {
result.cache[cacheType] = size;
}
}
} }
resolve(result); resolve(result);
}); });
@ -433,6 +497,28 @@ function cpuTemperature(callback) {
} }
}); });
} }
if (_freebsd || _openbsd) {
exec('sysctl dev.cpu | grep temp', function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
let sum = 0;
lines.forEach(function (line) {
const parts = line.split(':');
if (parts.length > 0) {
const temp = parseFloat(parts[1].replace(',', '.'), 10);
if (temp > result.max) result.max = temp;
sum = sum + temp;
result.cores.push(temp);
}
});
if (result.cores.length) {
result.main = Math.round(sum / result.cores.length * 100) / 100;
}
}
if (callback) { callback(result); }
resolve(result);
});
}
if (_darwin) { if (_darwin) {
let osxTemp = null; let osxTemp = null;
try { try {
@ -519,6 +605,24 @@ function cpuFlags(callback) {
resolve(result); resolve(result);
}); });
} }
if (_freebsd || _openbsd) {
exec('export LC_ALL=C; dmidecode -t 4; unset LC_ALL', function (error, stdout) {
let flags = [];
if (!error) {
let parts = stdout.toString().split('\tFlags:');
const lines = parts.length > 1 ? parts[1].split('\tVersion:')[0].split['\n'] : [];
lines.forEach(function (line) {
let flag = (line.indexOf('(') ? line .split('(')[0].toLowerCase() : '').trim().replace(/\t/g, '');
if (flag) {
flags.push(flag);
}
});
}
result = flags.join(' ').trim();
if (callback) { callback(result); }
resolve(result);
});
}
if (_darwin) { if (_darwin) {
exec('sysctl machdep.cpu.features', function (error, stdout) { exec('sysctl machdep.cpu.features', function (error, stdout) {
if (!error) { if (!error) {
@ -545,7 +649,12 @@ function cpuCache(callback) {
return new Promise((resolve) => { return new Promise((resolve) => {
process.nextTick(() => { process.nextTick(() => {
let result = {}; let result = {
l1d: -1,
l1i: -1,
l2: -1,
l3: -1,
};
if (_linux) { if (_linux) {
exec('lscpu', function (error, stdout) { exec('lscpu', function (error, stdout) {
if (!error) { if (!error) {
@ -570,6 +679,35 @@ function cpuCache(callback) {
resolve(result); resolve(result);
}); });
} }
if (_freebsd || _openbsd) {
exec('export LC_ALL=C; dmidecode -t 7 ; unset LC_ALL', function (error, stdout) {
let cache = [];
if (!error) {
const data = stdout.toString();
cache = data.split('Cache Information');
cache.shift();
}
for (let i = 0; i < cache.length; i++) {
const lines = cache[i].split('\n');
let cacheType = util.getValue(lines,'Socket Designation').toLowerCase().replace(' ', '-').split('-');
cacheType = cacheType.length ? cacheType[0] : '';
const sizeParts = util.getValue(lines,'Installed Size').split(' ');
let size = parseInt(sizeParts[0], 10);
const unit = sizeParts.length > 1 ? sizeParts[1] : 'kb';
size = size * (unit === 'kb' ? 1024 : (unit === 'mb' ? 1024 * 1024 : (unit === 'gb' ? 1024 * 1024 * 1024 : 1)));
if (cacheType) {
if (cacheType === 'l1') {
result.cache[cacheType + 'd'] = size / 2;
result.cache[cacheType + 'i'] = size / 2;
} else {
result.cache[cacheType] = size;
}
}
}
if (callback) { callback(result); }
resolve(result);
});
}
if (_darwin) { if (_darwin) {
exec('sysctl hw.l1icachesize hw.l1dcachesize hw.l2cachesize hw.l3cachesize', function (error, stdout) { exec('sysctl hw.l1icachesize hw.l1dcachesize hw.l2cachesize hw.l3cachesize', function (error, stdout) {
if (!error) { if (!error) {

View File

@ -88,6 +88,7 @@ function dockerContainers(all, callback) {
}); });
} }
} catch (err) { } catch (err) {
util.noop();
} }
// } // }
@ -244,6 +245,7 @@ function dockerContainerStats(containerID, callback) {
result.networks = (stats.networks ? stats.networks : {}); result.networks = (stats.networks ? stats.networks : {});
} }
} catch (err) { } catch (err) {
util.noop();
} }
// } // }
if (callback) { callback(result); } if (callback) { callback(result); }
@ -319,6 +321,7 @@ function dockerContainerProcesses(containerID, callback) {
}); });
} }
} catch (err) { } catch (err) {
util.noop();
} }
if (callback) { callback(result); } if (callback) { callback(result); }
resolve(result); resolve(result);

View File

@ -12,16 +12,18 @@
// 8. File System // 8. File System
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
const os = require('os');
const exec = require('child_process').exec; const exec = require('child_process').exec;
const execSync = require('child_process').execSync; const execSync = require('child_process').execSync;
const util = require('./util'); const util = require('./util');
let _platform = os.type(); let _platform = process.platform;
const _linux = (_platform === 'linux');
const _darwin = (_platform === 'darwin');
const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
const _linux = (_platform === 'Linux');
const _darwin = (_platform === 'Darwin');
const _windows = (_platform === 'Windows_NT');
const NOT_SUPPORTED = 'not supported'; const NOT_SUPPORTED = 'not supported';
let _fs_speed = {}; let _fs_speed = {};
@ -35,8 +37,11 @@ function fsSize(callback) {
return new Promise((resolve) => { return new Promise((resolve) => {
process.nextTick(() => { process.nextTick(() => {
let data = []; let data = [];
if (_linux || _darwin) { if (_linux || _freebsd || _openbsd || _darwin) {
let cmd = (_darwin ? 'df -lkP | grep ^/' : 'df -lkPT | grep ^/'); let cmd = '';
if (_darwin) cmd = 'df -lkP | grep ^/';
if (_linux) cmd = 'df -lkPT | grep ^/';
if (_freebsd || _openbsd) cmd = 'df -lkPT';
exec(cmd, function (error, stdout) { exec(cmd, function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
@ -44,14 +49,16 @@ function fsSize(callback) {
lines.forEach(function (line) { lines.forEach(function (line) {
if (line !== '') { if (line !== '') {
line = line.replace(/ +/g, ' ').split(' '); line = line.replace(/ +/g, ' ').split(' ');
data.push({ if (line && (line[0].startsWith('/')) || (line[6] && line[6] === '/')) {
'fs': line[0], data.push({
'type': (_linux ? line[1] : 'HFS'), 'fs': line[0],
'size': parseInt((_linux ? line[2] : line[1])) * 1024, 'type': ((_linux || _freebsd || _openbsd) ? line[1] : 'HFS'),
'used': parseInt((_linux ? line[3] : line[2])) * 1024, 'size': parseInt(((_linux || _freebsd || _openbsd) ? line[2] : line[1])) * 1024,
'use': parseFloat((100.0 * (_linux ? line[3] : line[2]) / (_linux ? line[2] : line[1])).toFixed(2)), 'used': parseInt(((_linux || _freebsd || _openbsd) ? line[3] : line[2])) * 1024,
'mount': line[line.length - 1] 'use': parseFloat((100.0 * ((_linux || _freebsd || _openbsd) ? line[3] : line[2]) / ((_linux || _freebsd || _openbsd) ? line[2] : line[1])).toFixed(2)),
}); 'mount': line[line.length - 1]
});
}
} }
}); });
} }
@ -360,7 +367,7 @@ function fsStats(callback) {
}); });
let output = fs_filter.join('|'); let output = fs_filter.join('|');
exec("cat /proc/diskstats | egrep '" + output + "'", function (error, stdout) { exec('cat /proc/diskstats | egrep "' + output + '"', function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
lines.forEach(function (line) { lines.forEach(function (line) {
@ -492,7 +499,7 @@ function disksIO(callback) {
let wIO = 0; let wIO = 0;
if ((_disk_io && !_disk_io.ms) || (_disk_io && _disk_io.ms && Date.now() - _disk_io.ms >= 500)) { if ((_disk_io && !_disk_io.ms) || (_disk_io && _disk_io.ms && Date.now() - _disk_io.ms >= 500)) {
if (_linux) { if (_linux || _freebsd || _openbsd) {
// prints Block layer statistics for all mounted volumes // prints Block layer statistics for all mounted volumes
// var cmd = "for mount in `lsblk | grep / | sed -r 's/│ └─//' | cut -d ' ' -f 1`; do cat /sys/block/$mount/stat | sed -r 's/ +/;/g' | sed -r 's/^;//'; done"; // var cmd = "for mount in `lsblk | grep / | sed -r 's/│ └─//' | cut -d ' ' -f 1`; do cat /sys/block/$mount/stat | sed -r 's/ +/;/g' | sed -r 's/^;//'; done";
// var cmd = "for mount in `lsblk | grep / | sed 's/[│└─├]//g' | awk '{$1=$1};1' | cut -d ' ' -f 1 | sort -u`; do cat /sys/block/$mount/stat | sed -r 's/ +/;/g' | sed -r 's/^;//'; done"; // var cmd = "for mount in `lsblk | grep / | sed 's/[│└─├]//g' | awk '{$1=$1};1' | cut -d ' ' -f 1 | sort -u`; do cat /sys/block/$mount/stat | sed -r 's/ +/;/g' | sed -r 's/^;//'; done";
@ -583,6 +590,7 @@ function diskLayout(callback) {
try { try {
mediumType = execSync('cat /sys/block/' + logical + '/queue/rotational').toString().split('\n')[0]; mediumType = execSync('cat /sys/block/' + logical + '/queue/rotational').toString().split('\n')[0];
} catch (e) { } catch (e) {
util.noop();
} }
const sizeString = util.getValue(lines, 'size', ':', true).trim(); const sizeString = util.getValue(lines, 'size', ':', true).trim();
@ -613,6 +621,10 @@ function diskLayout(callback) {
resolve(result); resolve(result);
}); });
} }
if (_freebsd || _openbsd) {
if (callback) { callback(result); }
resolve(result);
}
if (_darwin) { if (_darwin) {
exec('system_profiler SPSerialATADataType SPNVMeDataType', function (error, stdout) { exec('system_profiler SPSerialATADataType SPNVMeDataType', function (error, stdout) {

View File

@ -12,15 +12,17 @@
// 7. Graphics (controller, display) // 7. Graphics (controller, display)
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
const os = require('os');
const exec = require('child_process').exec; const exec = require('child_process').exec;
const util = require('./util'); const util = require('./util');
let _platform = os.type(); let _platform = process.platform;
const _linux = (_platform === 'linux');
const _darwin = (_platform === 'darwin');
const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
const _linux = (_platform === 'Linux');
const _darwin = (_platform === 'Darwin');
const _windows = (_platform === 'Windows_NT');
let _resolutionx = 0; let _resolutionx = 0;
let _resolutiony = 0; let _resolutiony = 0;
let _pixeldepth = 0; let _pixeldepth = 0;
@ -321,6 +323,10 @@ function graphics(callback) {
}); });
}); });
} }
if (_freebsd || _openbsd) {
if (callback) { callback(result); }
resolve(result);
}
if (_windows) { if (_windows) {
// https://blogs.technet.microsoft.com/heyscriptingguy/2013/10/03/use-powershell-to-discover-multi-monitor-information/ // https://blogs.technet.microsoft.com/heyscriptingguy/2013/10/03/use-powershell-to-discover-multi-monitor-information/
exec(util.getWmic() + ' path win32_VideoController get AdapterCompatibility, AdapterDACType, name, PNPDeviceID, CurrentVerticalResolution, CurrentHorizontalResolution, CurrentNumberOfColors, AdapterRAM, CurrentBitsPerPixel, CurrentRefreshRate, MinRefreshRate, MaxRefreshRate, VideoMemoryType /value', function (error, stdout) { exec(util.getWmic() + ' path win32_VideoController get AdapterCompatibility, AdapterDACType, name, PNPDeviceID, CurrentVerticalResolution, CurrentHorizontalResolution, CurrentNumberOfColors, AdapterRAM, CurrentBitsPerPixel, CurrentRefreshRate, MinRefreshRate, MaxRefreshRate, VideoMemoryType /value', function (error, stdout) {

View File

@ -83,8 +83,6 @@
// Dependencies // Dependencies
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
const os = require('os');
const lib_version = require('../package.json').version; const lib_version = require('../package.json').version;
const util = require('./util'); const util = require('./util');
const system = require('./system'); const system = require('./system');
@ -100,8 +98,10 @@ const users = require('./users');
const internet = require('./internet'); const internet = require('./internet');
const docker = require('./docker'); const docker = require('./docker');
let _platform = os.type(); let _platform = process.platform;
let _windows = (_platform === 'Windows_NT'); const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
// 1. General // 1. General
@ -185,7 +185,9 @@ function getDynamicData(srv, iface, callback) {
// use closure to track ƒ completion // use closure to track ƒ completion
let functionProcessed = (function () { let functionProcessed = (function () {
let totalFunctions = (_windows ? 10 : 14); let totalFunctions = 14;
if (_windows) totalFunctions = 10;
if (_freebsd || _openbsd) totalFunctions = 10;
return function () { return function () {
if (--totalFunctions === 0) { if (--totalFunctions === 0) {
@ -246,15 +248,19 @@ function getDynamicData(srv, iface, callback) {
functionProcessed(); functionProcessed();
}); });
network.networkStats(iface).then(res => { if (!_openbsd && !_freebsd) {
data.networkStats = res; network.networkStats(iface).then(res => {
functionProcessed(); data.networkStats = res;
}); functionProcessed();
});
}
network.networkConnections().then(res => { if (!_openbsd && !_freebsd) {
data.networkConnections = res; network.networkConnections().then(res => {
functionProcessed(); data.networkConnections = res;
}); functionProcessed();
});
}
memory.mem().then(res => { memory.mem().then(res => {
data.mem = res; data.mem = res;
@ -278,14 +284,14 @@ function getDynamicData(srv, iface, callback) {
functionProcessed(); functionProcessed();
}); });
if (!_windows) { if (!_windows && !_openbsd && !_freebsd) {
filesystem.fsStats().then(res => { filesystem.fsStats().then(res => {
data.fsStats = res; data.fsStats = res;
functionProcessed(); functionProcessed();
}); });
} }
if (!_windows) { if (!_windows && !_openbsd && !_freebsd) {
filesystem.disksIO().then(res => { filesystem.disksIO().then(res => {
data.disksIO = res; data.disksIO = res;
functionProcessed(); functionProcessed();
@ -313,6 +319,17 @@ function getAllData(srv, iface, callback) {
process.nextTick(() => { process.nextTick(() => {
let data = {}; let data = {};
if (iface && util.isFunction(iface) && !callback) {
callback = iface;
iface = '';
}
if (srv && util.isFunction(srv) && !iface && !callback) {
callback = srv;
srv = '';
iface = '';
}
getStaticData().then(res => { getStaticData().then(res => {
data = res; data = res;
getDynamicData(srv, iface).then(res => { getDynamicData(srv, iface).then(res => {

View File

@ -12,15 +12,16 @@
// 12. Internet // 12. Internet
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
const os = require('os');
const exec = require('child_process').exec; const exec = require('child_process').exec;
const util = require('./util'); const util = require('./util');
let _platform = os.type(); let _platform = process.platform;
const _linux = (_platform === 'Linux'); const _linux = (_platform === 'linux');
const _darwin = (_platform === 'Darwin'); const _darwin = (_platform === 'darwin');
const _windows = (_platform === 'Windows_NT'); const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
// -------------------------- // --------------------------
// check if external site is available // check if external site is available
@ -39,7 +40,7 @@ function inetChecksite(url, callback) {
if (url) { if (url) {
url = url.toLowerCase(); url = url.toLowerCase();
let t = Date.now(); let t = Date.now();
if (_linux || _darwin) { if (_linux || _freebsd || _openbsd || _darwin) {
let args = ' -I --connect-timeout 5 -m 5 ' + url + ' 2>/dev/null | head -n 1 | cut -d " " -f2'; let args = ' -I --connect-timeout 5 -m 5 ' + url + ' 2>/dev/null | head -n 1 | cut -d " " -f2';
let cmd = 'curl'; let cmd = 'curl';
exec(cmd + args, function (error, stdout) { exec(cmd + args, function (error, stdout) {
@ -73,7 +74,7 @@ function inetChecksite(url, callback) {
resolve(result); resolve(result);
}); });
} }
}).on('error', err => { }).on('error', () => {
if (callback) { callback(result); } if (callback) { callback(result); }
resolve(result); resolve(result);
}); });
@ -108,10 +109,13 @@ function inetLatency(host, callback) {
return new Promise((resolve) => { return new Promise((resolve) => {
process.nextTick(() => { process.nextTick(() => {
let cmd; let cmd;
if (_linux || _darwin) { if (_linux || _freebsd || _openbsd || _darwin) {
if (_linux) { if (_linux) {
cmd = 'ping -c 2 -w 3 ' + host + ' | grep rtt'; cmd = 'ping -c 2 -w 3 ' + host + ' | grep rtt';
} }
if (_freebsd || _openbsd) {
cmd = 'ping -c 2 -t 3 ' + host + ' | grep round-trip';
}
if (_darwin) { if (_darwin) {
cmd = 'ping -c 2 -t 3 ' + host + ' | grep avg'; cmd = 'ping -c 2 -t 3 ' + host + ' | grep avg';
} }

View File

@ -16,11 +16,14 @@ const os = require('os');
const exec = require('child_process').exec; const exec = require('child_process').exec;
const util = require('./util'); const util = require('./util');
let _platform = os.type(); let _platform = process.platform;
const _linux = (_platform === 'linux');
const _darwin = (_platform === 'darwin');
const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
const _linux = (_platform === 'Linux');
const _darwin = (_platform === 'Darwin');
const _windows = (_platform === 'Windows_NT');
const OSX_RAM_manufacturers = { const OSX_RAM_manufacturers = {
'0x014F': 'Transcend Information', '0x014F': 'Transcend Information',
@ -134,8 +137,32 @@ function mem(callback) {
resolve(result); resolve(result);
}); });
} }
if (_freebsd || _openbsd) {
exec('/sbin/sysctl -a | grep -E "hw.realmem|hw.physmem|vm.stats.vm.v_page_count|vm.stats.vm.v_wire_count|vm.stats.vm.v_active_count|vm.stats.vm.v_inactive_count|vm.stats.vm.v_cache_count|vm.stats.vm.v_free_count|vm.stats.vm.v_page_size"', function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
const pagesize = parseInt(util.getValue(lines, 'vm.stats.vm.v_page_size'), 10);
const inactive = parseInt(util.getValue(lines, 'vm.stats.vm.v_inactive_count'), 10) * pagesize;
const cache = parseInt(util.getValue(lines, 'vm.stats.vm.v_cache_count'), 10) * pagesize;
result.total = parseInt(util.getValue(lines, 'hw.realmem'), 10);
if (isNaN(result.total)) result.total = parseInt(util.getValue(lines, 'hw.physmem'), 10);
result.free = parseInt(util.getValue(lines, 'vm.stats.vm.v_free_count'), 10) * pagesize;
result.buffcache = inactive + cache;
result.available = result.buffcache + result.free;
result.active = result.total - result.free - result.buffcache;
result.swaptotal = 0;
result.swapfree = 0;
result.swapused = 0;
}
if (callback) { callback(result); }
resolve(result);
});
}
if (_darwin) { if (_darwin) {
exec("vm_stat | grep 'Pages active'", function (error, stdout) { exec('vm_stat | grep "Pages active"', function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
@ -203,34 +230,34 @@ function memLayout(callback) {
let result = []; let result = [];
if (_linux) { if (_linux || _freebsd || _openbsd) {
exec("dmidecode -t memory | grep -iE 'Size:|Type|Speed|Manufacturer|Form Factor|Locator|Memory Device|Serial Number|Voltage|Part Number'", function (error, stdout) { exec('dmidecode -t memory | grep -iE "Size:|Type|Speed|Manufacturer|Form Factor|Locator|Memory Device|Serial Number|Voltage|Part Number"', function (error, stdout) {
if (!error) { if (!error) {
let devices = stdout.toString().split('Memory Device'); let devices = stdout.toString().split('Memory Device');
devices.shift(); devices.shift();
devices.forEach(function (device) { devices.forEach(function (device) {
let lines = device.split('\n'); let lines = device.split('\n');
if (parseInt(util.getValue(lines, ' Size'), 10) > 0) { if (parseInt(util.getValue(lines, 'Size'), 10) > 0) {
result.push({ result.push({
size: parseInt(util.getValue(lines, ' Size'), 10)*1024*1024, size: parseInt(util.getValue(lines, 'Size'), 10)*1024*1024,
bank: util.getValue(lines, ' Bank Locator'), bank: util.getValue(lines, 'Bank Locator'),
type: util.getValue(lines, ' Type:'), type: util.getValue(lines, 'Type:'),
clockSpeed: (util.getValue(lines, ' Configured Clock Speed:') ? parseInt(util.getValue(lines, ' Configured Clock Speed:'), 10) : parseInt(util.getValue(lines, ' Speed:'), 10)), clockSpeed: (util.getValue(lines, 'Configured Clock Speed:') ? parseInt(util.getValue(lines, 'Configured Clock Speed:'), 10) : (util.getValue(lines, 'Speed:') ? parseInt(util.getValue(lines, 'Speed:'), 10) : -1)),
formFactor: util.getValue(lines, ' Form Factor:'), formFactor: util.getValue(lines, 'Form Factor:'),
manufacturer: util.getValue(lines, ' Manufacturer:'), manufacturer: util.getValue(lines, 'Manufacturer:'),
partNum: util.getValue(lines, ' Part Number:'), partNum: util.getValue(lines, 'Part Number:'),
serialNum: util.getValue(lines, ' Serial Number:'), serialNum: util.getValue(lines, 'Serial Number:'),
voltageConfigured: parseFloat(util.getValue(lines, ' Configured Voltage:') || -1), voltageConfigured: parseFloat(util.getValue(lines, 'Configured Voltage:') || -1),
voltageMin: parseFloat(util.getValue(lines, ' Minimum Voltage:') || -1), voltageMin: parseFloat(util.getValue(lines, 'Minimum Voltage:') || -1),
voltageMax: parseFloat(util.getValue(lines, ' Maximum Voltage:') || -1), voltageMax: parseFloat(util.getValue(lines, 'Maximum Voltage:') || -1),
}); });
} else { } else {
result.push({ result.push({
size: 0, size: 0,
bank: util.getValue(lines, ' Bank Locator'), bank: util.getValue(lines, 'Bank Locator'),
type: 'Empty', type: 'Empty',
clockSpeed: 0, clockSpeed: 0,
formFactor: util.getValue(lines, ' Form Factor:'), formFactor: util.getValue(lines, 'Form Factor:'),
partNum: '', partNum: '',
serialNum: '', serialNum: '',
voltageConfigured: -1, voltageConfigured: -1,

View File

@ -18,11 +18,13 @@ const execSync = require('child_process').execSync;
const fs = require('fs'); const fs = require('fs');
const util = require('./util'); const util = require('./util');
let _platform = os.type(); let _platform = process.platform;
const _linux = (_platform === 'Linux'); const _linux = (_platform === 'linux');
const _darwin = (_platform === 'Darwin'); const _darwin = (_platform === 'darwin');
const _windows = (_platform === 'Windows_NT'); const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
let _network = {}; let _network = {};
let _default_iface; let _default_iface;
@ -33,10 +35,16 @@ function getDefaultNetworkInterface() {
if (!_default_iface) { if (!_default_iface) {
let ifacename = ''; let ifacename = '';
let scopeid = 9999; let scopeid = 9999;
if (_linux || _darwin) { if (_linux || _darwin || _freebsd || _openbsd) {
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}'"); let cmd = '';
if (_linux) cmd = 'route 2>/dev/null | grep default | awk "{print $8}"';
if (_darwin) cmd = 'route get 0.0.0.0 2>/dev/null | grep interface: | awk "{print $2}"';
if (_freebsd || _openbsd) cmd = 'route get 0.0.0.0 | grep interface:';
let result = execSync(cmd); let result = execSync(cmd);
ifacename = result.toString().split('\n')[0]; ifacename = result.toString().split('\n')[0];
if (ifacename.indexOf(':') > -1) {
ifacename = ifacename.split(':')[1].trim();
}
} }
if (!ifacename) { // fallback - "first" external interface (sorted by scopeid) if (!ifacename) { // fallback - "first" external interface (sorted by scopeid)
@ -65,7 +73,7 @@ function getMacAddresses() {
let iface = ''; let iface = '';
let mac = ''; let mac = '';
let result = {}; let result = {};
if (_linux) { if (_linux || _freebsd || _openbsd) {
const cmd = 'export LC_ALL=C; /sbin/ifconfig; unset LC_ALL'; const cmd = 'export LC_ALL=C; /sbin/ifconfig; unset LC_ALL';
let res = execSync(cmd); let res = execSync(cmd);
const lines = res.toString().split('\n'); const lines = res.toString().split('\n');
@ -265,7 +273,7 @@ function networkStats(iface, callback) {
let cmd, lines, stats; let cmd, lines, stats;
if (!_network[iface] || (_network[iface] && !_network[iface].ms) || (_network[iface] && _network[iface].ms && Date.now() - _network[iface].ms >= 500)) { if (!_network[iface] || (_network[iface] && !_network[iface].ms) || (_network[iface] && _network[iface].ms && Date.now() - _network[iface].ms >= 500)) {
if (_linux) { if (_linux || _freebsd || _openbsd) {
if (fs.existsSync('/sys/class/net/' + iface)) { if (fs.existsSync('/sys/class/net/' + iface)) {
cmd = cmd =
'cat /sys/class/net/' + iface + '/operstate; ' + 'cat /sys/class/net/' + iface + '/operstate; ' +
@ -290,7 +298,7 @@ function networkStats(iface, callback) {
} }
} }
if (_darwin) { if (_darwin) {
cmd = "ifconfig " + iface + " | grep 'status'"; cmd = 'ifconfig ' + iface + ' | grep "status"';
exec(cmd, function (error, stdout) { exec(cmd, function (error, stdout) {
result.operstate = (stdout.toString().split(':')[1] || '').trim(); result.operstate = (stdout.toString().split(':')[1] || '').trim();
result.operstate = (result.operstate || '').toLowerCase(); result.operstate = (result.operstate || '').toLowerCase();
@ -396,7 +404,7 @@ function networkConnections(callback) {
process.nextTick(() => { process.nextTick(() => {
let result = []; let result = [];
if (_linux) { if (_linux) {
let cmd = "netstat -tuna | grep 'ESTABLISHED\\|SYN_SENT\\|SYN_RECV\\|FIN_WAIT1\\|FIN_WAIT2\\|TIME_WAIT\\|CLOSE\\|CLOSE_WAIT\\|LAST_ACK\\|LISTEN\\|CLOSING\\|UNKNOWN\\|VERBUNDEN'"; let cmd = 'netstat -tuna | grep "ESTABLISHED\\|SYN_SENT\\|SYN_RECV\\|FIN_WAIT1\\|FIN_WAIT2\\|TIME_WAIT\\|CLOSE\\|CLOSE_WAIT\\|LAST_ACK\\|LISTEN\\|CLOSING\\|UNKNOWN\\|VERBUNDEN"';
exec(cmd, function (error, stdout) { exec(cmd, function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
@ -438,7 +446,7 @@ function networkConnections(callback) {
} }
resolve(result); resolve(result);
} else { } else {
cmd = "ss -tuna | grep 'ESTAB\\|SYN-SENT\\|SYN-RECV\\|FIN-WAIT1\\|FIN-WAIT2\\|TIME-WAIT\\|CLOSE\\|CLOSE-WAIT\\|LAST-ACK\\|LISTEN\\|CLOSING'"; cmd = 'ss -tuna | grep "ESTAB\\|SYN-SENT\\|SYN-RECV\\|FIN-WAIT1\\|FIN-WAIT2\\|TIME-WAIT\\|CLOSE\\|CLOSE-WAIT\\|LAST-ACK\\|LISTEN\\|CLOSING"';
exec(cmd, function (error, stdout) { exec(cmd, function (error, stdout) {
if (!error) { if (!error) {
@ -487,7 +495,7 @@ function networkConnections(callback) {
}); });
} }
if (_darwin) { if (_darwin) {
let cmd = "netstat -nat | grep 'ESTABLISHED\\|SYN_SENT\\|SYN_RECV\\|FIN_WAIT1\\|FIN_WAIT2\\|TIME_WAIT\\|CLOSE\\|CLOSE_WAIT\\|LAST_ACK\\|LISTEN\\|CLOSING\\|UNKNOWN'"; let cmd = 'netstat -nat | grep "ESTABLISHED\\|SYN_SENT\\|SYN_RECV\\|FIN_WAIT1\\|FIN_WAIT2\\|TIME_WAIT\\|CLOSE\\|CLOSE_WAIT\\|LAST_ACK\\|LISTEN\\|CLOSING\\|UNKNOWN"';
exec(cmd, function (error, stdout) { exec(cmd, function (error, stdout) {
if (!error) { if (!error) {

View File

@ -16,11 +16,14 @@ const os = require('os');
const exec = require('child_process').exec; const exec = require('child_process').exec;
const util = require('./util'); const util = require('./util');
let _platform = os.type(); let _platform = process.platform;
const _linux = (_platform === 'linux');
const _darwin = (_platform === 'darwin');
const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
const _linux = (_platform === 'Linux');
const _darwin = (_platform === 'Darwin');
const _windows = (_platform === 'Windows_NT');
const NOT_SUPPORTED = 'not supported'; const NOT_SUPPORTED = 'not supported';
// -------------------------- // --------------------------
@ -91,6 +94,9 @@ function getLogoFile(distro) {
else if (distro.indexOf('openbsd') !== -1) { else if (distro.indexOf('openbsd') !== -1) {
result = 'openbsd'; result = 'openbsd';
} }
else if (distro.indexOf('freebsd') !== -1) {
result = 'freebsd';
}
else if (distro.indexOf('opensuse') !== -1) { else if (distro.indexOf('opensuse') !== -1) {
result = 'opensuse'; result = 'opensuse';
} }
@ -185,6 +191,22 @@ function osInfo(callback) {
resolve(result); resolve(result);
}); });
} }
if (_freebsd || _openbsd) {
exec('sysctl kern.ostype kern.osrelease kern.osrevision', function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
result.distro = util.getValue(lines, 'kern.ostype');
result.logofile = getLogoFile(result.distro);
result.release = util.getValue(lines, 'kern.osrelease').split('-')[0];
result.codename = '';
}
if (callback) {
callback(result);
}
resolve(result);
});
}
if (_darwin) { if (_darwin) {
exec('sw_vers', function (error, stdout) { exec('sw_vers', function (error, stdout) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');

View File

@ -16,11 +16,14 @@ const os = require('os');
const exec = require('child_process').exec; const exec = require('child_process').exec;
const util = require('./util'); const util = require('./util');
let _platform = os.type(); let _platform = process.platform;
const _linux = (_platform === 'linux');
const _darwin = (_platform === 'darwin');
const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
const _linux = (_platform === 'Linux');
const _darwin = (_platform === 'Darwin');
const _windows = (_platform === 'Windows_NT');
const NOT_SUPPORTED = 'not supported'; const NOT_SUPPORTED = 'not supported';
let _process_cpu = { let _process_cpu = {
@ -69,32 +72,85 @@ function services(srv, callback) {
return new Promise((resolve) => { return new Promise((resolve) => {
process.nextTick(() => { process.nextTick(() => {
srv = srv.trim().toLowerCase().replace(/,+/g, ' ').replace(/ +/g, ' ').replace(/ +/g, '|'); if (srv) {
let srvs = srv.split('|'); srv = srv.trim().toLowerCase().replace(/,+/g, ' ').replace(/ +/g, ' ').replace(/ +/g, '|');
let data = []; let srvs = srv.split('|');
let dataSrv = []; let data = [];
let dataSrv = [];
if (_linux || _darwin) { if (_linux || _freebsd || _openbsd || _darwin) {
let comm = (_darwin) ? 'ps -caxm -o pcpu,pmem,comm' : 'ps axo pcpu,pmem,comm'; let comm = (_darwin) ? 'ps -caxm -o pcpu,pmem,comm' : 'ps axo pcpu,pmem,comm';
if (srv !== '' && srvs.length > 0) { if (srv !== '' && srvs.length > 0) {
exec(comm + " | grep -v grep | egrep '" + srv + "'", function (error, stdout) { exec(comm + " | grep -v grep | egrep '" + srv + "'", function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.toString().replace(/ +/g, ' ').replace(/,+/g, '.').split('\n'); let lines = stdout.toString().replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
srvs.forEach(function (srv) { srvs.forEach(function (srv) {
let ps = lines.filter(function (e) { let ps = lines.filter(function (e) {
return e.indexOf(srv) !== -1; return e.indexOf(srv) !== -1;
});
data.push({
'name': srv,
'running': ps.length > 0,
'pcpu': parseFloat((ps.reduce(function (pv, cv) {
return pv + parseFloat(cv.trim().split(' ')[0]);
}, 0)).toFixed(2)),
'pmem': parseFloat((ps.reduce(function (pv, cv) {
return pv + parseFloat(cv.trim().split(' ')[1]);
}, 0)).toFixed(2))
});
}); });
if (callback) { callback(data); }
resolve(data);
} else {
srvs.forEach(function (srv) {
data.push({
'name': srv,
'running': false,
'pcpu': 0,
'pmem': 0
});
});
if (callback) { callback(data); }
resolve(data);
}
});
} else {
if (callback) { callback(data); }
resolve(data);
}
}
if (_windows) {
exec(util.getWmic() + ' service get /value', {maxBuffer: 1024 * 1000}, function (error, stdout) {
if (!error) {
let serviceSections = stdout.split(/\n\s*\n/);
for (let i = 0; i < serviceSections.length; i++) {
if (serviceSections[i].trim() !== '') {
let lines = serviceSections[i].trim().split('\r\n');
let srv = util.getValue(lines, 'Name', '=', true).toLowerCase();
let started = util.getValue(lines, 'Started', '=', true);
if (srvs.indexOf(srv) >= 0) {
data.push({
'name': srv,
'running': (started === 'TRUE'),
'pcpu': 0,
'pmem': 0
});
dataSrv.push(srv);
}
}
}
let srvsMissing = srvs.filter(function (e) {
return dataSrv.indexOf(e) === -1;
});
srvsMissing.forEach(function (srv) {
data.push({ data.push({
'name': srv, 'name': srv,
'running': ps.length > 0, 'running': false,
'pcpu': parseFloat((ps.reduce(function (pv, cv) { 'pcpu': 0,
return pv + parseFloat(cv.trim().split(' ')[0]); 'pmem': 0
}, 0)).toFixed(2)),
'pmem': parseFloat((ps.reduce(function (pv, cv) {
return pv + parseFloat(cv.trim().split(' ')[1]);
}, 0)).toFixed(2))
}); });
}); });
if (callback) { callback(data); } if (callback) { callback(data); }
resolve(data); resolve(data);
} else { } else {
@ -110,58 +166,10 @@ function services(srv, callback) {
resolve(data); resolve(data);
} }
}); });
} else {
if (callback) { callback(data); }
resolve(data);
} }
} } else {
if (_windows) { if (callback) { callback({}); }
exec(util.getWmic() + ' service get /value', {maxBuffer: 1024 * 1000}, function (error, stdout) { resolve({});
if (!error) {
let serviceSections = stdout.split(/\n\s*\n/);
for (let i = 0; i < serviceSections.length; i++) {
if (serviceSections[i].trim() !== '') {
let lines = serviceSections[i].trim().split('\r\n');
let srv = util.getValue(lines, 'Name', '=', true).toLowerCase();
let started = util.getValue(lines, 'Started', '=', true);
if (srvs.indexOf(srv) >= 0) {
data.push({
'name': srv,
'running': (started === 'TRUE'),
'pcpu': 0,
'pmem': 0
});
dataSrv.push(srv);
}
}
}
let srvsMissing = srvs.filter(function (e) {
return dataSrv.indexOf(e) === -1;
});
srvsMissing.forEach(function (srv) {
data.push({
'name': srv,
'running': false,
'pcpu': 0,
'pmem': 0
});
});
if (callback) { callback(data); }
resolve(data);
} else {
srvs.forEach(function (srv) {
data.push({
'name': srv,
'running': false,
'pcpu': 0,
'pmem': 0
});
});
if (callback) { callback(data); }
resolve(data);
}
});
} }
}); });
}); });
@ -407,8 +415,9 @@ function processes(callback) {
let cmd = ''; let cmd = '';
if ((_process_cpu.ms && Date.now() - _process_cpu.ms >= 500) || _process_cpu.ms === 0) { if ((_process_cpu.ms && Date.now() - _process_cpu.ms >= 500) || _process_cpu.ms === 0) {
if (_linux || _darwin) { if (_linux || _freebsd || _openbsd || _darwin) {
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 (_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 (_freebsd || _openbsd) cmd = 'ps axo pid,pcpu,pmem,pri,vsz,rss,ni,start,state,tty,user,command';
if (_darwin) cmd = 'ps acxo pid,pcpu,pmem,pri,vsz,rss,nice,start,state,tty,user,command -r'; if (_darwin) cmd = 'ps acxo pid,pcpu,pmem,pri,vsz,rss,nice,start,state,tty,user,command -r';
exec(cmd, function (error, stdout) { exec(cmd, function (error, stdout) {
if (!error) { if (!error) {
@ -426,7 +435,7 @@ function processes(callback) {
if (_linux) { if (_linux) {
// calc process_cpu - ps is not accurate in linux! // calc process_cpu - ps is not accurate in linux!
cmd = "cat /proc/stat | grep 'cpu '"; cmd = 'cat /proc/stat | grep "cpu "';
for (let i = 0; i < result.list.length; i++) { for (let i = 0; i < result.list.length; i++) {
cmd += (';cat /proc/' + result.list[i].pid + '/stat'); cmd += (';cat /proc/' + result.list[i].pid + '/stat');
} }

View File

@ -22,7 +22,7 @@ const _linux = (_platform === 'linux');
const _darwin = (_platform === 'darwin'); const _darwin = (_platform === 'darwin');
const _windows = (_platform === 'win32'); const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd'); const _freebsd = (_platform === 'freebsd');
const _sunos = (_platform === 'sunos'); const _openbsd = (_platform === 'openbsd');
function system(callback) { function system(callback) {
@ -38,7 +38,7 @@ function system(callback) {
sku: '-', sku: '-',
}; };
if (_linux) { if (_linux || _freebsd || _openbsd) {
exec('dmidecode -t system', function (error, stdout) { exec('dmidecode -t system', function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
@ -194,7 +194,7 @@ function bios(callback) {
revision: '', revision: '',
}; };
let cmd = ''; let cmd = '';
if (_linux) { if (_linux || _freebsd || _openbsd) {
if (process.arch === 'arm') { if (process.arch === 'arm') {
cmd = 'cat /proc/cpuinfo | grep Serial'; cmd = 'cat /proc/cpuinfo | grep Serial';
@ -207,7 +207,7 @@ function bios(callback) {
result.vendor = util.getValue(lines, 'Vendor'); result.vendor = util.getValue(lines, 'Vendor');
result.version = util.getValue(lines, 'Version'); result.version = util.getValue(lines, 'Version');
const datetime = util.getValue(lines, 'Release Date'); const datetime = util.getValue(lines, 'Release Date');
result.releaseDate = datetime.date; result.releaseDate = util.parseDateTime(datetime).date;
result.revision = util.getValue(lines, 'BIOS Revision'); result.revision = util.getValue(lines, 'BIOS Revision');
} }
@ -268,7 +268,7 @@ function baseboard(callback) {
assetTag: '-', assetTag: '-',
}; };
let cmd = ''; let cmd = '';
if (_linux) { if (_linux || _freebsd || _openbsd) {
if (process.arch === 'arm') { if (process.arch === 'arm') {
cmd = 'cat /proc/cpuinfo | grep Serial'; cmd = 'cat /proc/cpuinfo | grep Serial';
// 'BCM2709', 'BCM2835', 'BCM2708' --> // 'BCM2709', 'BCM2835', 'BCM2708' -->

View File

@ -12,15 +12,16 @@
// 11. Users/Sessions // 11. Users/Sessions
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
const os = require('os');
const exec = require('child_process').exec; const exec = require('child_process').exec;
const util = require('./util'); const util = require('./util');
let _platform = os.type(); let _platform = process.platform;
const _linux = (_platform === 'Linux'); const _linux = (_platform === 'linux');
const _darwin = (_platform === 'Darwin'); const _darwin = (_platform === 'darwin');
const _windows = (_platform === 'Windows_NT'); const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
// -------------------------- // --------------------------
// array of users online = sessions // array of users online = sessions
@ -204,6 +205,17 @@ function users(callback) {
} }
}); });
} }
if (_freebsd || _openbsd) {
exec('who; echo "---"; w -ih', function (error, stdout) {
if (!error) {
// lines / split
let lines = stdout.toString().split('\n');
result = parseUsersDarwin(lines);
}
if (callback) { callback(result); }
resolve(result);
});
}
if (_darwin) { if (_darwin) {
exec('who; echo "---"; w -ih', function (error, stdout) { exec('who; echo "---"; w -ih', function (error, stdout) {

View File

@ -65,11 +65,11 @@ function getValue(lines, property, separator, trimmed) {
property = property.toLowerCase(); property = property.toLowerCase();
trimmed = trimmed || false; trimmed = trimmed || false;
for (let i = 0; i < lines.length; i++) { for (let i = 0; i < lines.length; i++) {
let line = lines[i].toLowerCase(); let line = lines[i].toLowerCase().replace(/\t/g, '');
if (trimmed) { if (trimmed) {
line = line.trim(); line = line.trim();
} }
if (line.toLowerCase().startsWith(property)) { if (line.startsWith(property)) {
const parts = lines[i].split(separator); const parts = lines[i].split(separator);
if (parts.length >= 2) { if (parts.length >= 2) {
parts.shift(); parts.shift();
@ -128,11 +128,13 @@ function getWmic() {
if (os.type() === 'Windows_NT' && !wmic) { if (os.type() === 'Windows_NT' && !wmic) {
if (fs.existsSync(process.env.WINDIR + '\\system32\\wbem\\wmic.exe')) { if (fs.existsSync(process.env.WINDIR + '\\system32\\wbem\\wmic.exe')) {
wmic = process.env.WINDIR + '\\system32\\wbem\\wmic.exe'; wmic = process.env.WINDIR + '\\system32\\wbem\\wmic.exe';
} else wmic = 'wmic' } else wmic = 'wmic';
} }
return wmic; return wmic;
} }
function noop(){}
exports.isFunction = isFunction; exports.isFunction = isFunction;
exports.unique = unique; exports.unique = unique;
exports.sortByKey= sortByKey; exports.sortByKey= sortByKey;
@ -141,3 +143,4 @@ exports.getValue = getValue;
exports.decodeEscapeSequence = decodeEscapeSequence; exports.decodeEscapeSequence = decodeEscapeSequence;
exports.parseDateTime = parseDateTime; exports.parseDateTime = parseDateTime;
exports.getWmic = getWmic; exports.getWmic = getWmic;
exports.noop = noop;

View File

@ -18,6 +18,7 @@
"linux", "linux",
"osx", "osx",
"windows", "windows",
"freebsd",
"cpu", "cpu",
"cpuload", "cpuload",
"memory", "memory",
@ -48,7 +49,9 @@
"os": [ "os": [
"darwin", "darwin",
"linux", "linux",
"win32" "win32",
"freebsd",
"openbsd"
], ],
"engines": { "engines": {
"node": ">=4.0.0" "node": ">=4.0.0"