Skip to content

Commit 49aa650

Browse files
refactor: optimize system information logging
- feat: include MagicMirror version - refactor: use more variables to get the string array less complex - refactor: get `installedNodeVersion` from si.versions (with that it was possible to drop the import of `execSync`)
1 parent a05eb23 commit 49aa650

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

js/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ global.mmTestMode = process.env.mmTestMode === "true";
2222
Log.log(`Starting MagicMirror: v${global.version}`);
2323

2424
// Log system information.
25-
Utils.logSystemInformation();
25+
Utils.logSystemInformation(global.version);
2626

2727
// global absolute root path
2828
global.root_path = path.resolve(`${__dirname}/../`);

js/utils.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const execSync = require("node:child_process").execSync;
21
const path = require("node:path");
32

43
const rootPath = path.resolve(`${__dirname}/../`);
@@ -14,31 +13,34 @@ const discoveredPositionsJSFilename = "js/positions.js";
1413

1514
module.exports = {
1615

17-
async logSystemInformation () {
16+
async logSystemInformation (mirrorVersion) {
1817
try {
19-
let installedNodeVersion = execSync("node -v", { encoding: "utf-8" }).replace("v", "").replace(/(?:\r\n|\r|\n)/g, "");
18+
const system = await si.system();
19+
const osInfo = await si.osInfo();
20+
const versions = await si.versions();
21+
22+
const usedNodeVersion = process.version.replace("v", "");
23+
const installedNodeVersion = versions.node;
24+
const totalRam = (os.totalmem() / 1024 / 1024).toFixed(2);
25+
const freeRam = (os.freemem() / 1024 / 1024).toFixed(2);
26+
const usedRam = ((os.totalmem() - os.freemem()) / 1024 / 1024).toFixed(2);
2027

21-
const staticData = await si.get({
22-
system: "manufacturer, model, virtual",
23-
osInfo: "platform, distro, release, arch",
24-
versions: "kernel, node, npm, pm2"
25-
});
2628
let systemDataString = [
27-
"\n##### System Information #####",
28-
`- SYSTEM: manufacturer: ${staticData.system.manufacturer}; model: ${staticData.system.model}; virtual: ${staticData.system.virtual}; timeZone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}`,
29-
`- OS: platform: ${staticData.osInfo.platform}; distro: ${staticData.osInfo.distro}; release: ${staticData.osInfo.release}; arch: ${staticData.osInfo.arch}; kernel: ${staticData.versions.kernel}`,
30-
`- VERSIONS: electron: ${process.versions.electron}; used node: ${staticData.versions.node}; installed node: ${installedNodeVersion}; npm: ${staticData.versions.npm}; pm2: ${staticData.versions.pm2}`,
31-
`- ENV: XDG_SESSION_TYPE: ${process.env.XDG_SESSION_TYPE}; MM_CONFIG_FILE: ${process.env.MM_CONFIG_FILE};`,
32-
` WAYLAND_DISPLAY: ${process.env.WAYLAND_DISPLAY}; DISPLAY: ${process.env.DISPLAY}; ELECTRON_ENABLE_GPU: ${process.env.ELECTRON_ENABLE_GPU}`,
33-
`- RAM: total: ${(os.totalmem() / 1024 / 1024).toFixed(2)} MB; free: ${(os.freemem() / 1024 / 1024).toFixed(2)} MB; used: ${((os.totalmem() - os.freemem()) / 1024 / 1024).toFixed(2)} MB`,
34-
`- UPTIME: ${Math.floor(os.uptime() / 60)} minutes`
29+
"\n#### System Information ####",
30+
`- SYSTEM: manufacturer: ${system.manufacturer}; model: ${system.model}; virtual: ${system.virtual}; MM: ${mirrorVersion}`,
31+
`- OS: platform: ${osInfo.platform}; distro: ${osInfo.distro}; release: ${osInfo.release}; arch: ${osInfo.arch}; kernel: ${versions.kernel}`,
32+
`- VERSIONS: electron: ${process.versions.electron}; used node: ${usedNodeVersion}; installed node: ${installedNodeVersion}; npm: ${versions.npm}; pm2: ${versions.pm2}`,
33+
`- ENV: XDG_SESSION_TYPE: ${process.env.XDG_SESSION_TYPE}; MM_CONFIG_FILE: ${process.env.MM_CONFIG_FILE}`,
34+
` WAYLAND_DISPLAY: ${process.env.WAYLAND_DISPLAY}; DISPLAY: ${process.env.DISPLAY}; ELECTRON_ENABLE_GPU: ${process.env.ELECTRON_ENABLE_GPU}`,
35+
`- RAM: total: ${totalRam} MB; free: ${freeRam} MB; used: ${usedRam} MB`,
36+
`- OTHERS: uptime: ${Math.floor(os.uptime() / 60)} minutes; timeZone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}`
3537
].join("\n");
3638
Log.info(systemDataString);
3739

3840
// Return is currently only for jest
3941
return systemDataString;
40-
} catch (e) {
41-
Log.error(e);
42+
} catch (error) {
43+
Log.error(error);
4244
}
4345
},
4446

0 commit comments

Comments
 (0)