Commit 02450efe authored by Alexandra Rogova's avatar Alexandra Rogova

added systeminformation package

parent 43bb64f8
......@@ -17,6 +17,7 @@ if (!(args.saveAs === "metadata" ||args.saveAs === "attachment")){
var saveAs = args.saveAs;
var browser;
var Server = require('ws').Server;
var port = 9030;
var ws = new Server({port: port});
......@@ -35,6 +36,10 @@ var ws = new Server({port: port});
});
(async () => {
const used = process.memoryUsage();
for (let key in used) {
console.log(`${key} ${Math.round(used[key] / 1024 / 1024 * 100) / 100} MB`);
}
browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://softinst115787.host.vifib.net/public/unit_tests/index_load.html?saveAs='+saveAs);
......@@ -43,8 +48,4 @@ var ws = new Server({port: port});
page.click('input#load')
]);
await fileChooser.accept([args.file]);
const used = process.memoryUsage();
for (let key in used) {
console.log(`${key} ${Math.round(used[key] / 1024 / 1024 * 100) / 100} MB`);
}
})();
This diff is collapsed.
The MIT License (MIT)
Copyright (c) 2014-2019 Sebastian Hildebrandt
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This diff is collapsed.
'use strict';
// @ts-check;
// ==================================================================================
// battery.js
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2019
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
// ==================================================================================
// 6. Battery
// ----------------------------------------------------------------------------------
const exec = require('child_process').exec;
const fs = require('fs');
const util = require('./util');
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 _netbsd = (_platform === 'netbsd');
const _sunos = (_platform === 'sunos');
module.exports = function (callback) {
return new Promise((resolve) => {
process.nextTick(() => {
let result = {
hasbattery: false,
cyclecount: 0,
ischarging: false,
maxcapacity: 0,
currentcapacity: 0,
percent: 0,
timeremaining: -1,
acconnected: true,
type: '',
model: '',
manufacturer: '',
serial: ''
};
if (_linux) {
let battery_path = '';
if (fs.existsSync('/sys/class/power_supply/BAT1/uevent')) {
battery_path = '/sys/class/power_supply/BAT1/';
} else if (fs.existsSync('/sys/class/power_supply/BAT0/uevent')) {
battery_path = '/sys/class/power_supply/BAT0/';
}
if (battery_path) {
exec('cat ' + battery_path + 'uevent', function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
result.ischarging = (util.getValue(lines, 'POWER_SUPPLY_STATUS', '=').toLowerCase() === 'charging');
result.acconnected = result.ischarging;
result.cyclecount = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CYCLE_COUNT', '='), 10);
result.maxcapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL', '='), 10);
if (!result.maxcapacity) {
result.maxcapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL', '='), 10);
}
result.currentcapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_NOW', '='), 10);
if (!result.currentcapacity) {
result.currentcapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_NOW', '='), 10);
}
const percent = util.getValue(lines, 'POWER_SUPPLY_CAPACITY', '=');
const energy = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_NOW', '='), 10);
const power = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_POWER_NOW', '='), 10);
const current = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CURRENT_NOW', '='), 10);
result.percent = parseInt('0' + percent, 10);
if (result.maxcapacity && result.currentcapacity) {
result.hasbattery = true;
if (!percent) {
result.percent = 100.0 * result.currentcapacity / result.maxcapacity;
}
}
if (result.ischarging) {
result.hasbattery = true;
}
if (energy && power) {
result.timeremaining = Math.floor(energy / power * 60);
} else if (current && result.currentcapacity) {
result.timeremaining = Math.floor(result.currentcapacity / current * 60);
}
result.type = util.getValue(lines, 'POWER_SUPPLY_TECHNOLOGY', '=');
result.model = util.getValue(lines, 'POWER_SUPPLY_MODEL_NAME', '=');
result.manufacturer = util.getValue(lines, 'POWER_SUPPLY_MANUFACTURER', '=');
result.serial = util.getValue(lines, 'POWER_SUPPLY_SERIAL_NUMBER', '=');
if (callback) { callback(result); }
resolve(result);
}
});
} else {
if (callback) { callback(result); }
resolve(result);
}
}
if (_freebsd || _openbsd || _netbsd) {
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.acconnected = result.ischarging;
result.maxcapacity = -1;
result.currentcapacity = -1;
result.percent = batteries ? percent : -1;
if (callback) { callback(result); }
resolve(result);
});
}
if (_darwin) {
exec('ioreg -n AppleSmartBattery -r | egrep "CycleCount|IsCharging|MaxCapacity|CurrentCapacity|BatterySerialNumber|TimeRemaining"; pmset -g batt | grep %', function (error, stdout) {
if (stdout) {
let lines = stdout.toString().replace(/ +/g, '').replace(/"+/g, '').replace(/-/g, '').split('\n');
result.cyclecount = parseInt('0' + util.getValue(lines, 'cyclecount', '='), 10);
result.maxcapacity = parseInt('0' + util.getValue(lines, 'maxcapacity', '='), 10);
result.currentcapacity = parseInt('0' + util.getValue(lines, 'currentcapacity', '='), 10);
result.manufacturer = 'Apple';
result.serial = util.getValue(lines, 'BatterySerialNumber', '=');
let percent = -1;
const line = util.getValue(lines, 'internal', 'Battery');
let parts = line.split(';');
if (parts && parts[0]) {
let parts2 = parts[0].split('\t');
if (parts2 && parts2[1]) {
percent = parseFloat(parts2[1].trim().replace(/%/g, ''));
}
}
if (parts && parts[1]) {
result.ischarging = (parts[1].trim() === 'charging');
result.acconnected = (parts[1].trim() !== 'discharging');
} else {
result.ischarging = util.getValue(lines, 'ischarging', '=').toLowerCase() === 'yes';
result.acconnected = result.ischarging;
}
if (result.maxcapacity && result.currentcapacity) {
result.hasbattery = true;
result.type = 'Li-ion';
result.percent = percent !== -1 ? percent : Math.round(100.0 * result.currentcapacity / result.maxcapacity);
if (!result.ischarging) {
result.timeremaining = parseInt('0' + util.getValue(lines, 'TimeRemaining', '='), 10);
}
}
}
if (callback) { callback(result); }
resolve(result);
});
}
if (_sunos) {
if (callback) { callback(result); }
resolve(result);
}
if (_windows) {
try {
util.wmic('Path Win32_Battery Get BatteryStatus, DesignCapacity, EstimatedChargeRemaining /value').then((stdout) => {
if (stdout) {
let lines = stdout.split('\r\n');
let status = util.getValue(lines, 'BatteryStatus', '=').trim();
// 1 = "Discharging"
// 2 = "On A/C"
// 3 = "Fully Charged"
// 4 = "Low"
// 5 = "Critical"
// 6 = "Charging"
// 7 = "Charging High"
// 8 = "Charging Low"
// 9 = "Charging Critical"
// 10 = "Undefined"
// 11 = "Partially Charged"
if (status && status != '10') {
const statusValue = parseInt(status);
result.hasbattery = true;
result.maxcapacity = parseInt(util.getValue(lines, 'DesignCapacity', '=') || 0);
result.percent = parseInt(util.getValue(lines, 'EstimatedChargeRemaining', '=') || 0);
result.currentcapacity = parseInt(result.maxcapacity * result.percent / 100);
result.ischarging = (statusValue >= 6 && statusValue <= 9) || statusValue === 11 || (!(statusValue === 3) && !(statusValue === 1) && result.percent < 100);
result.acconnected = result.ischarging || statusValue === 2;
}
}
if (callback) { callback(result); }
resolve(result);
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
}
}
});
});
};
This diff is collapsed.
This diff is collapsed.
'use strict';
// @ts-check
// ==================================================================================
// dockerSockets.js
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2019
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
// ==================================================================================
// 13. DockerSockets
// ----------------------------------------------------------------------------------
const net = require('net');
const isWin = require('os').type() === 'Windows_NT';
const socketPath = isWin ? '//./pipe/docker_engine' : '/var/run/docker.sock';
class DockerSocket {
getInfo(callback) {
try {
let socket = net.createConnection({ path: socketPath });
let alldata = '';
let data;
socket.on('connect', () => {
socket.write('GET http:/info HTTP/1.0\r\n\r\n');
});
socket.on('data', data => {
alldata = alldata + data.toString();
});
socket.on('error', () => {
socket = false;
callback({});
});
socket.on('end', () => {
let startbody = alldata.indexOf('\r\n\r\n');
alldata = alldata.substring(startbody + 4);
socket = false;
try {
data = JSON.parse(alldata);
callback(data);
} catch (err) {
callback({});
}
});
} catch (err) {
callback({});
}
}
listContainers(all, callback) {
try {
let socket = net.createConnection({ path: socketPath });
let alldata = '';
let data;
socket.on('connect', () => {
socket.write('GET http:/containers/json' + (all ? '?all=1' : '') + ' HTTP/1.0\r\n\r\n');
});
socket.on('data', data => {
alldata = alldata + data.toString();
});
socket.on('error', () => {
socket = false;
callback({});
});
socket.on('end', () => {
let startbody = alldata.indexOf('\r\n\r\n');
alldata = alldata.substring(startbody + 4);
socket = false;
try {
data = JSON.parse(alldata);
callback(data);
} catch (err) {
callback({});
}
});
} catch (err) {
callback({});
}
}
getStats(id, callback) {
id = id || '';
if (id) {
try {
let socket = net.createConnection({ path: socketPath });
let alldata = '';
let data;
socket.on('connect', () => {
socket.write('GET http:/containers/' + id + '/stats?stream=0 HTTP/1.0\r\n\r\n');
});
socket.on('data', data => {
alldata = alldata + data.toString();
});
socket.on('error', () => {
socket = false;
callback({});
});
socket.on('end', () => {
let startbody = alldata.indexOf('\r\n\r\n');
alldata = alldata.substring(startbody + 4);
socket = false;
try {
data = JSON.parse(alldata);
callback(data);
} catch (err) {
callback({});
}
});
} catch (err) {
callback({});
}
} else {
callback({});
}
}
getInspect(id, callback) {
id = id || '';
if (id) {
try {
let socket = net.createConnection({ path: socketPath });
let alldata = '';
let data;
socket.on('connect', () => {
socket.write('GET http:/containers/' + id + '/json?stream=0 HTTP/1.0\r\n\r\n');
});
socket.on('data', data => {
alldata = alldata + data.toString();
});
socket.on('error', () => {
socket = false;
callback({});
});
socket.on('end', () => {
let startbody = alldata.indexOf('\r\n\r\n');
alldata = alldata.substring(startbody + 4);
socket = false;
try {
data = JSON.parse(alldata);
callback(data);
} catch (err) {
callback({});
}
});
} catch (err) {
callback({});
}
} else {
callback({});
}
}
getProcesses(id, callback) {
id = id || '';
if (id) {
try {
let socket = net.createConnection({ path: socketPath });
let alldata = '';
let data;
socket.on('connect', () => {
socket.write('GET http:/containers/' + id + '/top?ps_args=-opid,ppid,pgid,vsz,time,etime,nice,ruser,user,rgroup,group,stat,rss,args HTTP/1.0\r\n\r\n');
});
socket.on('data', data => {
alldata = alldata + data.toString();
});
socket.on('error', () => {
socket = false;
callback({});
});
socket.on('end', () => {
let startbody = alldata.indexOf('\r\n\r\n');
alldata = alldata.substring(startbody + 4);
socket = false;
try {
data = JSON.parse(alldata);
callback(data);
} catch (err) {
callback({});
}
});
} catch (err) {
callback({});
}
} else {
callback({});
}
}
}
module.exports = DockerSocket;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
'use strict';
// @ts-check
// ==================================================================================
// virtualbox.js
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2019
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
// ==================================================================================
// 14. Docker
// ----------------------------------------------------------------------------------
const os = require('os');
const exec = require('child_process').exec;
const util = require('./util');
function vboxInfo(callback) {
// fallback - if only callback is given
let result = [];
return new Promise((resolve) => {
process.nextTick(() => {
try {
exec(util.getVboxmanage() + ' list vms --long', function (error, stdout) {
let parts = (os.EOL + stdout.toString()).split(os.EOL + 'Name:');
parts.shift();
parts.forEach(part => {
const lines = ('Name:' + part).split(os.EOL);
const state = util.getValue(lines, 'State');
const running = state.startsWith('running');
const runningSinceString = running ? state.replace('running (since ', '').replace(')', '').trim() : '';
let runningSince = 0;
try {
if (running) {
const sinceDateObj = new Date(runningSinceString);
const offset = sinceDateObj.getTimezoneOffset();
runningSince = Math.round((Date.now() - Date.parse(sinceDateObj)) / 1000) + offset * 60;
}
} catch (e) {
util.noop();
}
const stoppedSinceString = !running ? state.replace('powered off (since', '').replace(')', '').trim() : '';
let stoppedSince = 0;
try {
if (!running) {
const sinceDateObj = new Date(stoppedSinceString);
const offset = sinceDateObj.getTimezoneOffset();
stoppedSince = Math.round((Date.now() - Date.parse(sinceDateObj)) / 1000) + offset * 60;
}
} catch (e) {
util.noop();
}
result.push({
id: util.getValue(lines, 'UUID'),
name: util.getValue(lines, 'Name'),
running,
started: runningSinceString,
runningSince,
stopped: stoppedSinceString,
stoppedSince,
guestOS: util.getValue(lines, 'Guest OS'),
hardwareUUID: util.getValue(lines, 'Hardware UUID'),
memory: parseInt(util.getValue(lines, 'Memory size', ' '), 10),
vram: parseInt(util.getValue(lines, 'VRAM size'), 10),
cpus: parseInt(util.getValue(lines, 'Number of CPUs'), 10),
cpuExepCap: util.getValue(lines, 'CPU exec cap'),
cpuProfile: util.getValue(lines, 'CPUProfile'),
chipset: util.getValue(lines, 'Chipset'),
firmware: util.getValue(lines, 'Firmware'),
pageFusion: util.getValue(lines, 'Page Fusion') === 'enabled',
configFile: util.getValue(lines, 'Config file'),
snapshotFolder: util.getValue(lines, 'Snapshot folder'),
logFolder: util.getValue(lines, 'Log folder'),
HPET: util.getValue(lines, 'HPET') === 'enabled',
PAE: util.getValue(lines, 'PAE') === 'enabled',
longMode: util.getValue(lines, 'Long Mode') === 'enabled',
tripleFaultReset: util.getValue(lines, 'Triple Fault Reset') === 'enabled',
APIC: util.getValue(lines, 'APIC') === 'enabled',
X2APIC: util.getValue(lines, 'X2APIC') === 'enabled',
ACPI: util.getValue(lines, 'ACPI') === 'enabled',
IOAPIC: util.getValue(lines, 'IOAPIC') === 'enabled',
biosAPICmode: util.getValue(lines, 'BIOS APIC mode'),
bootMenuMode: util.getValue(lines, 'Boot menu mode'),
bootDevice1: util.getValue(lines, 'Boot Device 1'),
bootDevice2: util.getValue(lines, 'Boot Device 2'),
bootDevice3: util.getValue(lines, 'Boot Device 3'),
bootDevice4: util.getValue(lines, 'Boot Device 4'),
timeOffset: util.getValue(lines, 'Time offset'),
RTC: util.getValue(lines, 'RTC'),
});
});
if (callback) { callback(result); }
resolve(result);
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
}
});
});
}
exports.vboxInfo = vboxInfo;
This diff is collapsed.
This diff is collapsed.
......@@ -417,6 +417,11 @@
"ansi-regex": "^4.1.0"
}
},
"systeminformation": {
"version": "4.14.11",
"resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-4.14.11.tgz",
"integrity": "sha512-KlMaQQftyGUPjKzGRrATN5mpKrpdtrVk/KPuqPeu733bUgpokIhevg5zjKOb4Gur91XKdbdQCCja/oFsg5R4Dw=="
},
"typedarray": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment