Skip to content

Commit

Permalink
Use top for getting correct CPU usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas committed Nov 17, 2014
1 parent 5b89de0 commit 7f5aed0
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ var fs = require('fs'),
var debugging = process.env.DEBUG,
debug = debugging ? console.log : function() { /* noop */ };

var get_key = function(file) {
var file = file || join(process.env.HOME, '.ssh', 'id_rsa');
return fs.readFileSync(file);
var get_key = function() {
var keys = ['id_rsa', 'id_dsa'];

for (var i in keys) {
var file = join(process.env.HOME, '.ssh', keys[i]);
if (fs.existsSync(file))
return fs.readFileSync(file);
}
}

var processes = 'ps aux | awk \'{print $3 " " $4 " " $11 " "$12}\' | sort -n | tail -10';

var usage = {
cpu : "grep 'cpu ' /proc/stat | awk '{ print ($2+$4)*100/($2+$4+$5) \"%\" }'",
// cpu : "grep 'cpu ' /proc/stat | awk '{ print ($2+$4)*100/($2+$4+$5) \"%\" }'",
cpu : "top -bn 2 -d 0.3 | grep '^%\\?Cpu.s.' | tail -1 | awk '{print $2+$4+$6 \"%\"}'",
ram : "free | egrep 'Mem|buffers' | tr -d '\\n' | awk '{print $14*100/$7 \"%\"}'",
disk : "df -lh | grep '% /$' | awk '{print $5}'"
}
Expand Down Expand Up @@ -84,7 +92,7 @@ Remote.prototype.start = function(cb) {
var self = this;

self.connect(function(err) {
cb(err);
cb(err);

if (!err) self.poll();
})
Expand Down Expand Up @@ -131,7 +139,7 @@ Remote.prototype.stream_closed = function() {
*/

Remote.prototype.stop = function(cb) {
// if (this.stream)
// if (this.stream)
// this.close_stream(); // should trigger the stream_ended method
if (this.connected)
this.disconnect(function() { cb && cb() });
Expand Down

0 comments on commit 7f5aed0

Please sign in to comment.