MagicMirror/js/utils.js

35 lines
1.6 KiB
JavaScript
Raw Normal View History

/* MagicMirror²
2017-02-28 01:41:21 -03:00
* Utils
*
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
* MIT Licensed.
*/
const execSync = require("node:child_process").execSync;
2021-01-05 18:37:01 +01:00
const colors = require("colors/safe");
Add systeminfo (#3331) This is a first attempt to bring additional system information into the console (see #3328). It's certainly not yet perfect, but with the PR we have a better basis for discussion. I tried to keep the output small so that we get as much information as possible in screenshots. This is how it looks on my development system. ```bash [03.01.2024 00:50.19.226] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; raspberry: undefined; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12 ### VERSIONS: MagicMirror: 2.27.0-develop; electron: 27.2.0; kernel: 5.10.0-20-amd64; node: 21.1.0; npm: 10.2.4; pm2: 5.3.0; docker: 20.10.24+dfsg1 ``` Why is it still a draft: - [x] I have doubts that utils.js is the right place for the function. What do you think? => Update: As long as there is no better idea, it stays there. - [x] Instead of working through all wishes you expressed in the issue #3328, I only implemented what was easy to achieve. And wanted to hear what you think about this approach. => Update: Some added. Of course, more information could be added later, as soon as experience has been gained in productive use. - [x] I don't quite like the introductory line ("The following lines provide information..."). Should I perhaps simply replace it with "System information:"? => Update: Changed to "System information:" [Here](https://github.com/sebhildebrandt/systeminformation#function-reference-and-os-support) you can see what information we could easily add with the systeminformation package. It would be interesting how the raspberry field is filled on a raspi system and with docker there should be another line, but I can't easily test that now.
2024-01-04 22:38:53 +01:00
const Log = require("logger");
const si = require("systeminformation");
2017-02-28 01:41:21 -03:00
2021-01-05 18:37:01 +01:00
module.exports = {
2017-02-28 01:41:21 -03:00
colors: {
warn: colors.yellow,
error: colors.red,
info: colors.blue,
pass: colors.green
Add systeminfo (#3331) This is a first attempt to bring additional system information into the console (see #3328). It's certainly not yet perfect, but with the PR we have a better basis for discussion. I tried to keep the output small so that we get as much information as possible in screenshots. This is how it looks on my development system. ```bash [03.01.2024 00:50.19.226] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; raspberry: undefined; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12 ### VERSIONS: MagicMirror: 2.27.0-develop; electron: 27.2.0; kernel: 5.10.0-20-amd64; node: 21.1.0; npm: 10.2.4; pm2: 5.3.0; docker: 20.10.24+dfsg1 ``` Why is it still a draft: - [x] I have doubts that utils.js is the right place for the function. What do you think? => Update: As long as there is no better idea, it stays there. - [x] Instead of working through all wishes you expressed in the issue #3328, I only implemented what was easy to achieve. And wanted to hear what you think about this approach. => Update: Some added. Of course, more information could be added later, as soon as experience has been gained in productive use. - [x] I don't quite like the introductory line ("The following lines provide information..."). Should I perhaps simply replace it with "System information:"? => Update: Changed to "System information:" [Here](https://github.com/sebhildebrandt/systeminformation#function-reference-and-os-support) you can see what information we could easily add with the systeminformation package. It would be interesting how the raspberry field is filled on a raspi system and with docker there should be another line, but I can't easily test that now.
2024-01-04 22:38:53 +01:00
},
async logSystemInformation () {
try {
Update system information (#3337) - Add ELECTRON_ENABLE_GPU - Remove docker version - Differentiation between installed and used node version - Highlight "Ready to go!" for server mode (Since we display system information in the console, it is easy to overlook this important line.) ## Electron mode ### Before ```bash [07.01.2024 16:37.30.591] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; raspberry: undefined; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 ### VERSIONS: electron: 27.2.0; node: 18.17.1; npm: 10.2.4; pm2: 5.3.0; docker: 20.10.24+dfsg1 ### OTHER: timeZone: Europe/Berlin ``` ### After ```bash [07.01.2024 16:39.04.736] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; raspberry: undefined; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 ### VERSIONS: electron: 27.2.0; used node: 18.17.1; installed node: 21.1.0; npm: 10.2.4; pm2: 5.3.0 ### OTHER: timeZone: Europe/Berlin; ELECTRON_ENABLE_GPU: undefined ``` ## server mode ### Before ```bash [07.01.2024 16:36.49.106] [LOG] Ready to go! Please point your browser to: http://localhost:8080 [07.01.2024 16:36.49.287] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; raspberry: undefined; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 ### VERSIONS: electron: undefined; node: 21.1.0; npm: 10.2.4; pm2: 5.3.0; docker: 20.10.24+dfsg1 ### OTHER: timeZone: Europe/Berlin ``` ### After ```bash [2024-01-07 16:33:53.804] [INFO] >>> Ready to go! Please point your browser to: http://localhost:8080 <<< [2024-01-07 16:33:53.997] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; raspberry: undefined; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 ### VERSIONS: electron: undefined; used node: 21.1.0; installed node: 21.1.0; npm: 10.2.4; pm2: 5.3.0 ### OTHER: timeZone: Europe/Berlin; ELECTRON_ENABLE_GPU: undefined ```
2024-01-07 17:28:17 +01:00
let installedNodeVersion = execSync("node -v", { encoding: "utf-8" }).replace("v", "").replace(/(?:\r\n|\r|\n)/g, "");
Add systeminfo (#3331) This is a first attempt to bring additional system information into the console (see #3328). It's certainly not yet perfect, but with the PR we have a better basis for discussion. I tried to keep the output small so that we get as much information as possible in screenshots. This is how it looks on my development system. ```bash [03.01.2024 00:50.19.226] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; raspberry: undefined; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12 ### VERSIONS: MagicMirror: 2.27.0-develop; electron: 27.2.0; kernel: 5.10.0-20-amd64; node: 21.1.0; npm: 10.2.4; pm2: 5.3.0; docker: 20.10.24+dfsg1 ``` Why is it still a draft: - [x] I have doubts that utils.js is the right place for the function. What do you think? => Update: As long as there is no better idea, it stays there. - [x] Instead of working through all wishes you expressed in the issue #3328, I only implemented what was easy to achieve. And wanted to hear what you think about this approach. => Update: Some added. Of course, more information could be added later, as soon as experience has been gained in productive use. - [x] I don't quite like the introductory line ("The following lines provide information..."). Should I perhaps simply replace it with "System information:"? => Update: Changed to "System information:" [Here](https://github.com/sebhildebrandt/systeminformation#function-reference-and-os-support) you can see what information we could easily add with the systeminformation package. It would be interesting how the raspberry field is filled on a raspi system and with docker there should be another line, but I can't easily test that now.
2024-01-04 22:38:53 +01:00
const staticData = await si.getStaticData();
let systemDataString = "System information:";
Update system information (#3337) - Add ELECTRON_ENABLE_GPU - Remove docker version - Differentiation between installed and used node version - Highlight "Ready to go!" for server mode (Since we display system information in the console, it is easy to overlook this important line.) ## Electron mode ### Before ```bash [07.01.2024 16:37.30.591] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; raspberry: undefined; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 ### VERSIONS: electron: 27.2.0; node: 18.17.1; npm: 10.2.4; pm2: 5.3.0; docker: 20.10.24+dfsg1 ### OTHER: timeZone: Europe/Berlin ``` ### After ```bash [07.01.2024 16:39.04.736] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; raspberry: undefined; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 ### VERSIONS: electron: 27.2.0; used node: 18.17.1; installed node: 21.1.0; npm: 10.2.4; pm2: 5.3.0 ### OTHER: timeZone: Europe/Berlin; ELECTRON_ENABLE_GPU: undefined ``` ## server mode ### Before ```bash [07.01.2024 16:36.49.106] [LOG] Ready to go! Please point your browser to: http://localhost:8080 [07.01.2024 16:36.49.287] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; raspberry: undefined; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 ### VERSIONS: electron: undefined; node: 21.1.0; npm: 10.2.4; pm2: 5.3.0; docker: 20.10.24+dfsg1 ### OTHER: timeZone: Europe/Berlin ``` ### After ```bash [2024-01-07 16:33:53.804] [INFO] >>> Ready to go! Please point your browser to: http://localhost:8080 <<< [2024-01-07 16:33:53.997] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; raspberry: undefined; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 ### VERSIONS: electron: undefined; used node: 21.1.0; installed node: 21.1.0; npm: 10.2.4; pm2: 5.3.0 ### OTHER: timeZone: Europe/Berlin; ELECTRON_ENABLE_GPU: undefined ```
2024-01-07 17:28:17 +01:00
systemDataString += `\n### SYSTEM: manufacturer: ${staticData["system"]["manufacturer"]}; model: ${staticData["system"]["model"]}; raspberry: ${staticData["system"]["raspberry"]}; virtual: ${staticData["system"]["virtual"]}`;
systemDataString += `\n### OS: platform: ${staticData["os"]["platform"]}; distro: ${staticData["os"]["distro"]}; release: ${staticData["os"]["release"]}; arch: ${staticData["os"]["arch"]}; kernel: ${staticData["versions"]["kernel"]}`;
systemDataString += `\n### VERSIONS: electron: ${process.versions.electron}; used node: ${staticData["versions"]["node"]}; installed node: ${installedNodeVersion}; npm: ${staticData["versions"]["npm"]}; pm2: ${staticData["versions"]["pm2"]}`;
systemDataString += `\n### OTHER: timeZone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}; ELECTRON_ENABLE_GPU: ${process.env.ELECTRON_ENABLE_GPU}`;
Add systeminfo (#3331) This is a first attempt to bring additional system information into the console (see #3328). It's certainly not yet perfect, but with the PR we have a better basis for discussion. I tried to keep the output small so that we get as much information as possible in screenshots. This is how it looks on my development system. ```bash [03.01.2024 00:50.19.226] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; raspberry: undefined; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12 ### VERSIONS: MagicMirror: 2.27.0-develop; electron: 27.2.0; kernel: 5.10.0-20-amd64; node: 21.1.0; npm: 10.2.4; pm2: 5.3.0; docker: 20.10.24+dfsg1 ``` Why is it still a draft: - [x] I have doubts that utils.js is the right place for the function. What do you think? => Update: As long as there is no better idea, it stays there. - [x] Instead of working through all wishes you expressed in the issue #3328, I only implemented what was easy to achieve. And wanted to hear what you think about this approach. => Update: Some added. Of course, more information could be added later, as soon as experience has been gained in productive use. - [x] I don't quite like the introductory line ("The following lines provide information..."). Should I perhaps simply replace it with "System information:"? => Update: Changed to "System information:" [Here](https://github.com/sebhildebrandt/systeminformation#function-reference-and-os-support) you can see what information we could easily add with the systeminformation package. It would be interesting how the raspberry field is filled on a raspi system and with docker there should be another line, but I can't easily test that now.
2024-01-04 22:38:53 +01:00
Log.info(systemDataString);
} catch (e) {
Log.error(e);
}
2017-02-28 01:41:21 -03:00
}
};