added TypeScript type definitions

This commit is contained in:
Sebastian Hildebrandt 2018-12-30 11:30:44 +01:00
parent 2fac9982e4
commit d00e0ef42c
8 changed files with 600 additions and 17 deletions

1
.gitignore vendored
View File

@ -63,7 +63,6 @@ package-lock.json
test/
dist/
index.d.ts
tsconfig.json
tslint.json
typings.d.ts

View File

@ -100,6 +100,7 @@ Other changes
| Version | Date | Comment |
| -------------- | -------------- | -------- |
| 3.54.0 | 2018-12-30 | added TypeScript type definitions |
| 3.53.1 | 2018-12-29 | `versions()` bug fix nginx version |
| 3.53.0 | 2018-12-29 | `versions()` added perl, python, gcc |
| 3.52.7 | 2018-12-29 | `versions()` bug fix macOS detection |

View File

@ -158,7 +158,7 @@ I also created a nice little command line tool called [mmon][mmon-github-url] (
| | socket | X | X | | X | | socket type e.g. "LGA1356" |
| | vendor | X | X | X | X | | vendor ID |
| | family | X | X | X | X | | processor family |
| | Model | X | X | X | X | | processor model |
| | model | X | X | X | X | | processor model |
| | stepping | X | X | X | X | | processor stepping |
| | revision | X | | X | X | | revision |
| | voltage | | X | | | | voltage |
@ -245,11 +245,11 @@ I also created a nice little command line tool called [mmon][mmon-github-url] (
| | ...[0].main | X | | X | | | true if main monitor |
| | ...[0].builtin | X | | X | | | true if built in monitor |
| | ...[0].connection | X | | X | | | e.g. DisplayPort or HDMI |
| | ...[0].resolutionx | X | | X | X | | pixel horizontal |
| | ...[0].resolutiony | X | | X | X | | pixel vertical |
| | ...[0].pixeldepth | X | | X | X | | color depth in bits |
| | ...[0].sizex | X | | X | | | size in mm horizontal |
| | ...[0].sizey | X | | X | | | size in mm vertical |
| | ...[0].pixeldepth | X | | X | X | | color depth in bits |
| | ...[0].resolutionx | X | | X | X | | pixel horizontal |
| | ...[0].resolutiony | X | | X | X | | pixel vertical |
#### 4. Operating System
@ -263,10 +263,10 @@ I also created a nice little command line tool called [mmon][mmon-github-url] (
| | kernel | X | X | X | X | X | kernel release - same as os.release() |
| | arch | X | X | X | X | X | same as os.arch() |
| | hostname | X | X | X | X | X | same as os.hostname() |
| | codepage | X | X | X | X | | OS build version |
| | logofile | X | X | X | X | X | e.g. 'apple', 'debian', 'fedora', ... |
| | serial | | X | X | X | | OS/Host serial number |
| | build | | | X | X | | OS build version |
| | codepage | X | X | X | X | | OS build version |
| si.uuid(cb) | {...} | X | X | X | X | X | object of several UUIDs |
| | os | X | X | X | X | | os specific UUID |
| si.versions(cb) | {...} | X | X | X | X | X | version information (kernel, ssl, node, ...) |
@ -394,12 +394,14 @@ I also created a nice little command line tool called [mmon][mmon-github-url] (
| si.processLoad('apache2',cb) | {...} | X | X | X | X | | detailed information about given process |
| | proc | X | X | X | X | | process name |
| | pid | X | X | X | X | | PID |
| | pids | X | X | X | X | | additional pids |
| | cpu | X | X | X | X | | process % CPU |
| | mem | X | X | X | X | | process % MEM |
| si.services('mysql, apache2', cb) | [{...}] | X | X | X | X | | pass comma separated string of services<br>pass "*" for ALL services (linux/win only) |
| | [0].name | X | X | X | X | | name of service |
| | [0].running | X | X | X | X | | true / false |
| | [0].startmode | | | | X | | manual, automatic, ... |
| | [0].pids | X | X | X | | | pids |
| | [0].pcpu | X | X | X | | | process % CPU |
| | [0].pmem | X | X | X | | | process % MEM |

View File

@ -829,7 +829,7 @@ function cpuFlags(callback) {
exports.cpuFlags = cpuFlags;
// --------------------------
// CPU Flags
// CPU Cache
function cpuCache(callback) {

View File

@ -45,8 +45,24 @@ function graphics(callback) {
let lastlevel = -1;
let controllers = [];
let displays = [];
let currentController = {};
let currentDisplay = {};
let currentController = {
vendor: '',
model: '',
bus: '',
vram: -1,
vramDynamic: false
};
let currentDisplay = {
model: '',
main: false,
builtin: false,
connection: '',
sizex: -1,
sizey: -1,
pixeldepth: -1,
resolutionx: -1,
resolutiony: -1
};
for (let i = 0; i < lines.length; i++) {
if ('' !== lines[i].trim()) {
let start = lines[i].search(/\S|$/);
@ -57,11 +73,27 @@ function graphics(callback) {
if (level < lastlevel) {
if (Object.keys(currentController).length > 0) {// just changed to Displays
controllers.push(currentController);
currentController = {};
currentController = {
vendor: '',
model: '',
bus: '',
vram: -1,
vramDynamic: false
};
}
if (Object.keys(currentDisplay).length > 0) {// just changed to Displays
displays.push(currentDisplay);
currentDisplay = {};
currentDisplay = {
model: '',
main: false,
builtin: false,
connection: '',
sizex: -1,
sizey: -1,
pixeldepth: -1,
resolutionx: -1,
resolutiony: -1
};
}
}
lastlevel = level;
@ -87,6 +119,7 @@ function graphics(callback) {
currentDisplay.connection = '';
currentDisplay.sizex = -1;
currentDisplay.sizey = -1;
currentDisplay.pixeldepth = -1;
}
}
if (4 === level) { // display controller details level
@ -96,6 +129,7 @@ function graphics(callback) {
currentDisplay.resolutiony = (resolution.length > 1 ? parseInt(resolution[1]) : 0);
}
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('pixeldepth') !== -1) currentDisplay.pixeldepth = parseInt(parts[1]); // in BIT
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('framebufferdepth') !== -1) currentDisplay.pixeldepth = parseInt(parts[1]); // in BIT
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('maindisplay') !== -1 && parts[1].replace(/ +/g, '').toLowerCase() === 'yes') currentDisplay.main = true;
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('built-in') !== -1 && parts[1].replace(/ +/g, '').toLowerCase() === 'yes') {
currentDisplay.builtin = true;
@ -122,7 +156,13 @@ function graphics(callback) {
function parseLinesLinuxControllers(lines) {
let controllers = [];
let currentController = {};
let currentController = {
vendor: '',
model: '',
bus: '',
vram: -1,
vramDynamic: false
};
let isGraphicsController = false;
// PCI bus IDs
let pciIDs = [];
@ -149,7 +189,13 @@ function graphics(callback) {
}
if (Object.keys(currentController).length > 0) {// already a controller found
controllers.push(currentController);
currentController = {};
currentController = {
vendor: '',
model: '',
bus: '',
vram: -1,
vramDynamic: false
};
}
isGraphicsController = true;
let endpos = lines[i].search(/\[[0-9a-f]{4}:[0-9a-f]{4}]|$/);
@ -215,7 +261,17 @@ function graphics(callback) {
// --> pixeldepth (?)
// --> sizex
// --> sizey
let result = {};
let result = {
model: '',
main: false,
builtin: false,
connection: '',
sizex: -1,
sizey: -1,
pixeldepth: -1,
resolutionx: -1,
resolutiony: -1
};
// find first "Detailed Timing Description"
let start = 108;
if (edid.substr(start, 6) === '000000') {
@ -252,7 +308,17 @@ function graphics(callback) {
function parseLinesLinuxDisplays(lines, depth) {
let displays = [];
let currentDisplay = {};
let currentDisplay = {
model: '',
main: false,
builtin: false,
connection: '',
sizex: -1,
sizey: -1,
pixeldepth: -1,
resolutionx: -1,
resolutiony: -1
};
let is_edid = false;
let edid_raw = '';
let start = 0;
@ -261,7 +327,17 @@ function graphics(callback) {
if (' ' !== lines[i][0] && '\t' !== lines[i][0] && lines[i].toLowerCase().indexOf(' connected ') !== -1) { // first line of new entry
if (Object.keys(currentDisplay).length > 0) { // push last display to array
displays.push(currentDisplay);
currentDisplay = {};
currentDisplay = {
model: '',
main: false,
builtin: false,
connection: '',
sizex: -1,
sizey: -1,
pixeldepth: -1,
resolutionx: -1,
resolutiony: -1
};
}
let parts = lines[i].split(' ');
currentDisplay.connection = parts[0];

503
lib/index.d.ts vendored Normal file
View File

@ -0,0 +1,503 @@
// Type definitions for systeminformation
// Project: https://github.com/sebhildebrandt/systeminformation
// Definitions by: sebhildebrandt <https://github.com/sebhildebrandt>
export namespace Systeminformation {
// 1. General
interface TimeData {
current: string;
uptime: string;
timezone: string;
timezoneName: string;
}
// 2. System (HW)
interface SystemData {
manufacturer: string;
model: string;
version: string;
serial: string;
uuid: string;
sku: string;
}
interface BiosData {
vendor: string;
version: string;
releaseDate: string;
revision: string;
}
interface BaseboardData {
manufacturer: string;
model: string;
version: string;
serial: string;
assetTag: string;
}
// 3. CPU, Memory, Disks, Battery, Graphics
interface CpuData {
manufacturer: string;
brand: string;
vendor: string;
family: string;
model: string;
stepping: string;
revision: string;
voltage: string;
speed: string;
speedmin: string;
speedmax: string;
cores: number;
physicalCores: number;
processors: number;
socket: string;
cache: CpuCacheData;
}
interface CpuWithFlagsData extends CpuData {
flags: string;
}
interface CpuCacheData {
l1d: number;
l1i: number;
l2: number;
l3: number;
}
interface CpuCurrentSpeedData {
min: string;
max: string;
avg: string;
cores: number[];
}
interface CpuTemperatureData {
main: string;
cores: string;
max: string;
}
interface MemData {
total: number;
free: number;
used: number;
active: number;
available: number;
buffcache: number;
swaptotal: number;
swapused: number;
swapfree: number;
}
interface MemLayoutData {
size: number;
bank: string;
type: string;
clockSpeed: number;
formFactor: string;
partNum: string;
serialNum: string;
voltageConfigured: number;
voltageMin: number;
voltageMax: number;
}
interface DiskLayoutData {
type: string;
name: string;
vendor: string;
size: number;
bytesPerSector: number;
totalCylinders: number;
totalHeads: number;
totalSectors: number;
totalTracks: number;
tracksPerCylinder: number;
sectorsPerTrack: number;
firmwareRevision: string;
serialNum: string;
interfaceType: string;
smartStatus: string;
}
interface BatteryData {
hasbattery: boolean;
cyclecount: number;
ischarging: boolean;
maxcapacity: number;
currentcapacity: number;
percent: number;
timeremaining: number,
acconnected: boolean;
type: string;
model: string;
manufacturer: string;
serial: string;
}
interface GraphicsData {
controllers: GraphicsControllerData[];
displays: GraphicsDisplayData[];
}
interface GraphicsControllerData {
vendor: string;
model: string;
bus: string;
vram: number;
vramDynamic: boolean;
}
interface GraphicsDisplayData {
model: string;
main: boolean;
builtin: boolean;
connection: string;
sizex: number;
sizey: number;
pixeldepth: number;
resolutionx: number;
resolutiony: number;
}
// 4. Operating System
interface OsData {
platform: string;
distro: string;
release: string;
codename: string;
kernel: string;
arch: string;
hostname: string;
codepage: string;
logofile: string;
serial: string;
build: string;
}
interface UuidData {
os: string;
}
interface VersionData {
kernel: string;
openssl: string;
systemOpenssl: string;
systemOpensslLib: string;
node: string;
v8: string;
npm: string;
yarn: string;
pm2: string;
gulp: string;
grunt: string;
git: string;
tsc: string;
mysql: string;
redis: string;
mongodb: string;
nginx: string;
php: string;
docker: string;
postfix: string;
postgresql: string;
perl: string;
python: string;
gcc: string;
}
interface UserData {
user: string;
tty: string;
date: string;
time: string;
ip: string;
command: string;
}
// 5. File System
interface FsSizeData {
fs: string;
type: string;
size: number;
used: number;
use: number;
mount: string;
}
interface BlockDevicesData {
name: string;
identifier: string;
type: string;
fstype: string;
mount: string;
size: number;
physical: string;
uuid: string;
label: string;
model: string;
serial: string;
removable: boolean;
protocol: string;
}
interface FsStatsData {
rx: number;
wx: number;
tx: number;
rx_sec: number;
wx_sec: number;
tx_sec: number;
ms: number;
}
interface DisksIoData {
rIO: number;
wIO: number;
tIO: number;
rIO_sec: number;
wIO_sec: number;
tIO_sec: number;
ms: number;
}
// 6. Network related functions
interface NetworkInterfacesData {
iface: string;
ip4: string;
ip6: string;
mac: string;
internal: boolean;
}
interface NetworkStatsData {
iface: string;
operstate: string;
rx: number;
tx: number;
rx_sec: number;
tx_sec: number;
ms: number;
}
interface NetworkConnectionsData {
protocol: string;
localaddress: string;
localport: string;
peeraddress: string;
peerport: string;
state: string;
}
interface InetChecksiteData {
url: string;
ok: boolean;
status: number;
ms: number;
}
// 7. Current Load, Processes & Services
interface CurrentLoadData {
avgload: number;
currentload: number;
currentload_user: number;
currentload_system: number;
currentload_nice: number;
currentload_idle: number;
currentload_irq: number;
raw_currentload: number;
raw_currentload_user: number;
raw_currentload_system: number;
raw_currentload_nice: number;
raw_currentload_idle: number;
raw_currentload_irq: number;
cpus: CurrentLoadCpuData[];
}
interface CurrentLoadCpuData {
load: number;
load_user: number;
load_system: number;
load_nice: number;
load_idle: number;
load_irq: number;
raw_load: number;
raw_load_user: number;
raw_load_system: number;
raw_load_nice: number;
raw_load_idle: number;
raw_load_irq: number;
}
interface ProcessesData {
all: number;
running: number;
blocked: number;
sleeping: number;
unknown: number;
list: ProcessesProcessData[];
}
interface ProcessesProcessData {
pid: number;
parentPid: number;
name: string,
pcpu: number;
pcpuu: number;
pcpus: number;
pmem: number;
priority: number;
mem_vsz: number;
mem_rss: number;
nice: number;
started: string,
state: number;
tty: number;
user: number;
command: number;
}
interface ProcessesProcessLoadData {
proc: string;
pid: number;
pids: number[];
cpu: number;
mem: number;
}
interface ServicesData {
name: string;
running: boolean;
startmode: string;
pids: number[];
pcpu: number;
pmem: number;
}
// 8. Docker
interface DockerContainerData {
id: string;
name: string;
image: string;
imageID: string;
command: string;
created: number;
state: string;
ports: number[];
mounts: DockerContainerMountData[];
}
interface DockerContainerMountData {
Type: string;
Source: string;
Destination: string;
Mode: string;
RW: boolean;
Propagation: string;
}
interface DockerContainerStatsData {
id: string;
mem_usage: number;
mem_limit: number;
mem_percent: number;
cpu_percent: number;
netIO: {
rx: number;
wx: number;
};
blockIO: {
r: number;
w: number;
};
cpu_stats: any;
precpu_stats: any;
memory_stats: any,
networks: any;
}
// 9. "Get All at once" - functions
interface StaticData {
version: string;
system: SystemData;
bios: BiosData;
baseboard: BaseboardData;
os: OsData;
uuid: UuidData;
versions: VersionData;
cpu: CpuWithFlagsData;
graphics: GraphicsData;
net: NetworkInterfacesData[];
memLayout: MemLayoutData[];
diskLayout: DiskLayoutData[];
}
}
export function version(): string;
export function system(cb?: (data: Systeminformation.SystemData) => any): Promise<Systeminformation.SystemData>;
export function bios(cb?: (data: Systeminformation.BiosData) => any): Promise<Systeminformation.BiosData>;
export function baseboard(cb?: (data: Systeminformation.BaseboardData) => any): Promise<Systeminformation.BaseboardData>;
export function time(): Systeminformation.TimeData;
export function osInfo(cb?: (data: Systeminformation.OsData) => any): Promise<Systeminformation.OsData>;
export function versions(cb?: (data: Systeminformation.VersionData) => any): Promise<Systeminformation.VersionData>;
export function shell(cb?: (data: string) => any): Promise<string>;
export function uuid(cb?: (data: Systeminformation.UuidData) => any): Promise<Systeminformation.UuidData>;
export function cpu(cb?: (data: Systeminformation.CpuData) => any): Promise<Systeminformation.CpuData>;
export function cpuFlags(cb?: (data: string) => any): Promise<string>;
export function cpuCache(cb?: (data: Systeminformation.CpuCacheData) => any): Promise<Systeminformation.CpuCacheData>;
export function cpuCurrentspeed(cb?: (data: Systeminformation.CpuCurrentSpeedData) => any): Promise<Systeminformation.CpuCurrentSpeedData>;
export function cpuTemperature(cb?: (data: Systeminformation.CpuTemperatureData) => any): Promise<Systeminformation.CpuTemperatureData>;
export function currentLoad(cb?: (data: Systeminformation.CurrentLoadData) => any): Promise<Systeminformation.CurrentLoadData>;
export function fullLoad(cb?: (data: number) => any): Promise<number>;
export function mem(cb?: (data: Systeminformation.MemData) => any): Promise<Systeminformation.MemData>;
export function memLayout(cb?: (data: Systeminformation.MemLayoutData) => any): Promise<Systeminformation.MemLayoutData>;
export function battery(cb?: (data: Systeminformation.BatteryData) => any): Promise<Systeminformation.BatteryData>;
export function graphics(cb?: (data: Systeminformation.GraphicsData) => any): Promise<Systeminformation.GraphicsData>;
export function fsSize(cb?: (data: Systeminformation.FsSizeData[]) => any): Promise<Systeminformation.FsSizeData[]>;
export function blockDevices(cb?: (data: Systeminformation.BlockDevicesData[]) => any): Promise<Systeminformation.BlockDevicesData[]>;
export function fsStats(cb?: (data: Systeminformation.FsStatsData) => any): Promise<Systeminformation.FsStatsData>;
export function disksIO(cb?: (data: Systeminformation.DisksIoData) => any): Promise<Systeminformation.DisksIoData>;
export function diskLayout(cb?: (data: Systeminformation.DiskLayoutData) => any): Promise<Systeminformation.DiskLayoutData>;
export function networkInterfaceDefault(cb?: (data: string) => any): Promise<string>;
export function networkInterfaces(cb?: (data: Systeminformation.NetworkInterfacesData[]) => any): Promise<Systeminformation.NetworkInterfacesData[]>;
export function networkStats(iface?: string, cb?: (data: Systeminformation.NetworkStatsData) => any): Promise<Systeminformation.NetworkStatsData>;
export function networkConnections(cb?: (data: Systeminformation.NetworkConnectionsData[]) => any): Promise<Systeminformation.NetworkConnectionsData[]>;
export function inetChecksite(url: string, cb?: (data: Systeminformation.InetChecksiteData) => any): Promise<Systeminformation.InetChecksiteData>;
export function inetLatency(host?: string, cb?: (data: number) => any): Promise<number>;
export function users(cb?: (data: Systeminformation.UserData[]) => any): Promise<Systeminformation.UserData[]>;
export function processes(cb?: (data: Systeminformation.ProcessesData) => any): Promise<Systeminformation.ProcessesData>;
export function processLoad(processName: string, cb?: (data: Systeminformation.ProcessesProcessLoadData) => any): Promise<Systeminformation.ProcessesProcessLoadData>;
export function services(serviceName: string, cb?: (data: Systeminformation.ServicesData[]) => any): Promise<Systeminformation.ServicesData[]>;
export function dockerContainers(all?: boolean, cb?: (data: Systeminformation.DockerContainerData[]) => any): Promise<Systeminformation.DockerContainerData[]>;
export function dockerContainerStats(id?: string, cb?: (data: Systeminformation.DockerContainerStatsData[]) => any): Promise<Systeminformation.DockerContainerStatsData[]>;
export function dockerContainerProcesses(id?: string, cb?: (data: any) => any): Promise<any>;
export function dockerAll(cb?: (data: any) => any): Promise<any>;
export function getStaticData(cb?: (data: Systeminformation.StaticData) => any): Promise<Systeminformation.StaticData>;
export function getDynamicData(srv?: string, iface?: string, cb?: (data: any) => any): Promise<any>;
export function getAllData(srv?: string, iface?: string, cb?: (data: any) => any): Promise<any>;

View File

@ -371,9 +371,10 @@ function versions(callback) {
});
if (_darwin) {
const cmdLineToolsExists = fs.existsSync('/Library/Developer/CommandLineTools/');
const xcodeAppExists = fs.existsSync('/Applications/Xcode.app/Contents/Developer/Tools');
const xcodeExists = fs.existsSync('/Library/Developer/Xcode/');
const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/git');
if (cmdLineToolsExists || xcodeExists || gitHomebrewExists) {
if (cmdLineToolsExists || xcodeExists || gitHomebrewExists || xcodeAppExists) {
exec('git --version', function (error, stdout) {
if (!error) {
let git = stdout.toString().split('\n')[0] || '';

View File

@ -6,6 +6,7 @@
"author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)",
"homepage": "https://github.com/sebhildebrandt/systeminformation",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"scripts": {
"clean": "rimraf dist",
"test-bare": "npm run compile && mocha ./test/**/*.test.js",