-->

Newrelic + node.js + socket.io

2019-06-13 19:52发布

问题:

Newrelic announced support for node.js applications on Oct 24, 2013.

I set up monitoring for my node.js server. It is a service that talks to Client via socket.io. Now, all the requests like this /socket.io/*/xhr-polling/40pt1SBvasfDuwctz4Ma for the service appear to take 20.000 seconds.

Is there a way to set up newrelic so it would correctly show request times served by socket.io?

回答1:

New Relic gives you the option to ignore a rule for something exactly like this. For example you would want to add something like the following:

// newrelic.js
exports.config = {
  // other configuration
  rules : {
    ignore : [
      '^/socket.io/.*/xhr-polling/.*'
    ]
  }
};

There is also an API call that you can use to programmatically do this. You can find more about this in the node.js agent github README.md



回答2:

The software is actually working as intended.

When using XHR-polling with Socket.IO, the default polling duration is 20 seconds. Therefore, the connection is held open for 20 seconds, which is the reason why New Relic reports it as so.