Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js http server how to get connections count

I'm using node as a http server with the following code:

http.createServer(function(req, res) {}).listen(8181);

I'm looking for a simple way to monitor a node js http server from within the same process. For me it would be enough to have a own function which just outputs the current resource usage and connection count as json. For now I don't need deep measuring or real time performance monitoring.

What are the key performance indicators for a node http server and is it possible to get them from node? If yes how? What you think of the folling kpi's:

  1. Connection Count
  2. CPU Usage
  3. Ram Usage

Just need to know which variables/functions I need to get the data?

Thx I really appreciate your help

like image 326
Manuel Avatar asked Jul 29 '14 09:07

Manuel


People also ask

How many connections can a node js server handle?

JS uses a single thread with an event-loop. In this way, Node can handle 1000s of concurrent connections without any of the traditional detriments associated with threads.

How many connections are in a Node?

No matter what size instance we use Node always appears to max out at 1000 concurrent connections (this is NOT 1000 per second, but 1000 it can handle at 1 time).

How many concurrent HTTP requests can node js handle?

JS can handle 10,000 concurrent requests they are essentially non-blocking requests i.e. these requests are majorly pertaining to database query.


1 Answers

You can get the amount of connection using a built in function of NodeJS. Check getConnections. Bellow an example how to use it:

var server = http.createServer(app);    

server.getConnections(function(error, count) {

    console.log(count);

});

I hope this is what you were looking for :)

like image 174
David Gatti Avatar answered Oct 29 '22 10:10

David Gatti