From 0c328e96e341c90547753d23f9578da5ee799d53 Mon Sep 17 00:00:00 2001 From: chaos-zhu Date: Wed, 14 Aug 2024 10:52:07 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=AE=A2=E6=88=B7=E7=AB=AF?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BA=A4=E6=8D=A2=E5=86=85=E5=AD=98=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=9B=9E=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/app/lib/swap.js | 59 +++++++++++++++++++++++++++++++ client/app/utils/os-data.js | 11 +++++- client/easynode-client-install.sh | 6 ++-- client/package.json | 8 ++--- server/app/controller/host.js | 14 ++++---- 5 files changed, 84 insertions(+), 14 deletions(-) create mode 100644 client/app/lib/swap.js diff --git a/client/app/lib/swap.js b/client/app/lib/swap.js new file mode 100644 index 0000000..79c3696 --- /dev/null +++ b/client/app/lib/swap.js @@ -0,0 +1,59 @@ +let exec = require('child_process').exec +let os = require('os') + +function getSwapMemory() { + return new Promise((resolve, reject) => { + if (os.platform() === 'win32') { + // Windows-specific command + const command = 'powershell -command "Get-CimInstance Win32_OperatingSystem | Select-Object TotalVirtualMemorySize, FreeVirtualMemory"' + exec(command, { encoding: 'utf8' }, (error, stdout, stderr) => { + if (error) { + console.error('exec error:', error) + return reject(error) + } + if (stderr) { + console.error('stderr:', stderr) + return reject(stderr) + } + + const lines = stdout.trim().split('\n') + const values = lines[lines.length - 1].trim().split(/\s+/) + const totalVirtualMemory = parseInt(values[0], 10) / 1024 + const freeVirtualMemory = parseInt(values[1], 10) / 1024 + const usedVirtualMemory = totalVirtualMemory - freeVirtualMemory + + resolve({ + swapTotal: totalVirtualMemory, + swapFree: freeVirtualMemory, + swapUsed: usedVirtualMemory, + swapPercentage: ((usedVirtualMemory / totalVirtualMemory) * 100).toFixed(1) + }) + }) + } else { + exec('free -m | grep Swap', (error, stdout, stderr) => { + if (error) { + console.error('exec error:', error) + return reject(error) + } + if (stderr) { + console.error('stderr:', stderr) + return reject(stderr) + } + + const swapInfo = stdout.trim().split(/\s+/) + const swapTotal = parseInt(swapInfo[1], 10) + const swapUsed = parseInt(swapInfo[2], 10) + const swapFree = parseInt(swapInfo[3], 10) + + resolve({ + swapTotal, + swapUsed, + swapFree, + swapPercentage: ((swapUsed / swapTotal) * 100).toFixed(1) + }) + }) + } + }) +} + +module.exports = getSwapMemory \ No newline at end of file diff --git a/client/app/utils/os-data.js b/client/app/utils/os-data.js index 2c0491f..cd83631 100644 --- a/client/app/utils/os-data.js +++ b/client/app/utils/os-data.js @@ -1,4 +1,5 @@ const osu = require('node-os-utils') +const osSwap = require('../lib/swap') const os = require('os') let cpu = osu.cpu @@ -9,7 +10,7 @@ let osuOs = osu.os let users = osu.users async function cpuInfo() { - let cpuUsage = await cpu.usage(200) + let cpuUsage = await cpu.usage(500) let cpuCount = cpu.count() let cpuModel = cpu.model() return { @@ -26,6 +27,13 @@ async function memInfo() { } } +async function swapInfo() { + let swapInfo = await osSwap() + return { + ...swapInfo + } +} + async function driveInfo() { let driveInfo = {} try { @@ -71,6 +79,7 @@ module.exports = async () => { data = { cpuInfo: await cpuInfo(), memInfo: await memInfo(), + swapInfo: await swapInfo(), driveInfo: await driveInfo(), netstatInfo: await netstatInfo(), osInfo: await osInfo(), diff --git a/client/easynode-client-install.sh b/client/easynode-client-install.sh index 90d4bb4..57e0f6c 100644 --- a/client/easynode-client-install.sh +++ b/client/easynode-client-install.sh @@ -42,14 +42,14 @@ echo "***********************创建文件PATH***********************" mkdir -p ${FILE_PATH} echo "***********************下载开始***********************" -DOWNLOAD_SERVICE_URL="https://mirror.ghproxy.com/https://github.com/chaos-zhu/easynode/releases/download/v2.0.0/easynode-client.service" +DOWNLOAD_SERVICE_URL="https://mirror.ghproxy.com/https://github.com/chaos-zhu/easynode/releases/download/v2.1.7/easynode-client.service" ARCH=$(uname -m) if [ "$ARCH" = "x86_64" ] ; then - DOWNLOAD_FILE_URL="https://mirror.ghproxy.com/https://github.com/chaos-zhu/easynode/releases/download/v2.0.0/easynode-client-x86" + DOWNLOAD_FILE_URL="https://mirror.ghproxy.com/https://github.com/chaos-zhu/easynode/releases/download/v2.1.7/easynode-client-x86" elif [ "$ARCH" = "aarch64" ] ; then - DOWNLOAD_FILE_URL="https://mirror.ghproxy.com/https://github.com/chaos-zhu/easynode/releases/download/v2.0.0/easynode-client-arm64" + DOWNLOAD_FILE_URL="https://mirror.ghproxy.com/https://github.com/chaos-zhu/easynode/releases/download/v2.1.7/easynode-client-arm64" else echo "未知的架构:$ARCH" exit 1 diff --git a/client/package.json b/client/package.json index cc7b586..f1d4def 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "easynode-client", - "version": "1.0.0", + "version": "1.0.1", "description": "easynode-client", "bin": "./bin/www", "pkg": { @@ -8,9 +8,9 @@ }, "scripts": { "client": "nodemon ./app/main.js", - "pkg": "pkg .", - "pkglinux:x86": "pkg . -t node18-linux-x64", - "pkglinux:arm": "pkg . -t node18" + "pkgwin": "pkg . -t node16-win-x64", + "pkglinux:x86": "pkg . -t node16-linux-x64 -o dist/easynode-client-x86", + "pkglinux:arm": "pkg . -t node16-linux-arm64 -o dist/easynode-client-arm64" }, "keywords": [], "author": "", diff --git a/server/app/controller/host.js b/server/app/controller/host.js index 7f2d971..ccf8f8f 100644 --- a/server/app/controller/host.js +++ b/server/app/controller/host.js @@ -35,12 +35,14 @@ async function addHost({ name, host: newHost, index, expired, expiredNotify, group, consoleUrl, remark, port, username, authType, password, privateKey, credential, command } - const clearTempKey = await RSADecryptSync(tempKey) - console.log('clearTempKey:', clearTempKey) - const clearSSHKey = await AESDecryptSync(record[authType], clearTempKey) - console.log(`${ authType }原密文: `, clearSSHKey) - record[authType] = await AESEncryptSync(clearSSHKey) - console.log(`${ authType }__commonKey加密存储: `, record[authType]) + if (record[authType]) { + const clearTempKey = await RSADecryptSync(tempKey) + console.log('clearTempKey:', clearTempKey) + const clearSSHKey = await AESDecryptSync(record[authType], clearTempKey) + console.log(`${ authType }原密文: `, clearSSHKey) + record[authType] = await AESEncryptSync(clearSSHKey) + console.log(`${ authType }__commonKey加密存储: `, record[authType]) + } hostList.push(record) await writeHostList(hostList) res.success()