6

Ok so in some spare time i have developed a nodejs/socketio application that streams video but i would like to know what sort of stats its running at, i have my activity monitor running and currently with 2 users sending each other data streams and the stats are as follows:

%CPU: 6.0
Threads: 5
Real Memory: 59.6mb

How can i work out the total MB/GB of data sent on the server?

ChrisMJ
  • 1,620
  • 4
  • 21
  • 27

1 Answers1

3

My suggestion would be to add a counter in your app.

You should be able to add something like the following:

socket.on('message', function(message, callback) { myCounter += sizeof(message); })

The key here would be identifying the sizeof the message you are sending. If it's a buffer, then you can just count bytes. I'm not clear what type of packing they use when sending JSON.

Gates VP
  • 44,957
  • 11
  • 105
  • 108
  • to get the size of the string in bytes is easy: `Buffer.from(string, 'utf8').byteLength` So just add up all bytes and you will have how much bandwidth you use. Actually, that's what I use at https://trafikito.com while counting how much data is coming into the system. – Lukas Liesis Nov 30 '18 at 22:42
  • 1
    This doesn't work if messages are compressed. You are reading the message already uncompressed, and that's not the real measurement if messages are compressed. – c4b4d4 Dec 05 '19 at 22:56