Convert resources widget to systeminformation dependency

Update resources.js
pull/1084/head
shamoon 1 year ago
parent bffda3240a
commit d4a3ba84e9

@ -23,7 +23,6 @@
"minecraft-ping-js": "^1.0.2", "minecraft-ping-js": "^1.0.2",
"next": "^12.3.1", "next": "^12.3.1",
"next-i18next": "^12.0.1", "next-i18next": "^12.0.1",
"node-os-utils": "^1.3.7",
"pretty-bytes": "^6.0.0", "pretty-bytes": "^6.0.0",
"raw-body": "^2.5.1", "raw-body": "^2.5.1",
"react": "^18.2.0", "react": "^18.2.0",
@ -32,6 +31,7 @@
"react-icons": "^4.4.0", "react-icons": "^4.4.0",
"shvl": "^3.0.0", "shvl": "^3.0.0",
"swr": "^1.3.0", "swr": "^1.3.0",
"systeminformation": "^5.17.12",
"tough-cookie": "^4.1.2", "tough-cookie": "^4.1.2",
"winston": "^3.8.2", "winston": "^3.8.2",
"xml-js": "^1.6.11" "xml-js": "^1.6.11"

@ -25,7 +25,6 @@ specifiers:
minecraft-ping-js: ^1.0.2 minecraft-ping-js: ^1.0.2
next: ^12.3.1 next: ^12.3.1
next-i18next: ^12.0.1 next-i18next: ^12.0.1
node-os-utils: ^1.3.7
postcss: ^8.4.16 postcss: ^8.4.16
prettier: ^2.7.1 prettier: ^2.7.1
pretty-bytes: ^6.0.0 pretty-bytes: ^6.0.0
@ -36,6 +35,7 @@ specifiers:
react-icons: ^4.4.0 react-icons: ^4.4.0
shvl: ^3.0.0 shvl: ^3.0.0
swr: ^1.3.0 swr: ^1.3.0
systeminformation: ^5.17.12
tailwind-scrollbar: ^2.0.1 tailwind-scrollbar: ^2.0.1
tailwindcss: ^3.1.8 tailwindcss: ^3.1.8
tough-cookie: ^4.1.2 tough-cookie: ^4.1.2
@ -57,7 +57,6 @@ dependencies:
minecraft-ping-js: 1.0.2 minecraft-ping-js: 1.0.2
next: 12.3.1_biqbaboplfbrettd7655fr4n2y next: 12.3.1_biqbaboplfbrettd7655fr4n2y
next-i18next: 12.0.1_azq6kxkn3od7qdylwkyksrwopy next-i18next: 12.0.1_azq6kxkn3od7qdylwkyksrwopy
node-os-utils: 1.3.7
pretty-bytes: 6.0.0 pretty-bytes: 6.0.0
raw-body: 2.5.1 raw-body: 2.5.1
react: 18.2.0 react: 18.2.0
@ -66,6 +65,7 @@ dependencies:
react-icons: 4.4.0_react@18.2.0 react-icons: 4.4.0_react@18.2.0
shvl: 3.0.0 shvl: 3.0.0
swr: 1.3.0_react@18.2.0 swr: 1.3.0_react@18.2.0
systeminformation: 5.17.12
tough-cookie: 4.1.2 tough-cookie: 4.1.2
winston: 3.8.2 winston: 3.8.2
xml-js: 1.6.11 xml-js: 1.6.11
@ -2301,10 +2301,6 @@ packages:
resolution: {integrity: sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==} resolution: {integrity: sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==}
dev: false dev: false
/node-os-utils/1.3.7:
resolution: {integrity: sha512-fvnX9tZbR7WfCG5BAy3yO/nCLyjVWD6MghEq0z5FDfN+ZXpLWNITBdbifxQkQ25ebr16G0N7eRWJisOcMEHG3Q==}
dev: false
/node-releases/2.0.6: /node-releases/2.0.6:
resolution: {integrity: sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg==} resolution: {integrity: sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg==}
dev: true dev: true
@ -3063,6 +3059,13 @@ packages:
react: 18.2.0 react: 18.2.0
dev: false 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: /tailwind-scrollbar/2.0.1_tailwindcss@3.1.8:
resolution: {integrity: sha512-OcR7qHBbux4k+k6bWqnEQFYFooLK/F4dhkBz6nvswIoaA9ancZ5h20e0tyV7ifSWLDCUBtpG+1NHRA8HMRH/wg==} resolution: {integrity: sha512-OcR7qHBbux4k+k6bWqnEQFYFooLK/F4dhkBz6nvswIoaA9ancZ5h20e0tyV7ifSWLDCUBtpG+1NHRA8HMRH/wg==}
engines: {node: '>=12.13.0'} engines: {node: '>=12.13.0'}

