首页 > 解决方案 > 获取 Windows 和 Nodejs 上的 CPU 使用百分比

问题描述

我正在尝试获取 Windows 中的处理器使用百分比,我目前有以下代码:

const usage = process.cpuUsage();
const currentCPUUsage = (usage.user + usage.system) * 1000;
const percentCpu = currentCPUUsage / total * 100;
console.log(`El totoal: ${total}, cpu_user: ${usage.user}, cpu_system: ${usage.system}`)

但它并没有给我带来总百分比,我希望得到 Windows 任务管理器中显示的百分比。 在此处输入图像描述

知道我能做什么吗?

谢谢。

标签: node.jsperformancemonitoring

解决方案


推荐阅读