git problem
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
const os = require('os');
|
||||
const diskusage = require('diskusage-ng');
|
||||
const { physicalCpuCount } = require('physical-cpu-count');
|
||||
const { formatBytes } = require("./util/convutil")
|
||||
|
||||
// 获取操作系统信息
|
||||
function getOSInfo() {
|
||||
return {
|
||||
type: os.type(),
|
||||
platform: os.platform(),
|
||||
release: os.release(),
|
||||
arch: os.arch()
|
||||
};
|
||||
}
|
||||
|
||||
// 获取 CPU 信息
|
||||
function getCPUInfo() {
|
||||
const cpus = os.cpus();
|
||||
return {
|
||||
model: cpus[0].model,
|
||||
speed: cpus[0].speed,
|
||||
cores: cpus.length,
|
||||
physicalCores: physicalCpuCount
|
||||
};
|
||||
}
|
||||
|
||||
// 获取内存信息
|
||||
function getMemoryInfo() {
|
||||
let info = {
|
||||
totalSize: os.totalmem(),
|
||||
freeSize: os.freemem()
|
||||
}
|
||||
|
||||
return Object.assign(info, {
|
||||
total : formatBytes(info.totalSize),
|
||||
free : formatBytes(info.freeSize),
|
||||
});
|
||||
}
|
||||
|
||||
// 获取硬盘信息
|
||||
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 = getOSInfo();
|
||||
const cpuInfo = getCPUInfo();
|
||||
const memoryInfo = getMemoryInfo();
|
||||
const diskInfo = await getDiskInfo();
|
||||
|
||||
return {
|
||||
os: osInfo,
|
||||
cpu: cpuInfo,
|
||||
memory: memoryInfo,
|
||||
disk: diskInfo
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getOSInfo,
|
||||
getCPUInfo,
|
||||
getMemoryInfo,
|
||||
getDiskInfo,
|
||||
getAllDeviceInfo
|
||||
};
|
||||
Reference in New Issue
Block a user