【问题标题】:Check Remote Server Load in node js检查节点 js 中的远程服务器负载
【发布时间】:2021-02-22 21:53:58
【问题描述】:

如何在节点 js 或任何其他框架中检查远程 IP/服务器的负载。基本上我有一个 ips / 实例列表。我想为我的程序选择一个 CPU 负载最少的 IP。如何在 node js(preference) 或任何其他语言/框架中实现这一点?

【问题讨论】:

    标签: node.js microservices


    【解决方案1】:

    在 Node.js 中,您实际上可以使用 OS 模块检查 CPU 使用情况:

    var os = require('os');
    console.log(os.cpus());
    console.log(os.totalmem());
    console.log(os.freemem())
    

    你也可以使用来自 Github 的 os-utility 模块:

    var os = require('os-utils');
    
    os.cpuUsage((usage) => {
        console.log( 'CPU Usage:' + usage); //it will be in %
    });
    

    您可以使用上述模块在每个实例上创建一个函数,该函数可以帮助您返回每个实例的 CPU 使用率。根据使用情况,您可以在预期的服务器/IP 上运行您的程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-03
      • 2016-07-24
      • 1970-01-01
      • 2022-11-15
      • 2019-06-26
      • 2014-10-19
      • 2011-09-04
      相关资源
      最近更新 更多