From d4a3ba84e93e77ba4455f1471e3b8258dabd9df4 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 5 Mar 2023 13:16:16 -0800 Subject: [PATCH] Convert resources widget to systeminformation dependency Update resources.js --- package.json | 2 +- pnpm-lock.yaml | 15 +++++++++------ src/components/widgets/resources/disk.jsx | 6 +++--- src/components/widgets/resources/memory.jsx | 6 +++--- src/pages/api/widgets/resources.js | 13 ++++++++----- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index bbe3cbf0c..f6e86adbc 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ "minecraft-ping-js": "^1.0.2", "next": "^12.3.1", "next-i18next": "^12.0.1", - "node-os-utils": "^1.3.7", "pretty-bytes": "^6.0.0", "raw-body": "^2.5.1", "react": "^18.2.0", @@ -32,6 +31,7 @@ "react-icons": "^4.4.0", "shvl": "^3.0.0", "swr": "^1.3.0", + "systeminformation": "^5.17.12", "tough-cookie": "^4.1.2", "winston": "^3.8.2", "xml-js": "^1.6.11" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a3ce3fcd8..94afa5916 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -25,7 +25,6 @@ specifiers: minecraft-ping-js: ^1.0.2 next: ^12.3.1 next-i18next: ^12.0.1 - node-os-utils: ^1.3.7 postcss: ^8.4.16 prettier: ^2.7.1 pretty-bytes: ^6.0.0 @@ -36,6 +35,7 @@ specifiers: react-icons: ^4.4.0 shvl: ^3.0.0 swr: ^1.3.0 + systeminformation: ^5.17.12 tailwind-scrollbar: ^2.0.1 tailwindcss: ^3.1.8 tough-cookie: ^4.1.2 @@ -57,7 +57,6 @@ dependencies: minecraft-ping-js: 1.0.2 next: 12.3.1_biqbaboplfbrettd7655fr4n2y next-i18next: 12.0.1_azq6kxkn3od7qdylwkyksrwopy - node-os-utils: 1.3.7 pretty-bytes: 6.0.0 raw-body: 2.5.1 react: 18.2.0 @@ -66,6 +65,7 @@ dependencies: react-icons: 4.4.0_react@18.2.0 shvl: 3.0.0 swr: 1.3.0_react@18.2.0 + systeminformation: 5.17.12 tough-cookie: 4.1.2 winston: 3.8.2 xml-js: 1.6.11 @@ -2301,10 +2301,6 @@ packages: resolution: {integrity: sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==} dev: false - /node-os-utils/1.3.7: - resolution: {integrity: sha512-fvnX9tZbR7WfCG5BAy3yO/nCLyjVWD6MghEq0z5FDfN+ZXpLWNITBdbifxQkQ25ebr16G0N7eRWJisOcMEHG3Q==} - dev: false - /node-releases/2.0.6: resolution: {integrity: sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg==} dev: true @@ -3063,6 +3059,13 @@ packages: react: 18.2.0 dev: false + /systeminformation/5.17.12: + resolution: {integrity: sha512-I3pfMW2vue53u+X08BNxaJieaHkRoMMKjWetY9lbYJeWFaeWPO6P4FkNc4XOCX8F9vbQ0HqQ25RJoz3U/B7liw==} + engines: {node: '>=8.0.0'} + os: [darwin, linux, win32, freebsd, openbsd, netbsd, sunos, android] + hasBin: true + dev: false + /tailwind-scrollbar/2.0.1_tailwindcss@3.1.8: resolution: {integrity: sha512-OcR7qHBbux4k+k6bWqnEQFYFooLK/F4dhkBz6nvswIoaA9ancZ5h20e0tyV7ifSWLDCUBtpG+1NHRA8HMRH/wg==} engines: {node: '>=12.13.0'} diff --git a/src/components/widgets/resources/disk.jsx b/src/components/widgets/resources/disk.jsx index fb770dbb1..dbc41b1cf 100644 --- a/src/components/widgets/resources/disk.jsx +++ b/src/components/widgets/resources/disk.jsx @@ -44,19 +44,19 @@ export default function Disk({ options, expanded }) { ); } - const percent = Math.round((data.drive.usedGb / data.drive.totalGb) * 100); + const percent = Math.round((data.drive.used / data.drive.size) * 100); return (
-
{t("common.bytes", { value: data.drive.freeGb * 1024 * 1024 * 1024 })}
+
{t("common.bytes", { value: data.drive.available })}
{t("resources.free")}
{expanded && ( -
{t("common.bytes", { value: data.drive.totalGb * 1024 * 1024 * 1024 })}
+
{t("common.bytes", { value: data.drive.size })}
{t("resources.total")}
)} diff --git a/src/components/widgets/resources/memory.jsx b/src/components/widgets/resources/memory.jsx index 27351998e..2ee0a15e6 100644 --- a/src/components/widgets/resources/memory.jsx +++ b/src/components/widgets/resources/memory.jsx @@ -44,7 +44,7 @@ export default function Memory({ expanded }) { ); } - const percent = Math.round((data.memory.usedMemMb / data.memory.totalMemMb) * 100); + const percent = Math.round((data.memory.used / data.memory.total) * 100); return (
@@ -52,7 +52,7 @@ export default function Memory({ expanded }) {
- {t("common.bytes", { value: data.memory.freeMemMb * 1024 * 1024, maximumFractionDigits: 1, binary: true })} + {t("common.bytes", { value: data.memory.free, maximumFractionDigits: 1, binary: true })}
{t("resources.free")}
@@ -60,7 +60,7 @@ export default function Memory({ expanded }) {
{t("common.bytes", { - value: data.memory.totalMemMb * 1024 * 1024, + value: data.memory.total, maximumFractionDigits: 1, binary: true, })} diff --git a/src/pages/api/widgets/resources.js b/src/pages/api/widgets/resources.js index baa507a4e..69bec041a 100644 --- a/src/pages/api/widgets/resources.js +++ b/src/pages/api/widgets/resources.js @@ -1,15 +1,16 @@ import { existsSync } from "fs"; -import { cpu, drive, mem } from "node-os-utils"; +const si = require('systeminformation'); export default async function handler(req, res) { const { type, target } = req.query; if (type === "cpu") { + const load = await si.currentLoad(); return res.status(200).json({ cpu: { - usage: await cpu.usage(1000), - load: cpu.loadavgTime(5), + usage: load.currentLoad, + load: load.avgLoad, }, }); } @@ -21,14 +22,16 @@ export default async function handler(req, res) { }); } + const fsSize = await si.fsSize(); + return res.status(200).json({ - drive: await drive.info(target || "/"), + drive: fsSize.find(fs => fs.mount === target) ?? fsSize.find(fs => fs.mount === "/") }); } if (type === "memory") { return res.status(200).json({ - memory: await mem.info(), + memory: await si.mem(), }); }