Added thermal support for linux and macos

This commit is contained in:
Bryan Roe 2021-01-21 12:09:49 -08:00
parent a4a6a5d44f
commit cdd5153b93
2 changed files with 90 additions and 4 deletions

View File

@ -234,17 +234,60 @@ function windows_thermals()
return (ret);
}
function linux_thermals()
{
child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.stdin.write("cat /sys/class/thermal/thermal_zone*/temp | awk '{ print $0 / 1000 }'\nexit\n");
child.waitExit();
var ret = child.stdout.str.trim().split('\n');
if (ret.length == 1 && ret[0] == '') { ret = []; }
return (ret);
}
function macos_thermals()
{
var ret = [];
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.on('data', function () { });
child.stdin.write('powermetrics --help | grep SMC\nexit\n');
child.waitExit();
if (child.stdout.str.trim() != '')
{
child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c)
{
this.str += c.toString();
var tokens = this.str.trim().split('\n');
for (var i in tokens)
{
if (tokens[i].split(' die temperature: ').length > 1)
{
ret.push(tokens[i].split(' ')[3]);
this.parent.kill();
}
}
});
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.stdin.write('powermetrics -s smc\n');
child.waitExit(5000);
}
return (ret);
}
switch(process.platform)
{
case 'linux':
module.exports = { cpuUtilization: linux_cpuUtilization, memUtilization: linux_memUtilization };
module.exports = { cpuUtilization: linux_cpuUtilization, memUtilization: linux_memUtilization, thermals: linux_thermals };
break;
case 'win32':
module.exports = { cpuUtilization: windows_cpuUtilization, memUtilization: windows_memUtilization, thermals: windows_thermals };
break;
case 'darwin':
module.exports = { cpuUtilization: macos_cpuUtilization, memUtilization: macos_memUtilization };
module.exports = { cpuUtilization: macos_cpuUtilization, memUtilization: macos_memUtilization, thermals: macos_thermals };
break;
}

View File

@ -234,17 +234,60 @@ function windows_thermals()
return (ret);
}
function linux_thermals()
{
child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.stdin.write("cat /sys/class/thermal/thermal_zone*/temp | awk '{ print $0 / 1000 }'\nexit\n");
child.waitExit();
var ret = child.stdout.str.trim().split('\n');
if (ret.length == 1 && ret[0] == '') { ret = []; }
return (ret);
}
function macos_thermals()
{
var ret = [];
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.on('data', function () { });
child.stdin.write('powermetrics --help | grep SMC\nexit\n');
child.waitExit();
if (child.stdout.str.trim() != '')
{
child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c)
{
this.str += c.toString();
var tokens = this.str.trim().split('\n');
for (var i in tokens)
{
if (tokens[i].split(' die temperature: ').length > 1)
{
ret.push(tokens[i].split(' ')[3]);
this.parent.kill();
}
}
});
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.stdin.write('powermetrics -s smc\n');
child.waitExit(5000);
}
return (ret);
}
switch(process.platform)
{
case 'linux':
module.exports = { cpuUtilization: linux_cpuUtilization, memUtilization: linux_memUtilization };
module.exports = { cpuUtilization: linux_cpuUtilization, memUtilization: linux_memUtilization, thermals: linux_thermals };
break;
case 'win32':
module.exports = { cpuUtilization: windows_cpuUtilization, memUtilization: windows_memUtilization, thermals: windows_thermals };
break;
case 'darwin':
module.exports = { cpuUtilization: macos_cpuUtilization, memUtilization: macos_memUtilization };
module.exports = { cpuUtilization: macos_cpuUtilization, memUtilization: macos_memUtilization, thermals: macos_thermals };
break;
}