stats: fixed issue with missing /sys/fs in docker 1.9, using docker stats; login works
This commit is contained in:
10
ChangeLog
10
ChangeLog
@@ -1,3 +1,13 @@
|
|||||||
|
2016-11-22 15:56 marc
|
||||||
|
|
||||||
|
* nodejs/authentication, nodejs/package.json.in: authentication is
|
||||||
|
now in an own npm package
|
||||||
|
|
||||||
|
2016-09-21 17:24 marc
|
||||||
|
|
||||||
|
* ChangeLog, debian/control.in, servicedock.spec.in: fix build
|
||||||
|
where java is not installed
|
||||||
|
|
||||||
2016-09-21 09:43 marc
|
2016-09-21 09:43 marc
|
||||||
|
|
||||||
* debian/control.in, nodejs/makefile.am: fix build problem in
|
* debian/control.in, nodejs/makefile.am: fix build problem in
|
||||||
|
@@ -2,14 +2,7 @@
|
|||||||
"port": 8888,
|
"port": 8888,
|
||||||
"restrict": {
|
"restrict": {
|
||||||
"passwords": {
|
"passwords": {
|
||||||
"foo": ["sha256", "fcde2b2edxx56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9"]
|
"foo": ["sha256", "fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9"]
|
||||||
},
|
|
||||||
"ldap": {
|
|
||||||
"url": "ldap://dev.marc.waeckerlin.org",
|
|
||||||
"adminDn": "cn=tmp,ou=system,ou=people,dc=dev,dc=marc,dc=waeckerlin,dc=org",
|
|
||||||
"adminPassword": "secret",
|
|
||||||
"searchBase": "ou=person,ou=people,dc=dev,dc=marc,dc=waeckerlin,dc=org",
|
|
||||||
"searchFilter": "(uid={{username}})"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -308,6 +308,7 @@ function showviz(vizpath, more) {
|
|||||||
res = "digraph {\n"+" rankdir="+rankdir+";\n"+viz+"\n}";
|
res = "digraph {\n"+" rankdir="+rankdir+";\n"+viz+"\n}";
|
||||||
try {
|
try {
|
||||||
status(more?Viz(res)+more:Viz(res));
|
status(more?Viz(res)+more:Viz(res));
|
||||||
|
stats();
|
||||||
$('#main a > ellipse + text').attr('font-size', '12');
|
$('#main a > ellipse + text').attr('font-size', '12');
|
||||||
$('#main a > ellipse + text + text')
|
$('#main a > ellipse + text + text')
|
||||||
.attr('font-weight', 'bold')
|
.attr('font-weight', 'bold')
|
||||||
@@ -349,29 +350,21 @@ function size(num) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var oldoldstats = null;
|
var laststats=null;
|
||||||
var oldstats = null;
|
|
||||||
function stats(data) {
|
function stats(data) {
|
||||||
console.log("->rcv stats");
|
if (data)
|
||||||
if (!data && oldstats && oldoldstats) {
|
console.log("->rcv stats");
|
||||||
data = oldstats;
|
else
|
||||||
oldstats = oldoldstats;
|
data=laststats;
|
||||||
}
|
if (!data) return;
|
||||||
if (oldstats) for (name in data) {
|
var lines = data.split("\n");
|
||||||
var s = data[name];
|
var head = lines.shift();
|
||||||
var o = oldstats[name];
|
lines.forEach(function(line) {
|
||||||
if (!o|| !s) continue;
|
if (!line) return;
|
||||||
$('#main text + text:contains("'+name+'") + text')
|
elements = line.split(/ +/);
|
||||||
.html('cpu: '
|
$('#main text + text:contains("'+elements[0]+'") + text')
|
||||||
+(Math.round((s.cpuacct.usage.data-o.cpuacct.usage.data)
|
.html('cpu: '+elements[1]+' mem: '+elements[7]);
|
||||||
/(s.cpuacct.usage.date-o.cpuacct.usage.date)
|
});
|
||||||
/100)
|
|
||||||
/100)
|
|
||||||
+'% mem: '
|
|
||||||
+size(s.memory.usage_in_bytes.data));
|
|
||||||
}
|
|
||||||
oldoldstats = oldstats;
|
|
||||||
oldstats = data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function images(i) {
|
function images(i) {
|
||||||
|
@@ -1,3 +1,9 @@
|
|||||||
|
/*! @file
|
||||||
|
|
||||||
|
@id $Id$
|
||||||
|
*/
|
||||||
|
// 1 2 3 4 5 6 7 8
|
||||||
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||||
try {
|
try {
|
||||||
|
|
||||||
process.on('uncaughtException', function(e) {
|
process.on('uncaughtException', function(e) {
|
||||||
@@ -19,7 +25,7 @@ try {
|
|||||||
var package = require(__dirname+'/package.json');
|
var package = require(__dirname+'/package.json');
|
||||||
var config = require(package.path.config);
|
var config = require(package.path.config);
|
||||||
var docker = require(__dirname+'/docker')(app);
|
var docker = require(__dirname+'/docker')(app);
|
||||||
var authentication = require(__dirname+'/authentication')(config.restrict);
|
var authentication = require('authentication.js')(config.restrict);
|
||||||
var sockets = require(__dirname+'/sockets')(io, authentication);
|
var sockets = require(__dirname+'/sockets')(io, authentication);
|
||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
|
@@ -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) {
|
||||||
@@ -227,57 +227,13 @@ module.exports = function(io, authentication) {
|
|||||||
.on('bash-end', bash_end);
|
.on('bash-end', bash_end);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
broadcast("stats", stdout);
|
||||||
if (err) return;
|
|
||||||
broadcast("stats", res);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user