获取/查看内存和通过 NodeJS 使用 CPU [英] Get/View Memory & CPU usage via NodeJS
问题描述
我看到有几个节点包可以让你查找特定进程的使用情况,例如 https://www.npmjs.com/package/usage
我正在尝试获取整体服务器使用情况/统计信息(CPU 和内存),而不仅仅是某个特定进程或其他进程.甚至可能使用磁盘空间.
我目前找不到这样的东西,这可能吗?
原生模块 os可以给你一些内存和cpu使用统计.
var os = require('os');console.log(os.cpus());console.log(os.totalmem());console.log(os.freemem())
cpus() 函数为您提供平均值,但您可以使用公式和间隔计算当前使用量,如 this 答案.
还有一个包可以为您执行此操作,名为 os-utils..>
摘自github上的示例:
var os = require('os-utils');os.cpuUsage(函数(v){console.log('CPU 使用率 (%):' + v);});
有关磁盘的信息,您可以使用 diskspace
I see there are several node packages that allow you to look up a specific process's usage, such as https://www.npmjs.com/package/usage
I am trying to get the overall sever usage/stats (CPU and Memory), not just one specific process or another. Maybe even disk space usage.
I am currently unable to find anything like this, is this possible?
The native module os can give you some memory and cpu usage statistics.
var os = require('os');
console.log(os.cpus());
console.log(os.totalmem());
console.log(os.freemem())
The cpus() function gives you an average, but you can calculate the current usage by using a formula and an interval, as mentioned in this answer.
There is also a package that does this for you, called os-utils.
Taken from the example on github:
var os = require('os-utils');
os.cpuUsage(function(v){
console.log( 'CPU Usage (%): ' + v );
});
For information about the disk you can use diskspace
这篇关于获取/查看内存和通过 NodeJS 使用 CPU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!