如何在node.js中获取服务器CPU,内存和磁盘百分比
var os = require('os-utils');
os.cpuUsage(function(v){
console.log( 'os-utils CPU Usage (%): ' + v );
// os-utils CPU Usage (%): 0.11180382377389864
});
os.cpuFree(function(v){
console.log( 'os-utils CPU Free:' + v );
// os-utils CPU Free:0.8876135425268373
});
var osu = require('node-os-utils')
var cpu = osu.cpu
cpu.usage()
.then(info => {
console.log('node-os-utils cpu.usage '+info)
// node-os-utils cpu.usage 11.53
})
cpu.free()
.then(info => {
console.log('node-os-utils cpu.free '+ info)
// node-os-utils cpu.free 88.47
})
太烦人了。 为什么OS-Utils值与Node-OS-Utils值不同? 我需要当前运行node.js的服务器的CPU和磁盘内存值 - 电流CPU使用**(百分比) - 可用内存*(免费/总计) - 可用磁盘空间(免费/总计)
var os = require('os-utils');
os.cpuUsage(function(v){
console.log( 'os-utils CPU Usage (%): ' + v );
// os-utils CPU Usage (%): 0.11180382377389864
});
os.cpuFree(function(v){
console.log( 'os-utils CPU Free:' + v );
// os-utils CPU Free:0.8876135425268373
});
var osu = require('node-os-utils')
var cpu = osu.cpu
cpu.usage()
.then(info => {
console.log('node-os-utils cpu.usage '+info)
// node-os-utils cpu.usage 11.53
})
cpu.free()
.then(info => {
console.log('node-os-utils cpu.free '+ info)
// node-os-utils cpu.free 88.47
})
it's so annoying.
Why is the os-utils value different from the node-os-utils value?
I need the CPU and disk memory values of the server currently running node.js
-Current CPU usage** (percent)
-Available memory* (free/total)
-Available disk space (free/total)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎
OS-UTILS
软件包运行良好。仅给出0到1的百分比格式,含义0 => 0%
和1 => 100%
等等。关于获取磁盘空间卷信息,您可以使用软件包
diskusage
。您可以在那里查看文档 https://www.npmjs.coms.com/package/package/diskusage/diskusage
It seems like
os-utils
package works well. Just format of percentage was given from 0 to 1, meaning0 => 0%
and1 => 100%
and so on.About getting disk space volume info you can use package
diskusage
.You can check docs there https://www.npmjs.com/package/diskusage
因为一个是一个百分比(0到100之间的数字),而一个是0到1之间的数字。
(我认为多核系统可以将最大数量乘以核心数量。)
值是相同的。它们只是以非常不同的术语表示。
Because one is a percentage (a number between 0 and 100) and one is a number between 0 and 1.
(I would assume that multi-core systems may multiple the maximum number by the number of cores.)
The values are the same. They are just expressed in very slightly different terms.