客户端支持交换内存状态回传

This commit is contained in:
chaos-zhu 2024-08-14 10:52:07 +08:00
parent 0e252abc4f
commit 0c328e96e3
5 changed files with 84 additions and 14 deletions

59
client/app/lib/swap.js Normal file
View File

@ -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

View File

@ -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(),

View File

@ -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

View File

@ -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": "",

View File

@ -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()