我使用节点作为http服务器,其代码如下:
http.createServer(function(req, res) {}).listen(8181);我正在寻找一种简单的方法,从同一进程中监视节点js http服务器。对我来说,只要有一个自己的函数就足够了,它将当前的资源使用情况和连接计数作为json输出。目前,我不需要深入的测量或实时性能监测。
节点http服务器的关键性能指标是什么,是否可以从节点获取它们?如果是,怎么做?你对kpi的看法是:
只需要知道我需要哪些变量/函数才能得到数据?
我真的很感谢你的帮助
发布于 2016-02-17 00:35:29
您可以使用内置的NodeJS函数获得连接的数量。检查getConnections。下面是一个如何使用它的例子:
var server = http.createServer(app);
server.getConnections(function(error, count) {
console.log(count);
});我希望这就是你想要的:)
发布于 2014-07-29 09:48:02
你需要这样的东西:
var count = 0;
http.createServer(function(req, res) {
count++;
res.on('finish', function () {
//setTimeout(function () {
count--;
//}, 60000);
}).on('close', function () {
count--;
});
}).listen(8181);使用setTimeout(),您可以在最后1分钟内获得活动连接。
有关CPU使用情况,请参见cpus。
有关内存使用情况,请参见记忆法
发布于 2019-07-25 18:49:36
涂鸦是我创建的一个日志模块。
您可以直接进入您的项目,并获得CPU、Mem和Net,+更多其他方便的标志和度量。
检查 业绩-监测 部件.
使用:
const scribbles = require('scribbles');
scribbles.config({
dataOut:console.log
})
setInterval(function(){
scribbles.status();
}, 5000);
// This will give you a performance snapshot every 5 seconds.你得到的:
- port: _listening on this Port_
- connections: _number of current established connections_
https://stackoverflow.com/questions/25012185
复制相似问题