@ -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 ( return (
<div className="flex-none flex flex-row items-center mr-3 py-1.5"> <div className="flex-none flex flex-row items-center mr-3 py-1.5">
<FiHardDrive className="text-theme-800 dark:text-theme-200 w-5 h-5" /> <FiHardDrive className="text-theme-800 dark:text-theme-200 w-5 h-5" />
<div className="flex flex-col ml-3 text-left min-w-[85px]"> <div className="flex flex-col ml-3 text-left min-w-[85px]">
<span className="text-theme-800 dark:text-theme-200 text-xs flex flex-row justify-between"> <span className="text-theme-800 dark:text-theme-200 text-xs flex flex-row justify-between">
<div className="pl-0.5 pr-1">{t("common.bytes", { value: data.drive.freeGb * 1024 * 1024 * 1024 })}</div> <div className="pl-0.5 pr-1">{t("common.bytes", { value: data.drive.available })}</div>
<div className="pr-1">{t("resources.free")}</div> <div className="pr-1">{t("resources.free")}</div>
</span> </span>
{expanded && ( {expanded && (
<span className="text-theme-800 dark:text-theme-200 text-xs flex flex-row justify-between"> <span className="text-theme-800 dark:text-theme-200 text-xs flex flex-row justify-between">
<div className="pl-0.5 pr-1">{t("common.bytes", { value: data.drive.totalGb * 1024 * 1024 * 1024 })}</div> <div className="pl-0.5 pr-1">{t("common.bytes", { value: data.drive.size })}</div>
<div className="pr-1">{t("resources.total")}</div> <div className="pr-1">{t("resources.total")}</div>
</span> </span>
)} )}

@ -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 ( return (
<div className="flex-none flex flex-row items-center mr-3 py-1.5"> <div className="flex-none flex flex-row items-center mr-3 py-1.5">
@ -52,7 +52,7 @@ export default function Memory({ expanded }) {
<div className="flex flex-col ml-3 text-left min-w-[85px]"> <div className="flex flex-col ml-3 text-left min-w-[85px]">
<span className="text-theme-800 dark:text-theme-200 text-xs flex flex-row justify-between"> <span className="text-theme-800 dark:text-theme-200 text-xs flex flex-row justify-between">
<div className="pl-0.5 pr-1"> <div className="pl-0.5 pr-1">
{t("common.bytes", { value: data.memory.freeMemMb * 1024 * 1024, maximumFractionDigits: 1, binary: true })} {t("common.bytes", { value: data.memory.free, maximumFractionDigits: 1, binary: true })}
</div> </div>
<div className="pr-1">{t("resources.free")}</div> <div className="pr-1">{t("resources.free")}</div>
</span> </span>
@ -60,7 +60,7 @@ export default function Memory({ expanded }) {
<span className="text-theme-800 dark:text-theme-200 text-xs flex flex-row justify-between"> <span className="text-theme-800 dark:text-theme-200 text-xs flex flex-row justify-between">
<div className="pl-0.5 pr-1"> <div className="pl-0.5 pr-1">
{t("common.bytes", { {t("common.bytes", {
value: data.memory.totalMemMb * 1024 * 1024, value: data.memory.total,
maximumFractionDigits: 1, maximumFractionDigits: 1,
binary: true, binary: true,
})} })}

@ -1,15 +1,16 @@
import { existsSync } from "fs"; import { existsSync } from "fs";
import { cpu, drive, mem } from "node-os-utils"; const si = require('systeminformation');
export default async function handler(req, res) { export default async function handler(req, res) {
const { type, target } = req.query; const { type, target } = req.query;
if (type === "cpu") { if (type === "cpu") {
const load = await si.currentLoad();
return res.status(200).json({ return res.status(200).json({
cpu: { cpu: {
usage: await cpu.usage(1000), usage: load.currentLoad,
load: cpu.loadavgTime(5), load: load.avgLoad,
}, },
}); });
} }
@ -21,14 +22,16 @@ export default async function handler(req, res) {
}); });
} }
const fsSize = await si.fsSize();
return res.status(200).json({ 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") { if (type === "memory") {
return res.status(200).json({ return res.status(200).json({
memory: await mem.info(), memory: await si.mem(),
}); });
} }

Loading…
Cancel
Save