Added windows thermals

Bryan Roe committed Jan 20, 2021 at 14:38 UTC 78f48a7692c948875aae72d0d3d189c27dd42021
3 files changed +72 -14
agents/meshcore.js
+21 -3
@@ -1001,7 +1001,19 @@ function createMeshCore(agent) {
1001 var cpuuse = require('sysinfo').cpuUtilization();
1002 cpuuse.sessionid = data.sessionid;
1003 cpuuse.tag = data.tag;
1004 - cpuuse.then(function (data) { mesh.SendCommand(JSON.stringify({ action: 'msg', type: 'cpuinfo', cpu: data, memory: require('sysinfo').memUtilization(), sessionid: this.sessionid, tag: this.tag })); }, function (ex) { });
1004 + cpuuse.then(function (data)
1005 + {
1006 + mesh.SendCommand(JSON.stringify(
1007 + {
1008 + action: 'msg',
1009 + type: 'cpuinfo',
1010 + cpu: data,
1011 + memory: require('sysinfo').memUtilization(),
1012 + thermals: require('sysinfo').thermals==null?[]:require('sysinfo').thermals(),
1013 + sessionid: this.sessionid,
1014 + tag: this.tag
1015 + }));
1016 + }, function (ex) { });
1017 break;
1018 case 'localapp':
1019 // Send a message to a local application
@@ -3266,8 +3278,14 @@ function createMeshCore(agent) {
3278 // CPU & memory utilization
3279 pr = require('sysinfo').cpuUtilization();
3280 pr.sessionid = sessionid;
3269 - pr.then(function (data) {
3270 - sendConsoleText(JSON.stringify({ cpu: data, memory: require('sysinfo').memUtilization() }, null, 1), this.sessionid);
3281 + pr.then(function (data)
3282 + {
3283 + sendConsoleText(JSON.stringify(
3284 + {
3285 + cpu: data,
3286 + memory: require('sysinfo').memUtilization(),
3287 + thermals: require('sysinfo').thermals == null ? [] : require('sysinfo').thermals()
3288 + }, null, 1), this.sessionid);
3289 }, function (e) {
3290 sendConsoleText(e);
3291 });
agents/modules_meshcmd/sysinfo.js
+30 -10
@@ -72,11 +72,11 @@ function windows_cpuUtilization()
72 szName = item.Deref(0, GM.PointerSize).Deref();
73 if (szName.String == '_Total')
74 {
75 - u.total = item.Deref(16, 8).toBuffer().readDoubleLE().toFixed(2);
75 + u.total = item.Deref(16, 8).toBuffer().readDoubleLE();
76 }
77 else
78 {
79 - u.cpus[parseInt(szName.String)] = item.Deref(16, 8).toBuffer().readDoubleLE().toFixed(2);
79 + u.cpus[parseInt(szName.String)] = item.Deref(16, 8).toBuffer().readDoubleLE();
80 }
81 }
82
@@ -99,8 +99,8 @@ function windows_memUtilization()
99 MemFree: require('bignum').fromBuffer(info.Deref(16, 8).toBuffer(), { endian: 'little' })
100 };
101
102 - ret.percentFree = ((ret.MemFree.div(require('bignum')('1048576')).toNumber() / ret.MemTotal.div(require('bignum')('1048576')).toNumber()) * 100).toFixed(2);
103 - ret.percentConsumed = ((ret.MemTotal.sub(ret.MemFree).div(require('bignum')('1048576')).toNumber() / ret.MemTotal.div(require('bignum')('1048576')).toNumber()) * 100).toFixed(2);
102 + ret.percentFree = ((ret.MemFree.div(require('bignum')('1048576')).toNumber() / ret.MemTotal.div(require('bignum')('1048576')).toNumber()) * 100);//.toFixed(2);
103 + ret.percentConsumed = ((ret.MemTotal.sub(ret.MemFree).div(require('bignum')('1048576')).toNumber() / ret.MemTotal.div(require('bignum')('1048576')).toNumber()) * 100);//.toFixed(2);
104 ret.MemTotal = ret.MemTotal.toString();
105 ret.MemFree = ret.MemFree.toString();
106 return (ret);
@@ -123,7 +123,7 @@ function linux_cpuUtilization()
123 while (columns[++x] == '');
124 for (y = x; y < columns.length; ++y) { sum += parseInt(columns[y]); }
125 idle = parseInt(columns[3 + x]);
126 - utilization = (100 - ((idle / sum) * 100)).toFixed(2);
126 + utilization = (100 - ((idle / sum) * 100)); //.toFixed(2);
127 if (!ret.total)
128 {
129 ret.total = utilization;
@@ -157,8 +157,8 @@ function linux_memUtilization()
157 break;
158 }
159 }
160 - ret.percentFree = ((ret.free / ret.total) * 100).toFixed(2);
161 - ret.percentConsumed = (((ret.total - ret.free) / ret.total) * 100).toFixed(2);
160 + ret.percentFree = ((ret.free / ret.total) * 100);//.toFixed(2);
161 + ret.percentConsumed = (((ret.total - ret.free) / ret.total) * 100);//.toFixed(2);
162 return (ret);
163 }
164
@@ -205,8 +205,8 @@ function macos_memUtilization()
205
206 mem.MemTotal = parseInt(bdown[0].trim().split(' ')[0]);
207 mem.MemFree = parseInt(bdown[1].trim().split(' ')[0]);
208 - mem.percentFree = ((mem.MemFree / mem.MemTotal) * 100).toFixed(2);
209 - mem.percentConsumed = (((mem.MemTotal - mem.MemFree)/ mem.MemTotal) * 100).toFixed(2);
208 + mem.percentFree = ((mem.MemFree / mem.MemTotal) * 100);//.toFixed(2);
209 + mem.percentConsumed = (((mem.MemTotal - mem.MemFree) / mem.MemTotal) * 100);//.toFixed(2);
210 return (mem);
211 }
212 else
@@ -215,13 +215,33 @@ function macos_memUtilization()
215 }
216 }
217
218 +function windows_thermals()
219 +{
220 + var ret = [];
221 + child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', '/namespace:\\\\root\\wmi', 'PATH', 'MSAcpi_ThermalZoneTemperature', 'get', 'CurrentTemperature']);
222 + child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
223 + child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
224 + child.waitExit();
225 +
226 + if(child.stdout.str.trim!='')
227 + {
228 + var lines = child.stdout.str.trim().split('\r\n');
229 + for (var i = 1; i < lines.length; ++i)
230 + {
231 + if (lines[i].trim() != '') { ret.push(((parseFloat(lines[i]) / 10) - 273.15).toFixed(2)); }
232 + }
233 + }
234 + return (ret);
235 +}
236 +
237 +
238 switch(process.platform)
239 {
240 case 'linux':
241 module.exports = { cpuUtilization: linux_cpuUtilization, memUtilization: linux_memUtilization };
242 break;
243 case 'win32':
224 - module.exports = { cpuUtilization: windows_cpuUtilization, memUtilization: windows_memUtilization };
244 + module.exports = { cpuUtilization: windows_cpuUtilization, memUtilization: windows_memUtilization, thermals: windows_thermals };
245 break;
246 case 'darwin':
247 module.exports = { cpuUtilization: macos_cpuUtilization, memUtilization: macos_memUtilization };
agents/modules_meshcore/sysinfo.js
+21 -1
@@ -215,13 +215,33 @@ function macos_memUtilization()
215 }
216 }
217
218 +function windows_thermals()
219 +{
220 + var ret = [];
221 + child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', '/namespace:\\\\root\\wmi', 'PATH', 'MSAcpi_ThermalZoneTemperature', 'get', 'CurrentTemperature']);
222 + child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
223 + child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
224 + child.waitExit();
225 +
226 + if(child.stdout.str.trim!='')
227 + {
228 + var lines = child.stdout.str.trim().split('\r\n');
229 + for (var i = 1; i < lines.length; ++i)
230 + {
231 + if (lines[i].trim() != '') { ret.push(((parseFloat(lines[i]) / 10) - 273.15).toFixed(2)); }
232 + }
233 + }
234 + return (ret);
235 +}
236 +
237 +
238 switch(process.platform)
239 {
240 case 'linux':
241 module.exports = { cpuUtilization: linux_cpuUtilization, memUtilization: linux_memUtilization };
242 break;
243 case 'win32':
224 - module.exports = { cpuUtilization: windows_cpuUtilization, memUtilization: windows_memUtilization };
244 + module.exports = { cpuUtilization: windows_cpuUtilization, memUtilization: windows_memUtilization, thermals: windows_thermals };
245 break;
246 case 'darwin':
247 module.exports = { cpuUtilization: macos_cpuUtilization, memUtilization: macos_memUtilization };