Skip to content

Commit b343610

Browse files
committedJul 31, 2016
Added GET /ps.
1 parent 000391b commit b343610

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed
 

‎routes/domains.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function get(req, res) {
55
exit: function(code, stdout, stderr) {
66
if (stderr) {
77
return res.send({
8-
status: 'Error',
8+
status: 'error',
99
message: stderr
1010
});
1111
}

‎routes/ps.js

+36
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
11
var ssh = require('../utils/ssh');
22

33
function get(req, res) {
4+
ssh.create().exec('ps ' + req.query.app, {
5+
exit: function(code, stdout, stderr) {
6+
var lines = stdout.split('\n');
47

8+
// Parse container id
9+
var containerTokens = lines[0].split(' ');
10+
var containerId = containerTokens[containerTokens.length - 1];
11+
12+
// Isolated the lines that have process info
13+
lines = lines.slice(2, lines.length - 1);
14+
var processes = [];
15+
for (var i = 0; i < lines.length; i++) {
16+
processes.push(parseProcess(lines[i]));
17+
}
18+
res.send({
19+
containerId: containerId,
20+
processes: processes
21+
});
22+
}
23+
}).start();
24+
}
25+
26+
function parseProcess(line) {
27+
var tokens = line.split(/\s+/);
28+
return {
29+
user: tokens[0],
30+
pid: tokens[1],
31+
cpu: tokens[2],
32+
mem: tokens[3],
33+
vsz: tokens[4],
34+
rss: tokens[5],
35+
tty: tokens[6],
36+
stat: tokens[7],
37+
start: tokens[8],
38+
time: tokens[9],
39+
command: tokens.splice(10).join(' ')
40+
}
541
}
642

743
function rebuildall(req, res) {

0 commit comments

Comments
 (0)
Please sign in to comment.