|
|
@ -5,7 +5,7 @@ module.exports = function(io, authentication) { |
|
|
|
var docker = require(__dirname+'/../docker')(); |
|
|
|
var docker = require(__dirname+'/../docker')(); |
|
|
|
|
|
|
|
|
|
|
|
var module={}; |
|
|
|
var module={}; |
|
|
|
var idtoname = {}; |
|
|
|
var running=""; |
|
|
|
|
|
|
|
|
|
|
|
function broadcast(signal, data) { |
|
|
|
function broadcast(signal, data) { |
|
|
|
console.log("<= signal: "+signal); |
|
|
|
console.log("<= signal: "+signal); |
|
|
@ -31,13 +31,12 @@ module.exports = function(io, authentication) { |
|
|
|
return fail("inspect docker containers failed", { |
|
|
|
return fail("inspect docker containers failed", { |
|
|
|
error: error, stderr: stderr, stdout: stdout |
|
|
|
error: error, stderr: stderr, stdout: stdout |
|
|
|
}); |
|
|
|
}); |
|
|
|
idtoname = {}; |
|
|
|
running = ""; |
|
|
|
JSON.parse(stdout).forEach(function(n) { |
|
|
|
JSON.parse(stdout).forEach(function(n) { |
|
|
|
if (n.State.Running) idtoname[n.Id] = n.Name.replace(/^\//, ''); |
|
|
|
if (n.State.Running) running+=" "+n.Name.replace(/^\//, ''); |
|
|
|
}); |
|
|
|
}); |
|
|
|
if (oldcontainer && oldcontainer==stdout) return; // do not resend same containers
|
|
|
|
if (oldcontainer!=stdout) broadcast("containers", stdout); |
|
|
|
oldcontainer = stdout; |
|
|
|
oldcontainer = stdout; |
|
|
|
broadcast("containers", stdout); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function containerlist(error, stdout, stderr) { |
|
|
|
function containerlist(error, stdout, stderr) { |
|
|
@ -45,7 +44,8 @@ module.exports = function(io, authentication) { |
|
|
|
return fail("list docker containers failed", { |
|
|
|
return fail("list docker containers failed", { |
|
|
|
error: error, stderr: stderr, stdout: stdout |
|
|
|
error: error, stderr: stderr, stdout: stdout |
|
|
|
}); |
|
|
|
}); |
|
|
|
exec("docker inspect "+stdout.trim().replace(/\n/g, " "), containerinspect); |
|
|
|
var containers = stdout.trim().replace(/\n/g, " "); |
|
|
|
|
|
|
|
exec("docker inspect "+containers, containerinspect); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function updatecontainers(error, stdout, stderr) { |
|
|
|
function updatecontainers(error, stdout, stderr) { |
|
|
@ -228,56 +228,12 @@ module.exports = function(io, authentication) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function stats() { |
|
|
|
function stats(error, stdout, stderr) { |
|
|
|
var res = {}; |
|
|
|
if (error || stderr) |
|
|
|
var fs = require('fs'); |
|
|
|
return fail("get containers stats failed", { |
|
|
|
var async = require('async'); |
|
|
|
error: error, stderr: stderr, stdout: stdout |
|
|
|
var base = "/sys/fs/cgroup/"; |
|
|
|
|
|
|
|
var dataPoints = { |
|
|
|
|
|
|
|
"cpuacct": [ |
|
|
|
|
|
|
|
"usage" |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
"memory": [ |
|
|
|
|
|
|
|
"usage_in_bytes", |
|
|
|
|
|
|
|
"limit_in_bytes", |
|
|
|
|
|
|
|
"max_usage_in_bytes" |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
async.forEachOf(idtoname, function(name, id, cb1) { |
|
|
|
|
|
|
|
res[name] = {}; |
|
|
|
|
|
|
|
async.forEachOf(dataPoints, function(val1, category, cb2) { |
|
|
|
|
|
|
|
res[name][category] = {}; |
|
|
|
|
|
|
|
async.each(val1, function(element, cb3) { |
|
|
|
|
|
|
|
var file = base + category + '/docker/' + id + '/' + category + '.' + element; |
|
|
|
|
|
|
|
fs.readFile(file, 'utf8', function(err, data) { |
|
|
|
|
|
|
|
res[name][category][element] = { |
|
|
|
|
|
|
|
date: (new Date()).getTime(), |
|
|
|
|
|
|
|
data: {} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
if (err) {cb3(); console.log(err); return} |
|
|
|
|
|
|
|
data.trim().split('\n').forEach(function(v, i) { |
|
|
|
|
|
|
|
var vals = v.split(' '); |
|
|
|
|
|
|
|
switch (vals.length) { |
|
|
|
|
|
|
|
case 1: |
|
|
|
|
|
|
|
res[name][category][element].data = parseInt(vals[0]); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 2: |
|
|
|
|
|
|
|
res[name][category][element].data[vals[0]] = parseInt(vals[1]); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
cb3(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, function(err) { |
|
|
|
|
|
|
|
cb2(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, function(err) { |
|
|
|
|
|
|
|
cb1(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, function(err) { |
|
|
|
|
|
|
|
if (err) return; |
|
|
|
|
|
|
|
broadcast("stats", res); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
broadcast("stats", stdout); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Handle Connection
|
|
|
|
// Handle Connection
|
|
|
@ -295,16 +251,16 @@ module.exports = function(io, authentication) { |
|
|
|
timeout: "none" |
|
|
|
timeout: "none" |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Regular Update of Stats
|
|
|
|
|
|
|
|
setInterval(function() { |
|
|
|
|
|
|
|
stats(); |
|
|
|
|
|
|
|
}, 1000); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Regular Update of Images and Containers
|
|
|
|
// Regular Update of Images and Containers
|
|
|
|
setInterval(function() { |
|
|
|
setInterval(function() { |
|
|
|
updateimages(); |
|
|
|
updateimages(); |
|
|
|
updatecontainers(); |
|
|
|
updatecontainers(); |
|
|
|
}, 10000); |
|
|
|
}, 10000); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Regular Update of Stats
|
|
|
|
|
|
|
|
setInterval(function() { |
|
|
|
|
|
|
|
exec('docker stats --no-stream'+running, stats); |
|
|
|
|
|
|
|
}, 1000); |
|
|
|
|
|
|
|
|
|
|
|
return module; |
|
|
|
return module; |
|
|
|
} |
|
|
|
} |
|
|
|