|
|
@ -9,38 +9,53 @@ module.exports = function() { |
|
|
|
var proc = require('child_process'); |
|
|
|
var proc = require('child_process'); |
|
|
|
|
|
|
|
|
|
|
|
function stats(ids) { |
|
|
|
function stats(ids) { |
|
|
|
var res = []; |
|
|
|
var res = {}; |
|
|
|
var fs = require('fs'); |
|
|
|
var fs = require('fs'); |
|
|
|
|
|
|
|
var async = require('async'); |
|
|
|
var base = "/sys/fs/cgroup/"; |
|
|
|
var base = "/sys/fs/cgroup/"; |
|
|
|
var dataPoints = { |
|
|
|
var dataPoints = { |
|
|
|
"cpuacct": "stat", |
|
|
|
"cpuacct": [ |
|
|
|
"memory": "usage_in_bytes", |
|
|
|
"stat" |
|
|
|
"memory": "max_usage_in_bytes" |
|
|
|
], |
|
|
|
|
|
|
|
"memory": [ |
|
|
|
|
|
|
|
"usage_in_bytes", |
|
|
|
|
|
|
|
"max_usage_in_bytes" |
|
|
|
|
|
|
|
] |
|
|
|
}; |
|
|
|
}; |
|
|
|
ids.forEach(function(id) { |
|
|
|
async.each(ids, function(id, cb1) { |
|
|
|
res[id] = {}; |
|
|
|
res[id] = {}; |
|
|
|
for (key in dataPoints) { |
|
|
|
async.forEachOf(dataPoints, function(val1, category, cb2) { |
|
|
|
var file = base + key + '/docker/' + id + '/' + dataPoints[key]; |
|
|
|
res[id][category] = {}; |
|
|
|
res[id][key] = {}; |
|
|
|
async.each(val1, function(element, cb3) { |
|
|
|
fs.readFile(file, 'utf8', function(err, data) { |
|
|
|
var file = base + category + '/docker/' + id + '/' + category + '.' + element; |
|
|
|
if (err) return; |
|
|
|
res[id][category][element] = {}; |
|
|
|
data.trim().split('\n').forEach(function(v, i) { |
|
|
|
fs.readFile(file, 'utf8', function(err, data) { |
|
|
|
var vals = v.split(' '); |
|
|
|
if (err) {cb3(err); return} |
|
|
|
switch (vals.length) { |
|
|
|
data.trim().split('\n').forEach(function(v, i) { |
|
|
|
case 1: |
|
|
|
var vals = v.split(' '); |
|
|
|
res[id][dataPoints[key]] = parseInt(vals[0]); |
|
|
|
switch (vals.length) { |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
case 2: |
|
|
|
res[id][category][element] = vals[0]; |
|
|
|
res[id][key][dataPoints[key]] = {}; |
|
|
|
break; |
|
|
|
res[id][key][dataPoints[key]][vals[0]] = parseInt(vals[1]); |
|
|
|
case 2: |
|
|
|
break; |
|
|
|
res[id][category][element][vals[0]] = vals[1]; |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
cb3(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
}, function(err) { |
|
|
|
|
|
|
|
cb2(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
}, function(err) { |
|
|
|
|
|
|
|
cb1(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, function(err) { |
|
|
|
|
|
|
|
if (err) return; |
|
|
|
|
|
|
|
broadcast("stats", res); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
console.log("new client"); |
|
|
|
console.log("new client"); |
|
|
|
|
|
|
|
|
|
|
|
function emit(signal, data, info) { |
|
|
|
function emit(signal, data, info) { |
|
|
@ -82,7 +97,6 @@ module.exports = function() { |
|
|
|
error: error, stderr: stderr, stdout: stdout |
|
|
|
error: error, stderr: stderr, stdout: stdout |
|
|
|
}); |
|
|
|
}); |
|
|
|
exec("docker inspect "+stdout.trim().replace(/\n/g, " "), containerinspect); |
|
|
|
exec("docker inspect "+stdout.trim().replace(/\n/g, " "), containerinspect); |
|
|
|
stats(stdout.trim().split('\n')); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function updatecontainers(error, stdout, stderr) { |
|
|
|
function updatecontainers(error, stdout, stderr) { |
|
|
@ -228,6 +242,13 @@ module.exports = function() { |
|
|
|
.on('bash-input', bash_input) |
|
|
|
.on('bash-input', bash_input) |
|
|
|
.on('bash-end', bash_end); |
|
|
|
.on('bash-end', bash_end); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setInterval(function() { |
|
|
|
|
|
|
|
exec("docker ps -q --no-trunc ", function(error, stdout, stderr) { |
|
|
|
|
|
|
|
if (error || stderr) return; // ignore
|
|
|
|
|
|
|
|
stats(stdout.trim().split('\n')); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
1000); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|