I have a distributed server system.
There are a lot of servers, coordinated through PubSub. All of them are connected to the statistics server. Every minute servers send their stats to the stat server (how many requests was processed, average time etc.).
So... It would be nice to include system status in this stat-messages. I need CPU load (every core) and amount of free memory.
I made a little workaround and decided to call a linux command with "exec", parse answer and form a JSON data for sending.
But how can I get this data from command line?
On Mac OS X I can easily get all I need with geektool scripts, but on linux (debian) they don't work.
For example:
top -l 1 | awk '/PhysMem/ {print "Used: " $8 " Free: " $10}'
On Mac OS X Lion I get:
Used: 3246M Free: 848M
And just an error in debian...
On Linux, you can use /proc. See here for a bunch of command line examples to read the stats.
It would be better to read the files from Node directly though, using fs.readFile()
Update: There is also the OS API which is probably better. Example usage: Convert the output of os.cpus() in Node.js to percentage