How to get system statistics using node.js

I have a distributed server system.

There are many servers coordinated through PubSub. All of them are connected to the statistics server. Every minute, the servers send their statistics to the statistics server (how many requests were processed, average time, etc.).

So ... It would be nice to include system status in these stat messages. I need a processor load (each core) and the amount of free memory.

I made a small workaround and decided to call the linux command using "exec", parse the response, and generate the JSON data to send.

But how can I get this data from the command line?

On Mac OS X, I can easily get everything I need using geektool scripts, but they do not work on linux (debian).

For instance:

top -l 1 | awk '/PhysMem/ {print "Used: " $8 " Free: " $10}'

Mac OS X Lion :

Used: 3246M Free: 848M

debian...

+5
3

Linux /proc. , .

Node, fs.readFile()

: OS API, , , . : os.cpus() Node.js

+7

os-usage, top.

, ​​ . :

var usage = require('os-usage');

// create an instance of CpuMonitor
var cpuMonitor = new usage.CpuMonitor();

// watch cpu usage overview
cpuMonitor.on('cpuUsage', function(data) {
    console.log(data);

    // { user: '9.33', sys: '56.0', idle: '34.66' }
});

// watch processes that use most cpu percentage
cpuMonitor.on('topCpuProcs', function(data) {
    console.log(data);

    // [ { pid: '21749', cpu: '0.0', command: 'top' },
    //  { pid: '21748', cpu: '0.0', command: 'node' },
    //  { pid: '21747', cpu: '0.0', command: 'node' },
    //  { pid: '21710', cpu: '0.0', command: 'com.apple.iCloud' },
    //  { pid: '21670', cpu: '0.0', command: 'LookupViewServic' } ]
});
+1

- https://www.npmjs.com/package/microstats

You can also configure user alerts when disk space, processor, or memory crosses a user-defined threshold. works for linux, macOS and windows.

+1
source

All Articles