How to get memory utilization using node.js OR socket.io

Viewed 176

How can I get the Memory & Process utilization of client's machine using node.js OR socket.io ??

I tried with systemInformation Npm package in node.js but getting server CPU and memory utilization not getting client's machine

How can it be done using node.js OR socket.io either JavaScript ??

1 Answers

There are 2 possible answers to this question, depends on how your client implementation looks like

A - If your client is running in a browser

  • No, you can't access underlying system informations of a client from within a browser, that would be a big security risk. Same with the file system.
  • You propably use the socket.io client implementation in browser like this <script src="/socket.io/socket.io.js"></script>, so the socket.io client is running in the browser, therefore you can't send any underlying systeminformations back to the server, because this would require to access those informations, and that's not possible from within the browser.

B - If your client is running in a "serverside" application using NodeJS

  • Yes, it's possible to access underlying system informations of a client machine from within a locally running NodeJS process, for example in form of a desktop application.
  • For this, a seperate client process needs to run on a client machine, using the socket.io-client (npm install socket.io-client). This socket.io client library can be run with NodeJS. The client would connect to your socket.io server.

Why am I getting systeminformations of server, not the client ?

The reason why you only get back the systeminformations of your server, is because the nodejs process you are trying to access those informations from, is, simply, running on the server machine, not the client machine.

Using chrome.system.cpu on the client side

You can checkout https://developer.chrome.com/docs/extensions/reference/system_cpu/ , a chrome implementation to query CPU metadata. This would be available within the browser of the client, if using chrome, but is limited probably.

Related