修正 platform 命令
This commit is contained in:
+10
-6
@@ -138,15 +138,19 @@ parser.addCmdLine("platform", "平台信息", function (cli) {
|
||||
}
|
||||
table.push({ '项' : 'Mem ' + k, '值' : info.memory[k]})
|
||||
}
|
||||
for ( let k in info.disk ){
|
||||
if ( k.endsWith("Size") ) {
|
||||
continue;
|
||||
}
|
||||
table.push({ '项' : 'Disk' + k, '值' : info.disk[k]})
|
||||
}
|
||||
|
||||
console.table(table);
|
||||
const disks = info.disk;
|
||||
disks.forEach(disk => {
|
||||
console.log(`磁盘 ${disk.mount}:`);
|
||||
console.log(` 总空间: ${(disk.size / 1024 / 1024 / 1024).toFixed(2)} GB`);
|
||||
console.log(` 已用空间: ${(disk.used / 1024 / 1024 / 1024).toFixed(2)} GB`);
|
||||
console.log(` 可用空间: ${(disk.available / 1024 / 1024 / 1024).toFixed(2)} GB`);
|
||||
console.log(` 使用率: ${disk.use}%`);
|
||||
});
|
||||
console.log( JSON.stringify(info, null, 4));
|
||||
|
||||
|
||||
}).catch(error => {
|
||||
console.error('Error getting device information:', error);
|
||||
});
|
||||
|
||||
+4
-29
@@ -1,6 +1,5 @@
|
||||
const os = require('os');
|
||||
const diskusage = require('diskusage-ng');
|
||||
const { physicalCpuCount } = require('physical-cpu-count');
|
||||
const si = require('systeminformation');
|
||||
const { formatBytes } = require("./util/convutil")
|
||||
const { exec } = require('child_process');
|
||||
const { promisify } = require('util');
|
||||
@@ -14,6 +13,7 @@ const readFilePromise = promisify(fs.readFile);
|
||||
|
||||
// 获取操作系统信息
|
||||
async function getOSInfo() {
|
||||
|
||||
return {
|
||||
type: os.type(),
|
||||
platform: os.platform(),
|
||||
@@ -26,6 +26,7 @@ async function getOSInfo() {
|
||||
// 获取 CPU 信息
|
||||
function getCPUInfo() {
|
||||
const cpus = os.cpus();
|
||||
const physicalCpuCount = require('physical-cpu-count')
|
||||
return {
|
||||
model: cpus[0].model,
|
||||
speed: cpus[0].speed,
|
||||
@@ -47,38 +48,13 @@ function getMemoryInfo() {
|
||||
});
|
||||
}
|
||||
|
||||
// 获取硬盘信息
|
||||
async function getDiskInfo() {
|
||||
try {
|
||||
const path = os.platform() === 'win32' ? 'C:' : '/';
|
||||
return new Promise(function (resolve, reject) {
|
||||
diskusage(path, function (err, usage) {
|
||||
if (err) {
|
||||
console.error('Error getting disk information:', err);
|
||||
reject(err);
|
||||
}
|
||||
resolve({
|
||||
totalSize: usage.total,
|
||||
freeSize: usage.available,
|
||||
total : formatBytes(usage.total),
|
||||
free : formatBytes(usage.available),
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error getting disk information:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 主函数,调用上述函数获取所有信息
|
||||
async function getAllDeviceInfo() {
|
||||
const osInfo = await getOSInfo();
|
||||
const cpuInfo = getCPUInfo();
|
||||
const memoryInfo = getMemoryInfo();
|
||||
const diskInfo = await getDiskInfo();
|
||||
const diskInfo = await si.fsSize();
|
||||
|
||||
return {
|
||||
os: osInfo,
|
||||
@@ -131,6 +107,5 @@ module.exports = {
|
||||
getOSInfo,
|
||||
getCPUInfo,
|
||||
getMemoryInfo,
|
||||
getDiskInfo,
|
||||
getAllDeviceInfo
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user