diff --git a/agents/modules_meshcmd/sysinfo.js b/agents/modules_meshcmd/sysinfo.js index e6a1cdff..bb157ba3 100644 --- a/agents/modules_meshcmd/sysinfo.js +++ b/agents/modules_meshcmd/sysinfo.js @@ -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; } diff --git a/agents/modules_meshcore/sysinfo.js b/agents/modules_meshcore/sysinfo.js index e6a1cdff..bb157ba3 100644 --- a/agents/modules_meshcore/sysinfo.js +++ b/agents/modules_meshcore/sysinfo.js @@ -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; }