Skip to content

Commit

Permalink
✨ 客户端支持交换内存状态回传
Browse files Browse the repository at this point in the history
  • Loading branch information
chaos-zhu committed Aug 14, 2024
1 parent 0e252ab commit 0c328e9
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 14 deletions.
59 changes: 59 additions & 0 deletions client/app/lib/swap.js
Original file line number Diff line number Diff line change
@@ -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
11 changes: 10 additions & 1 deletion client/app/utils/os-data.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const osu = require('node-os-utils')
const osSwap = require('../lib/swap')
const os = require('os')

let cpu = osu.cpu
Expand All @@ -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 {
Expand All @@ -26,6 +27,13 @@ async function memInfo() {
}
}

async function swapInfo() {
let swapInfo = await osSwap()
return {
...swapInfo
}
}

async function driveInfo() {
let driveInfo = {}
try {
Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions client/easynode-client-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "easynode-client",
"version": "1.0.0",
"version": "1.0.1",
"description": "easynode-client",
"bin": "./bin/www",
"pkg": {
"outputPath": "dist"
},
"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": "",
Expand Down
14 changes: 8 additions & 6 deletions server/app/controller/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0c328e9

Please sign in to comment.