From 37f4e94c73b08454653642224ddc62ac36d229aa Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Mon, 25 Oct 2021 22:26:03 +0200 Subject: [PATCH] code improvements, typings improvement --- CHANGELOG.md | 2 +- lib/cpu.js | 59 +++++++++++++++++++++++++++++++++++++------------- lib/docker.js | 7 +++++- lib/index.d.ts | 36 +++++++++++++++++++++++++----- lib/memory.js | 12 +++++----- lib/osinfo.js | 3 ++- 6 files changed, 89 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdd263e..0aa5cb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,7 +85,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page. | 5.9.6 | 2021-10-08 | `system()` fixed virtual on WSL2 | | 5.9.5 | 2021-10-08 | `battery()` fixed isCharging (windows) | | 5.9.4 | 2021-09-23 | `processes()` fixed memVsz, Memrss (macOS M1) | -| 5.9.3 | 2021-09-17 | `cpuTemperature()` improved tdie detection (linus) | +| 5.9.3 | 2021-09-17 | `cpuTemperature()` improved tdie detection (linux) | | 5.9.2 | 2021-09-16 | `graohics()` (macOS), `memLayout()` (win) improvements | | 5.9.1 | 2021-09-15 | `diskLayout()` fix size (macOS) | | 5.9.0 | 2021-09-15 | `graphics()` new XML parser, added properties (macOS) | diff --git a/lib/cpu.js b/lib/cpu.js index 0c6530f..29d5a80 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -373,10 +373,12 @@ const AMDBaseFrequencies = { '4700G': '3.6', 'Pro 4750G': '3.6', '4300U': '2.7', + '4450U': '2.5', 'Pro 4450U': '2.5', '4500U': '2.3', '4600U': '2.1', 'PRO 4650U': '2.1', + '4680U': '2.1', '4600HS': '3.0', '4600H': '3.0', '4700U': '2.0', @@ -386,6 +388,9 @@ const AMDBaseFrequencies = { '4800H': '2.9', '4900HS': '3.0', '4900H': '3.3', + '5300U': '2.6', + '5500U': '2.1', + '5700U': '1.8', // ZEN2 - EPYC '7232P': '3.1', @@ -414,6 +419,28 @@ const AMDBaseFrequencies = { '7F52': '3.5', '7F72': '3.2', + // Epyc (Milan) + + '7763': '2.45', + '7713': '2.0', + '7713P': '2.0', + '7663': '2.0', + '7643': '2.3', + '75F3': '2.95', + '7543': '2.8', + '7543P': '2.8', + '7513': '2.6', + '7453': '2.75', + '74F3': '3.2', + '7443': '2.85', + '7443P': '2.85', + '7413': '2.65', + '73F3': '3.5', + '7343': '3.2', + '7313': '3.0', + '7313P': '3.0', + '72F3': '3.7', + // ZEN3 '5600X': '3.7', '5800X': '3.8', @@ -421,6 +448,7 @@ const AMDBaseFrequencies = { '5950X': '3.4' }; + const socketTypes = { 1: 'Other', 2: 'Unknown', @@ -484,6 +512,7 @@ const socketTypes = { 60: 'BGA1528', 61: 'LGA4189', 62: 'LGA1200', + 63: 'LGA4677', }; function cpuBrandManufacturer(res) { @@ -739,8 +768,8 @@ function getCpu() { const threadCount = util.getValue(lines, 'thread count').trim(); const coreCount = util.getValue(lines, 'core count').trim(); if (coreCount && threadCount) { - result.cores = threadCount; - result.physicalCores = coreCount; + result.cores = parseInt(threadCount, 10); + result.physicalCores = parseInt(coreCount, 10); } resolve(result); }); @@ -1237,7 +1266,7 @@ function cpuFlags(callback) { let flags = []; if (!error) { let parts = stdout.toString().split('\tFlags:'); - const lines = parts.length > 1 ? parts[1].split('\tVersion:')[0].split['\n'] : []; + 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) { @@ -1538,18 +1567,18 @@ function getLoad() { } result = { avgLoad: avgLoad, - currentload: _current_cpu.currentload, - currentloadUser: _current_cpu.currentloadUser, - currentloadSystem: _current_cpu.currentloadSystem, - currentloadNice: _current_cpu.currentloadNice, - currentloadIdle: _current_cpu.currentloadIdle, - currentloadIrq: _current_cpu.currentloadIrq, - rawCurrentload: _current_cpu.rawCurrentload, - rawCurrentloadUser: _current_cpu.rawCurrentloadUser, - rawCurrentloadSystem: _current_cpu.rawCurrentloadSystem, - rawCurrentloadNice: _current_cpu.rawCurrentloadNice, - rawCurrentloadIdle: _current_cpu.rawCurrentloadIdle, - rawCurrentloadIrq: _current_cpu.rawCurrentloadIrq, + currentload: _current_cpu.currentLoad, + currentloadUser: _current_cpu.currentLoadUser, + currentloadSystem: _current_cpu.currentLoadSystem, + currentloadNice: _current_cpu.currentLoadNice, + currentloadIdle: _current_cpu.currentLoadIdle, + currentloadIrq: _current_cpu.currentLoadIrq, + rawCurrentload: _current_cpu.rawCurrentLoad, + rawCurrentloadUser: _current_cpu.rawCurrentLoadUser, + rawCurrentloadSystem: _current_cpu.rawCurrentLoadSystem, + rawCurrentloadNice: _current_cpu.rawCurrentLoadNice, + rawCurrentloadIdle: _current_cpu.rawCurrentLoadIdle, + rawCurrentloadIrq: _current_cpu.rawCurrentLoadIrq, cpus: cores }; } diff --git a/lib/docker.js b/lib/docker.js index 41a8bab..6757377 100644 --- a/lib/docker.js +++ b/lib/docker.js @@ -543,7 +543,12 @@ function dockerContainerStatsSingle(containerID) { blockIO: { r: 0, w: 0 - } + }, + restartCount: 0, + cpuStats: {}, + precpuStats: {}, + memoryStats: {}, + networks: {}, }; return new Promise((resolve) => { process.nextTick(() => { diff --git a/lib/index.d.ts b/lib/index.d.ts index 3a775a3..0ab4fab 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -48,6 +48,8 @@ export namespace Systeminformation { version: string; serial: string; assetTag: string; + memMax: number | null; + memSlots: number | null; } interface ChassisData { @@ -127,14 +129,15 @@ export namespace Systeminformation { size: number; bank: string; type: string; - ecc?: boolean; - clockSpeed: number; + ecc?: boolean | null; + clockSpeed: number | null; formFactor: string; + manufacturer?: string; partNum: string; serialNum: string; - voltageConfigured: number; - voltageMin: number; - voltageMax: number; + voltageConfigured: number | null; + voltageMin: number | null; + voltageMax: number | null; } interface SmartData { @@ -360,11 +363,13 @@ export namespace Systeminformation { uefi: boolean; hypervizor?: boolean; remoteSession?: boolean; + hypervisor?: boolean; } interface UuidData { os: string; hardware: string; + macs: string[]; } interface VersionData { @@ -537,6 +542,7 @@ export namespace Systeminformation { iface: string; model: string; vendor: string; + mac: string; } interface WifiConnectionData { @@ -741,6 +747,7 @@ export namespace Systeminformation { memLimit: number; memPercent: number; cpuPercent: number; + pids: number; netIO: { rx: number; wx: number; @@ -756,6 +763,23 @@ export namespace Systeminformation { networks: any; } + interface DockerContainerProcessData { + pidHost: string; + ppid: string; + pgid: string; + user: string; + ruser: string; + group: string; + rgroup: string; + stat: string; + time: string; + elapsed: string; + nice: string; + rss: string; + vsz: string; + command: string; + } + interface DockerVolumeData { name: string; driver: string; @@ -931,7 +955,7 @@ export function dockerInfo(cb?: (data: Systeminformation.DockerInfoData) => any) export function dockerImages(all?: boolean, cb?: (data: Systeminformation.DockerImageData[]) => any): Promise; export function dockerContainers(all?: boolean, cb?: (data: Systeminformation.DockerContainerData[]) => any): Promise; export function dockerContainerStats(id?: string, cb?: (data: Systeminformation.DockerContainerStatsData[]) => any): Promise; -export function dockerContainerProcesses(id?: string, cb?: (data: any) => any): Promise; +export function dockerContainerProcesses(id?: string, cb?: (data: any) => any): Promise; export function dockerVolumes(cb?: (data: Systeminformation.DockerVolumeData[]) => any): Promise; export function dockerAll(cb?: (data: any) => any): Promise; diff --git a/lib/memory.js b/lib/memory.js index 74c34e6..c23170c 100644 --- a/lib/memory.js +++ b/lib/memory.js @@ -329,9 +329,9 @@ function memLayout(callback) { manufacturer: getManufacturerLinux(util.getValue(lines, 'Manufacturer:')), partNum: util.getValue(lines, 'Part Number:'), serialNum: util.getValue(lines, 'Serial Number:'), - voltageConfigured: parseFloat(util.getValue(lines, 'Configured Voltage:') || null), - voltageMin: parseFloat(util.getValue(lines, 'Minimum Voltage:') || null), - voltageMax: parseFloat(util.getValue(lines, 'Maximum Voltage:') || null), + voltageConfigured: parseFloat(util.getValue(lines, 'Configured Voltage:')) || null, + voltageMin: parseFloat(util.getValue(lines, 'Minimum Voltage:')) || null, + voltageMax: parseFloat(util.getValue(lines, 'Maximum Voltage:'))|| null, }); } else { result.push({ @@ -384,14 +384,14 @@ function memLayout(callback) { result[0].type = version && version[2] && version[2] === '3' ? 'LPDDR4' : result[0].type; result[0].ecc = false; result[0].clockSpeed = version && version[2] && clockSpeed[version[2]] || 400; - result[0].clockSpeed = version && version[4] && version[4] === 'd' ? '500' : result[0].clockSpeed; + result[0].clockSpeed = version && version[4] && version[4] === 'd' ? 500 : result[0].clockSpeed; result[0].formFactor = 'SoC'; stdout = execSync('vcgencmd get_config sdram_freq 2>/dev/null'); lines = stdout.toString().split('\n'); let freq = parseInt(util.getValue(lines, 'sdram_freq', '=', true), 10) || 0; if (freq) { - result.clockSpeed = freq; + result[0].clockSpeed = freq; } stdout = execSync('vcgencmd measure_volts sdram_p 2>/dev/null'); @@ -469,7 +469,7 @@ function memLayout(callback) { if (size && type) { result.push({ size: size * 1024 * 1024 * 1024, - bank: 0, + bank: '0', type, ecc: false, clockSpeed: 0, diff --git a/lib/osinfo.js b/lib/osinfo.js index 08b9b1a..721a8c7 100644 --- a/lib/osinfo.js +++ b/lib/osinfo.js @@ -196,7 +196,7 @@ function osInfo(callback) { process.nextTick(() => { let result = { - platform: (_platform === 'Windows_NT' ? 'Windows' : _platform), + platform: (_platform === 'win32' ? 'Windows' : _platform), distro: 'unknown', release: 'unknown', codename: '', @@ -299,6 +299,7 @@ function osInfo(callback) { result.codename = (result.release.indexOf('10.14') > -1 ? 'macOS Mojave' : result.codename); result.codename = (result.release.indexOf('10.15') > -1 ? 'macOS Catalina' : result.codename); result.codename = (result.release.startsWith('11.') ? 'macOS Big Sur' : result.codename); + result.codename = (result.release.startsWith('12.') ? 'macOS Monterey' : result.codename); result.uefi = true; result.codepage = util.getCodepage(); if (callback) {