Skip to content

Commit

Permalink
very firet windows functions, extended processes list
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhildebrandt committed Feb 19, 2017
1 parent 26c6b72 commit b2b9f79
Show file tree
Hide file tree
Showing 10 changed files with 588 additions and 411 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Other changes

| Version | Date | Comment |
| -------------- | -------------- | -------- |
| 3.17.0 | 2017-02-19 | windows support for some first functions, extended process list (linux)|
| 3.16.0 | 2017-01-19 | blockDevices: added removable attribute + fix |
| 3.15.1 | 2017-01-17 | minor cpuTemperature fix (OSX) |
| 3.15.0 | 2017-01-15 | added cpuTemperature also for OSX |
Expand Down
444 changes: 229 additions & 215 deletions README.md

Large diffs are not rendered by default.

56 changes: 37 additions & 19 deletions lib/cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,8 @@ function cpuBrandManufacturer(res) {

function getCpu() {

return new Promise((resolve, reject) => {
return new Promise((resolve) => {
process.nextTick(() => {
if (_windows) {
let error = new Error(NOT_SUPPORTED);
if (callback) { callback(NOT_SUPPORTED) }
reject(error);
}

let result = {
manufacturer: 'unknown',
brand: 'unknown',
Expand Down Expand Up @@ -105,6 +99,20 @@ function getCpu() {
resolve(result);
})
}
if (_windows) {
exec("wmic cpu get name", function (error, stdout) {
if (!error) {
let lines = stdout.split('\r\n').filter(line => line.trim() != '').filter((line, idx) => idx > 0);
let line = (lines && lines[0]) ? lines[0] : '';
result.brand = line.split('@')[0].trim();
result.speed = line.split('@')[1].trim();
result.speed = parseFloat(result.speed.replace(/GHz+/g, ""));
_cpu_speed = result.speed;
}
result = cpuBrandManufacturer(result);
resolve(result);
})
}
});
});
}
Expand All @@ -116,12 +124,6 @@ function cpu(callback) {

return new Promise((resolve, reject) => {
process.nextTick(() => {
if (_windows) {
let error = new Error(NOT_SUPPORTED);
if (callback) { callback(NOT_SUPPORTED) }
reject(error);
}

getCpu().then(result => {
if (callback) { callback(result) }
resolve(result);
Expand Down Expand Up @@ -188,12 +190,6 @@ function cpuTemperature(callback) {

return new Promise((resolve, reject) => {
process.nextTick(() => {
if (_windows) {
let error = new Error(NOT_SUPPORTED);
if (callback) { callback(NOT_SUPPORTED) }
reject(error);
}

let result = {
main: -1.0,
cores: [],
Expand Down Expand Up @@ -280,6 +276,28 @@ function cpuTemperature(callback) {
if (callback) { callback(result) }
resolve(result);
}
if (_windows) {
exec("wmic /namespace:\\\\root\\wmi PATH MSAcpi_ThermalZoneTemperature get CriticalTripPoint,CurrentTemperature /value", function (error, stdout) {
if (!error) {
let sum = 0;
let lines = stdout.trim().split(/\s\s+/);
lines.forEach(function (line) {
if (line.match('CriticalTripPoint') && !result.max)
result.max = (parseInt(line.split('CriticalTripPoint=')[1]) - 2732) / 10;
else if (line.match('CurrentTemperature')) {
let value = (parseInt(line.split('CurrentTemperature=')[1]) - 2732) / 10;
sum = sum + value;
result.cores.push(value);
}
});
if (result.cores.length) {
result.main = sum / result.cores.length;
}
if (callback) { callback(result) }
resolve(result);
}
});
}
});
});
}
Expand Down
105 changes: 72 additions & 33 deletions lib/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,55 @@ function fsSize(callback) {

return new Promise((resolve, reject) => {
process.nextTick(() => {
if (_windows) {
let error = new Error(NOT_SUPPORTED);
if (callback) {
callback(NOT_SUPPORTED)
}
reject(error);
if (_linux || _darwin) {
let cmd = (_darwin ? "df -lkP | grep ^/" : "df -lkPT | grep ^/");
exec(cmd, function (error, stdout) {
let data = [];
if (!error) {
let lines = stdout.toString().split('\n');
//lines.splice(0, 1);
lines.forEach(function (line) {
if (line != '') {
line = line.replace(/ +/g, " ").split(' ');
data.push({
'fs': line[0],
'type': (_linux ? line[1] : 'HFS'),
'size': parseInt((_linux ? line[2] : line[1])) * 1024,
'used': parseInt((_linux ? line[3] : line[2])) * 1024,
'use': parseFloat((100.0 * (_linux ? line[3] : line[2]) / (_linux ? line[2] : line[1])).toFixed(2)),
'mount': line[line.length - 1]
})
}
});
}
if (callback) {
callback(data)
}
resolve(data);
});
}

let cmd = (_darwin ? "df -lkP | grep ^/" : "df -lkPT | grep ^/");
exec(cmd, function (error, stdout) {
let data = [];
if (!error) {
let lines = stdout.toString().split('\n');
//lines.splice(0, 1);
if (_windows) {
exec('wmic logicaldisk get Caption,FileSystem,FreeSpace,Size', function (error, stdout) {
let lines = stdout.split('\r\n').filter(line => line.trim() != '').filter((line, idx) => idx > 0);
lines.forEach(function (line) {
if (line != '') {
line = line.replace(/ +/g, " ").split(' ');
line = line.trim().split(/\s\s+/);
data.push({
'fs': line[0],
'type': (_linux ? line[1] : 'HFS'),
'size': parseInt((_linux ? line[2] : line[1])) * 1024,
'used': parseInt((_linux ? line[3] : line[2])) * 1024,
'use': parseFloat((100.0 * (_linux ? line[3] : line[2]) / (_linux ? line[2] : line[1])).toFixed(2)),
'mount': line[line.length - 1]
'type': line[1],
'size': line[3],
'used': parseInt(line[3]) - parseInt(line[2]),
'use': parseFloat((100.0 * (parseInt(line[3]) - parseInt(line[2]))) / parseInt(line[3])),
'mount': line[0]
})
}
});
}
if (callback) {
callback(data)
}
resolve(data);
});
if (callback) {
callback(data)
}
resolve(data);
});
}
});
});
}
Expand Down Expand Up @@ -179,14 +195,6 @@ function blockDevices(callback) {

return new Promise((resolve, reject) => {
process.nextTick(() => {
if (_windows) {
let error = new Error(NOT_SUPPORTED);
if (callback) {
callback(NOT_SUPPORTED)
}
reject(error);
}

if (_linux) {
// see https://wiki.ubuntuusers.de/lsblk/
// exec("lsblk -bo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,TRAN,SERIAL,LABEL,MODEL,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,SCHED,RQ-SIZE,RA,WSAME", function (error, stdout) {
Expand Down Expand Up @@ -227,6 +235,37 @@ function blockDevices(callback) {
resolve(data);
});
}
if (_windows) {
exec('wmic logicaldisk get Caption,Description,DeviceID,DriveType,FileSystem,FreeSpace,Name,Size,VolumeName,VolumeSerialNumber /format:csv', function (error, stdout) {
if (!error) {
let lines = stdout.split('\r\n').filter(line => line.trim() != '').filter((line, idx) => idx > 0);
lines.forEach(function (line) {
if (line != '') {
line = line.replace('\r', '').split(',');
data.push({
name: line[7],
identifier: line[1],
type: 'disk',
fstype: line[5].toLowerCase(),
mount: line[1],
size: line[8],
physical: line[4] == '5' ? 'CD/DVD' : 'HDD',
uuid: line[10],
label: line[9],
model: '',
serial: line[10],
removable: line[4] == '2',
protocol: ''
});
}
});
}
if (callback) {
callback(data)
}
resolve(data);
});
}
});
});
}
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
// --------------------------------
//
// version date comment
// 3.17.0 2017-02-19 windows support for some first functions
// 3.16.0 2017-01-19 blockDevices: added removable attribute + fix
// 3.15.1 2017-01-17 minor cpuTemperature fix (OSX)
// 3.15.0 2017-01-15 added cpuTemperature also for OSX
Expand Down
5 changes: 0 additions & 5 deletions lib/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ module.exports = function (callback) {

return new Promise((resolve, reject) => {
process.nextTick(() => {
if (_windows) {
let error = new Error(NOT_SUPPORTED);
if (callback) { callback(NOT_SUPPORTED) }
reject(error);
}

let result = {
total: os.totalmem(),
Expand Down

0 comments on commit b2b9f79

Please sign in to comment.