Created
June 24, 2011 10:36
-
-
Save teemow/1044557 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var argv = require('/usr/local/lib/node_modules/optimist') | |
.usage('Usage: $0 [env]') | |
.boolean('f') | |
.argv | |
, exec = require('child_process').exec | |
if (argv._.length > 0) env = argv._.shift() | |
else env = 'production' | |
var cc_app = 'adcloud/' + env | |
function cmd(params) { | |
return 'cctrlapp ' + cc_app + ' ' + params | |
} | |
function get_worker_ids(cb) { | |
exec(cmd('worker'), function(err, result, stderr) { | |
if (err) throw err | |
if (stderr) return console.log(stderr) | |
var worker_ids = result.match(/(wrk.*)/g) | |
worker_ids.shift() | |
cb(undefined, worker_ids) | |
}) | |
} | |
function get_worker_info(worker_ids, cb) { | |
var number_of_workers = worker_ids.length | |
, workers = [] | |
worker_ids.forEach(function(worker) { | |
exec(cmd('worker ' + worker), function(err, result) { | |
if (err) { | |
number_of_workers-- | |
//console.log(err.message.replace(/\n/, '')) | |
return | |
} | |
var data = {} | |
result = result.split(/\n/) | |
result.forEach(function(line) { | |
var match = line.match(/\s*(\w*)\s*:\s*(.*)/) | |
if (match) data[match[1]] = match[2] | |
}) | |
workers.push(data) | |
if (workers.length === number_of_workers) cb(undefined, workers) | |
}) | |
}) | |
} | |
function display(workers) { | |
workers.sort(function(a, b) { | |
return new Date(a.created) - new Date(b.created) | |
}) | |
console.log("\033[2J") | |
console.log('found ' + workers.length + ' workers') | |
workers.forEach(function(worker) { | |
console.log(worker.created + ' ' + worker.wrk_id + ' ' + worker.params) | |
}) | |
} | |
function main() { | |
get_worker_ids(function(err, worker_ids) { | |
get_worker_info(worker_ids, function(err, workers) { | |
display(workers) | |
}) | |
}) | |
} | |
if (argv.f) setInterval(main, 10000) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment