Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  154] [ 6]  / answers: 1 / hits: 21696  / 12 Years ago, thu, april 26, 2012, 12:00:00

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...


More From » linux

 Answers
19

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


[#85959] Wednesday, April 25, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
colby

Total Points: 311
Total Questions: 102
Total Answers: 102

Location: Taiwan
Member since Mon, Sep 6, 2021
3 Years ago
;