add hover title to temps and more sensors (#5434)

* add hover title to temperatures Signed-off-by: Simon Smith <simonsmith5521@gmail.com> * fix temp trim Signed-off-by: Simon Smith <simonsmith5521@gmail.com> * add extra linux sensors Signed-off-by: Simon Smith <simonsmith5521@gmail.com> * add padding for temps on multi lines Signed-off-by: Simon Smith <simonsmith5521@gmail.com> --------- Signed-off-by: Simon Smith <simonsmith5521@gmail.com>

Simon Smith committed Oct 21, 2023 at 01:30 UTC 58580beb96b1a8e20ad1c5ddd7e94993b6dbcd24
3 files changed +38 -10
agents/modules_meshcore/sysinfo.js
+36 -9
@@ -225,17 +225,23 @@ function macos_memUtilization()
225 function windows_thermals()
226 {
227 var ret = [];
228 - child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', '/namespace:\\\\root\\wmi', 'PATH', 'MSAcpi_ThermalZoneTemperature', 'get', 'CurrentTemperature']);
228 + child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', '/namespace:\\\\root\\wmi', 'PATH', 'MSAcpi_ThermalZoneTemperature', 'get', 'CurrentTemperature,InstanceName', '/FORMAT:CSV']);
229 child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
230 child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
231 child.waitExit();
232 -
233 - if(child.stdout.str.trim!='')
232 + if(child.stdout.str.trim()!='')
233 {
234 var lines = child.stdout.str.trim().split('\r\n');
235 + var keys = lines[0].trim().split(',');
236 for (var i = 1; i < lines.length; ++i)
237 {
238 - if (lines[i].trim() != '') { ret.push(((parseFloat(lines[i]) / 10) - 273.15).toFixed(2)); }
238 + var obj = {};
239 + var tokens = lines[i].trim().split(',');
240 + for (var key = 0; key < keys.length; ++key)
241 + {
242 + if (tokens[key]) { obj[keys[key]] = key==1 ? ((parseFloat(tokens[key]) / 10) - 273.15).toFixed(2) : tokens[key]; }
243 + }
244 + ret.push(obj);
245 }
246 }
247 return (ret);
@@ -243,13 +249,35 @@ function windows_thermals()
249
250 function linux_thermals()
251 {
252 + var ret = [];
253 + child = require('child_process').execFile('/bin/sh', ['sh']);
254 + child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
255 + child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
256 + child.stdin.write("for folder in /sys/class/thermal/thermal_zone*/; do [ -e \"$folder/temp\" ] && echo \"$(cat \"$folder/temp\"),$(cat \"$folder/type\")\"; done\nexit\n");
257 + child.waitExit();
258 + if(child.stdout.str.trim()!='')
259 + {
260 + var lines = child.stdout.str.trim().split('\n');
261 + for (var i = 0; i < lines.length; ++i)
262 + {
263 + var line = lines[i].trim().split(',');
264 + ret.push({CurrentTemperature: (parseFloat(line[0])/1000), InstanceName: line[1]});
265 + }
266 + }
267 child = require('child_process').execFile('/bin/sh', ['sh']);
268 child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
269 child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
249 - child.stdin.write("cat /sys/class/thermal/thermal_zone*/temp | awk '{ print $0 / 1000 }'\nexit\n");
270 + child.stdin.write("for mon in /sys/class/hwmon/hwmon*; do for label in \"$mon\"/temp*_label; do if [ -f $label ]; then echo $(cat \"$label\")___$(cat \"${label%_*}_input\"); fi; done; done;\nexit\n");
271 child.waitExit();
251 - var ret = child.stdout.str.trim().split('\n');
252 - if (ret.length == 1 && ret[0] == '') { ret = []; }
272 + if(child.stdout.str.trim()!='')
273 + {
274 + var lines = child.stdout.str.trim().split('\n');
275 + for (var i = 0; i < lines.length; ++i)
276 + {
277 + var line = lines[i].trim().split('___');
278 + ret.push({ CurrentTemperature: (parseFloat(line[1])/1000), InstanceName: line[0] });
279 + }
280 + }
281 return (ret);
282 }
283
@@ -261,7 +289,6 @@ function macos_thermals()
289 child.stderr.on('data', function () { });
290 child.stdin.write('powermetrics --help | grep SMC\nexit\n');
291 child.waitExit();
264 -
292 if (child.stdout.str.trim() != '')
293 {
294 child = require('child_process').execFile('/bin/sh', ['sh']);
@@ -273,7 +300,7 @@ function macos_thermals()
300 {
301 if (tokens[i].split(' die temperature: ').length > 1)
302 {
276 - ret.push(tokens[i].split(' ')[3]);
303 + ret.push({CurrentTemperature: tokens[i].split(' ')[3], InstanceName: tokens[i].split(' ')[0]});
304 this.parent.kill();
305 }
306 }
public/styles/style.css
+1
@@ -3202,6 +3202,7 @@ a {
3202 background-color: gold;
3203 margin-right: 6px;
3204 border-radius: 4px;
3205 + margin-bottom: 5px;
3206 }
3207
3208 .night .thermalSensor {
views/default.handlebars
+1 -1
@@ -11518,7 +11518,7 @@
11518 if (message != null) {
11519 if (Array.isArray(message.thermals) && (message.thermals.length > 0)) {
11520 var x = '&nbsp;';
11521 - for (var i in message.thermals) { x += '<div class=thermalSensor>' + parseFloat(message.thermals[i]).toFixed(2) + '&deg;C / ' + parseFloat((message.thermals[i] * 1.8) + 32).toFixed(2) + '&deg;F' + '</div>'; }
11521 + for (var i in message.thermals) { x += '<div class=thermalSensor title="'+message.thermals[i].InstanceName+'">' + parseFloat(message.thermals[i].CurrentTemperature).toFixed(2) + '&deg;C / ' + parseFloat((message.thermals[i].CurrentTemperature * 1.8) + 32).toFixed(2) + '&deg;F' + '</div>'; }
11522 QV('extraGraphValues', true);
11523 QH('extraGraphValues', x);
11524 }