socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

state information about connected clients (1.0.0-pre)

Open mroth opened this issue 12 years ago • 1 comments

At a given moment, I would like to be able to get the following state information for ops purposes:

  • a list of namespaces with actively connected clients
  • foreach client in a namespace's connected clients, the following:
    • client IP
    • length of time connection has been open
    • client browser useragent string (optional but nice to have)

I haven't been able to figure out how to access this via the io object. Can someone please help point me in the right direction? Thanks!

(I need this information to be able to partition/scale additional servers based on load.)

mroth avatar Mar 28 '14 21:03 mroth

Hi, i'm getting some information from the socketIO object like this:

var socketIO = io.listen(server);

    var general = {
        sockets: socketIO.rooms[''] ? socketIO.rooms[''].length : 0,
        connected: Object.keys(socketIO.connected).length,
        open: Object.keys(socketIO.open).length,
        closed:  Object.keys(socketIO.closed).length,
        rooms: Object.keys(socketIO.rooms).length,
        roomClients: Object.keys(socketIO.roomClients).length,
        handshaken: Object.keys(socketIO.handshaken).length
    };

    var data = {
        general: general,
        socketIds: socketIO.rooms[''] ? socketIO.rooms[''] : [],
        connected: socketIO.connected,
        open: socketIO.open,
        closed: socketIO.closed,
        rooms: socketIO.rooms,
        roomClients: socketIO.roomClients,
        handshaken: socketIO.handshaken
    };

I hope I've helped

nicoburghi avatar Mar 31 '14 12:03 nicoburghi