Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Count process states.

  • Loading branch information...
commit dedf9be64c9220eb98c32ba90285a3fcccecb960 1 parent 3e41dd2
@jperkin authored
Showing with 35 additions and 0 deletions.
  1. +35 −0 probes/proc.js
View
35 probes/proc.js
@@ -32,6 +32,41 @@ function get_proc_count(callback)
}
}
+function get_proc_state(callback)
+{
+ switch (process.platform) {
+ case 'linux':
+ exec('ps -eo s', function (err, stdout, stderr) {
+ var map = {
+ 'D': 'iowait',
+ 'R': 'run',
+ 'S': 'sleep',
+ 'T': 'stopped',
+ 'W': 'paging',
+ 'X': 'dead',
+ 'Z': 'zombie',
+ }
+ var ret = {
+ 'proc.state.iowait': 0,
+ 'proc.state.run': 0,
+ 'proc.state.sleep': 0,
+ 'proc.state.stopped': 0,
+ 'proc.state.paging': 0,
+ 'proc.state.dead': 0,
+ 'proc.state.zombie': 0,
+ };
+ stdout.split('\n').forEach(function (state) {
+ if (state in map) {
+ ret["proc.state." + map[state]] += 1;
+ }
+ }, ret);
+ callback(ret);
+ });
+ break;
+ }
+}
+
module.exports.probes = {
'proc.count': get_proc_count,
+ 'proc.state': get_proc_state,
}
Please sign in to comment.
Something went wrong with that request. Please try again.