Skip to content
Browse files

Simple process module, for now just count number of processes,

threads, and threaded processes.
  • Loading branch information...
1 parent 1adb97e commit 20ac24ae1ebdd28bff6b4d0a002cfa415487c0f7 @jperkin committed Feb 29, 2012
Showing with 37 additions and 0 deletions.
  1. +37 −0 probes/proc.js
View
37 probes/proc.js
@@ -0,0 +1,37 @@
+/*
+ * Process statistics
+ */
+
+var exec = require('child_process').exec;
+
+function get_proc_count(callback)
+{
+ switch (process.platform) {
+ case 'linux':
+ exec('ps -eo pid,nlwp', function (err, stdout, stderr) {
+ var ret = {
+ 'proc.count.procs': 0,
+ 'proc.count.threads': 0,
+ 'proc.count.threadedprocs': 0,
+ };
+ stdout.split('\n').forEach(function (line) {
+ line = line.replace(/^\s+/, '');
+ var vals = line.split(/\s+/);
+ if (vals[0].match(/\d+/)) {
+ var lwps = parseInt(vals[1]);
+ ret['proc.count.procs'] += 1;
+ ret['proc.count.threads'] += lwps;
+ if (lwps > 1) {
+ ret['proc.count.threadedprocs'] += 1;
+ }
+ }
+ }, ret);
+ callback(ret);
+ });
+ break;
+ }
+}
+
+module.exports.probes = {
+ 'proc.count': get_proc_count,
+}

0 comments on commit 20ac24a

Please sign in to comment.
Something went wrong with that request. Please try again.