Added thermal support for linux and macos
Bryan Roe committed
Jan 21, 2021 at 12:09 UTC
cdd5153b939553f00bcf17a234f27d1f70fd02eb
2 files changed
+90
-4
agents/modules_meshcmd/sysinfo.js
+45
-2
@@ -234,17 +234,60 @@ function windows_thermals()
234
return (ret);
235
}
236
237
+function linux_thermals()
238
+{
239
+ child = require('child_process').execFile('/bin/sh', ['sh']);
240
+ child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
241
+ child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
242
+ child.stdin.write("cat /sys/class/thermal/thermal_zone*/temp | awk '{ print $0 / 1000 }'\nexit\n");
243
+ child.waitExit();
244
+ var ret = child.stdout.str.trim().split('\n');
245
+ if (ret.length == 1 && ret[0] == '') { ret = []; }
246
+ return (ret);
247
+}
248
+
249
+function macos_thermals()
250
+{
251
+ var ret = [];
252
+ var child = require('child_process').execFile('/bin/sh', ['sh']);
253
+ child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
254
+ child.stderr.on('data', function () { });
255
+ child.stdin.write('powermetrics --help | grep SMC\nexit\n');
256
+ child.waitExit();
257
+
258
+ if (child.stdout.str.trim() != '')
259
+ {
260
+ child = require('child_process').execFile('/bin/sh', ['sh']);
261
+ child.stdout.str = ''; child.stdout.on('data', function (c)
262
+ {
263
+ this.str += c.toString();
264
+ var tokens = this.str.trim().split('\n');
265
+ for (var i in tokens)
266
+ {
267
+ if (tokens[i].split(' die temperature: ').length > 1)
268
+ {
269
+ ret.push(tokens[i].split(' ')[3]);
270
+ this.parent.kill();
271
+ }
272
+ }
273
+ });
274
+ child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
275
+ child.stdin.write('powermetrics -s smc\n');
276
+ child.waitExit(5000);
277
+ }
278
+ return (ret);
279
+}
280
281
switch(process.platform)
282
{
283
case 'linux':
241
- module.exports = { cpuUtilization: linux_cpuUtilization, memUtilization: linux_memUtilization };
284
+ module.exports = { cpuUtilization: linux_cpuUtilization, memUtilization: linux_memUtilization, thermals: linux_thermals };
285
break;
286
case 'win32':
287
module.exports = { cpuUtilization: windows_cpuUtilization, memUtilization: windows_memUtilization, thermals: windows_thermals };
288
break;
289
case 'darwin':
247
- module.exports = { cpuUtilization: macos_cpuUtilization, memUtilization: macos_memUtilization };
290
+ module.exports = { cpuUtilization: macos_cpuUtilization, memUtilization: macos_memUtilization, thermals: macos_thermals };
291
break;
292
}
293
agents/modules_meshcore/sysinfo.js
+45
-2
@@ -234,17 +234,60 @@ function windows_thermals()
234
return (ret);
235
}
236
237
+function linux_thermals()
238
+{
239
+ child = require('child_process').execFile('/bin/sh', ['sh']);
240
+ child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
241
+ child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
242
+ child.stdin.write("cat /sys/class/thermal/thermal_zone*/temp | awk '{ print $0 / 1000 }'\nexit\n");
243
+ child.waitExit();
244
+ var ret = child.stdout.str.trim().split('\n');
245
+ if (ret.length == 1 && ret[0] == '') { ret = []; }
246
+ return (ret);
247
+}
248
+
249
+function macos_thermals()
250
+{
251
+ var ret = [];
252
+ var child = require('child_process').execFile('/bin/sh', ['sh']);
253
+ child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
254
+ child.stderr.on('data', function () { });
255
+ child.stdin.write('powermetrics --help | grep SMC\nexit\n');
256
+ child.waitExit();
257
+
258
+ if (child.stdout.str.trim() != '')
259
+ {
260
+ child = require('child_process').execFile('/bin/sh', ['sh']);
261
+ child.stdout.str = ''; child.stdout.on('data', function (c)
262
+ {
263
+ this.str += c.toString();
264
+ var tokens = this.str.trim().split('\n');
265
+ for (var i in tokens)
266
+ {
267
+ if (tokens[i].split(' die temperature: ').length > 1)
268
+ {
269
+ ret.push(tokens[i].split(' ')[3]);
270
+ this.parent.kill();
271
+ }
272
+ }
273
+ });
274
+ child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
275
+ child.stdin.write('powermetrics -s smc\n');
276
+ child.waitExit(5000);
277
+ }
278
+ return (ret);
279
+}
280
281
switch(process.platform)
282
{
283
case 'linux':
241
- module.exports = { cpuUtilization: linux_cpuUtilization, memUtilization: linux_memUtilization };
284
+ module.exports = { cpuUtilization: linux_cpuUtilization, memUtilization: linux_memUtilization, thermals: linux_thermals };
285
break;
286
case 'win32':
287
module.exports = { cpuUtilization: windows_cpuUtilization, memUtilization: windows_memUtilization, thermals: windows_thermals };
288
break;
289
case 'darwin':
247
- module.exports = { cpuUtilization: macos_cpuUtilization, memUtilization: macos_memUtilization };
290
+ module.exports = { cpuUtilization: macos_cpuUtilization, memUtilization: macos_memUtilization, thermals: macos_thermals };
291
break;
292
}
293