Skip to content

Commit

Permalink
Add a fix for user submitted ps outputs - fix #7 fix #6 fix #5
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRio committed Jun 10, 2014
1 parent 3045ea7 commit fac5e78
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions sensors/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ var plugin = {
'Command': 'Google Chrome',
'Count': '4',
'CPU %': '0.4',
'Memory': '100 MB'
'Memory %': '1'
}, {
'Command': 'Sublime Text 2',
'Count': '1',
'CPU %': '0.1',
'Memory': '200MB'
'Memory': '5'
}],

// comm, count calced, cp, pmem
Expand All @@ -48,18 +48,21 @@ var plugin = {
*/
poll: function() {
var stats = {};
// @todo If you can think of a better way of getting process stats,
// then please feel free to send me a pull request. This is version 0.1
// and needs some love.
var ps = child_process.exec('ps -ewwwo %cpu,%mem,comm', function (error, stdout, stderr) {
var lines = stdout.split("\n");
// Ditch the first line
lines[0] = '';
for (var line in lines) {
var currentLine = lines[line].trim();
var currentLine = lines[line].trim().replace(' ', ' ');
//console.log(currentLine);
var words = currentLine.split(" ");
if (typeof words[0] !== 'undefined' && typeof words[1] !== 'undefined' ) {
var cpu = words[0];
var mem = words[2];
var offset = cpu.length + mem.length + 3;
var mem = words[1];
var offset = cpu.length + mem.length + 2;
var comm = currentLine.slice(offset);
// If we're on Mac then remove the path
if (/^darwin/.test(process.platform)) {
Expand Down

0 comments on commit fac5e78

Please sign in to comment.