✨ 客户端支持交换内存状态回传
This commit is contained in:
parent
0e252abc4f
commit
0c328e96e3
59
client/app/lib/swap.js
Normal file
59
client/app/lib/swap.js
Normal 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
|
@ -1,4 +1,5 @@
|
|||||||
const osu = require('node-os-utils')
|
const osu = require('node-os-utils')
|
||||||
|
const osSwap = require('../lib/swap')
|
||||||
const os = require('os')
|
const os = require('os')
|
||||||
|
|
||||||
let cpu = osu.cpu
|
let cpu = osu.cpu
|
||||||
@ -9,7 +10,7 @@ let osuOs = osu.os
|
|||||||
let users = osu.users
|
let users = osu.users
|
||||||
|
|
||||||
async function cpuInfo() {
|
async function cpuInfo() {
|
||||||
let cpuUsage = await cpu.usage(200)
|
let cpuUsage = await cpu.usage(500)
|
||||||
let cpuCount = cpu.count()
|
let cpuCount = cpu.count()
|
||||||
let cpuModel = cpu.model()
|
let cpuModel = cpu.model()
|
||||||
return {
|
return {
|
||||||
@ -26,6 +27,13 @@ async function memInfo() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function swapInfo() {
|
||||||
|
let swapInfo = await osSwap()
|
||||||
|
return {
|
||||||
|
...swapInfo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function driveInfo() {
|
async function driveInfo() {
|
||||||
let driveInfo = {}
|
let driveInfo = {}
|
||||||
try {
|
try {
|
||||||
@ -71,6 +79,7 @@ module.exports = async () => {
|
|||||||
data = {
|
data = {
|
||||||
cpuInfo: await cpuInfo(),
|
cpuInfo: await cpuInfo(),
|
||||||
memInfo: await memInfo(),
|
memInfo: await memInfo(),
|
||||||
|
swapInfo: await swapInfo(),
|
||||||
driveInfo: await driveInfo(),
|
driveInfo: await driveInfo(),
|
||||||
netstatInfo: await netstatInfo(),
|
netstatInfo: await netstatInfo(),
|
||||||
osInfo: await osInfo(),
|
osInfo: await osInfo(),
|
||||||
|
@ -42,14 +42,14 @@ echo "***********************创建文件PATH***********************"
|
|||||||
mkdir -p ${FILE_PATH}
|
mkdir -p ${FILE_PATH}
|
||||||
|
|
||||||
echo "***********************下载开始***********************"
|
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)
|
ARCH=$(uname -m)
|
||||||
|
|
||||||
if [ "$ARCH" = "x86_64" ] ; then
|
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
|
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
|
else
|
||||||
echo "未知的架构:$ARCH"
|
echo "未知的架构:$ARCH"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "easynode-client",
|
"name": "easynode-client",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"description": "easynode-client",
|
"description": "easynode-client",
|
||||||
"bin": "./bin/www",
|
"bin": "./bin/www",
|
||||||
"pkg": {
|
"pkg": {
|
||||||
@ -8,9 +8,9 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"client": "nodemon ./app/main.js",
|
"client": "nodemon ./app/main.js",
|
||||||
"pkg": "pkg .",
|
"pkgwin": "pkg . -t node16-win-x64",
|
||||||
"pkglinux:x86": "pkg . -t node18-linux-x64",
|
"pkglinux:x86": "pkg . -t node16-linux-x64 -o dist/easynode-client-x86",
|
||||||
"pkglinux:arm": "pkg . -t node18"
|
"pkglinux:arm": "pkg . -t node16-linux-arm64 -o dist/easynode-client-arm64"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
|
@ -35,12 +35,14 @@ async function addHost({
|
|||||||
name, host: newHost, index, expired, expiredNotify, group, consoleUrl, remark,
|
name, host: newHost, index, expired, expiredNotify, group, consoleUrl, remark,
|
||||||
port, username, authType, password, privateKey, credential, command
|
port, username, authType, password, privateKey, credential, command
|
||||||
}
|
}
|
||||||
const clearTempKey = await RSADecryptSync(tempKey)
|
if (record[authType]) {
|
||||||
console.log('clearTempKey:', clearTempKey)
|
const clearTempKey = await RSADecryptSync(tempKey)
|
||||||
const clearSSHKey = await AESDecryptSync(record[authType], clearTempKey)
|
console.log('clearTempKey:', clearTempKey)
|
||||||
console.log(`${ authType }原密文: `, clearSSHKey)
|
const clearSSHKey = await AESDecryptSync(record[authType], clearTempKey)
|
||||||
record[authType] = await AESEncryptSync(clearSSHKey)
|
console.log(`${ authType }原密文: `, clearSSHKey)
|
||||||
console.log(`${ authType }__commonKey加密存储: `, record[authType])
|
record[authType] = await AESEncryptSync(clearSSHKey)
|
||||||
|
console.log(`${ authType }__commonKey加密存储: `, record[authType])
|
||||||
|
}
|
||||||
hostList.push(record)
|
hostList.push(record)
|
||||||
await writeHostList(hostList)
|
await writeHostList(hostList)
|
||||||
res.success()
|
res.success()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user