Joseph Miller
Joseph Miller

Reputation: 199

How to monitor socket.io web socket uptime

For several months, I'm facing an issue. Websocket goes offline randomly, and there is no any error log to find the issue.

I'm using socket.io for my application and is there any way to monitor the socket.io WebSocket? and keep an eye on it. (pinging based on time interval).

If the WebSocket goes down, i need to get an email alert.

I tried different websites which provide monitoring tools and methods, but nothing is working for socket.io

Upvotes: 1

Views: 1057

Answers (1)

Elliot B.
Elliot B.

Reputation: 17661

If you are using the socket.io library, then you can define a handler for the disconnect event. You may even automatically attempt to re-connect:

socket.on('disconnect', (reason) => {
  if (reason === 'io server disconnect') {
    // the disconnection was initiated by the server, you need to reconnect manually
    socket.connect();
  }
  // add code here for external notification
});

Upvotes: 1

Related Questions